Sha256: b086b6e32053fec31347a1d15379675b0fe2a753cd61245ee8b3fcf3bdb60f29

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true
# rubocop:disable Metrics/MethodLength

require_relative '../test_helper'

module Excon
  # ResourceObjectTest
  #
  # Validate the workings of `Excon::HyperResource::ResourceObject`.
  #
  class ResourceObjectTest < Minitest::Test
    def body
      <<~EOF
        {
          "_links": {
            "hello": {
              "href": "http://www.example.com/hello/{location}"
            }
          },
          "uid": "universe",
          "hello": "world"
        }
      EOF
    end

    def data
      @data ||= JSON.parse(body)
    end

    def resource
      @resource ||= Excon::HyperMedia::ResourceObject.new(data)
    end

    def test_resource
      assert_equal data, resource.instance_variable_get(:@data)
    end

    def test_links
      assert_equal data['_links']['hello']['href'], resource._links.hello.href
    end

    def test_properties
      assert_equal 'universe', resource.uid
      assert_equal 'world', resource.hello
      assert_equal 'world', resource['hello']
      assert_equal nil, resource['invalid']
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
excon-hypermedia-0.4.3 test/excon/resource_object_test.rb
excon-hypermedia-0.4.2 test/excon/resource_object_test.rb
excon-hypermedia-0.4.1 test/excon/resource_object_test.rb
excon-hypermedia-0.4.0 test/excon/resource_object_test.rb