Sha256: b34ac0e7f81379c2704549d15006c6157eba824237b9229c175aeebe9beb5ecd

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

require_relative '../test_helper'
require 'hyperclient/resource'

module Hyperclient
  describe Resource do
    let(:entry_point) { mock('Entry point') }

    describe 'initialize' do
      it 'initializes its links' do
        LinkCollection.expects(:new).with({"self" => { "href" => "/orders/523" }}, entry_point)

        Resource.new({'_links' => {"self" => { "href" => "/orders/523" } }}, entry_point)
      end

      it 'initializes its attributes' do
        Attributes.expects(:new).with({foo: :bar})

        Resource.new({foo: :bar}, entry_point)
      end

      it 'initializes links' do
        ResourceCollection.expects(:new).with({"orders" => []}, entry_point)

        Resource.new({'_embedded' => {"orders" => [] }}, entry_point)
      end
    end

    describe 'accessors' do
      let(:resource) do
        Resource.new({}, entry_point)
      end

      describe 'links' do
        it 'returns a LinkCollection' do
          resource.links.must_be_kind_of LinkCollection
        end
      end

      describe 'attributes' do
        it 'returns a Attributes' do
          resource.attributes.must_be_kind_of Attributes
        end
      end

      describe 'embedded' do
        it 'returns a ResourceCollection' do
          resource.embedded.must_be_kind_of ResourceCollection
        end
      end
    end

    it 'uses its self Link to handle HTTP connections' do
      self_link = mock('Self Link')
      self_link.expects(:get)

      LinkCollection.expects(:new).returns({'self' => self_link})
      resource = Resource.new({}, entry_point)

      resource.get
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hyperclient-0.3.1 test/hyperclient/resource_test.rb
hyperclient-0.3.0 test/hyperclient/resource_test.rb
hyperclient-0.2.0 test/hyperclient/resource_test.rb
hyperclient-0.1.0 test/hyperclient/resource_test.rb