Sha256: 3e90a002ebc8614e7413b93f041a7a96d52f978582b406e07cb46fe314d25300

Contents?: true

Size: 1.69 KB

Versions: 7

Compression:

Stored size: 1.69 KB

Contents

RSpec.describe 'Mapping domain models to Resource objects' do
  include_context 'fixtures'
  include_context 'yaks context'

  subject { mapper.call(john) }
  let(:mapper) { FriendMapper.new(yaks_context) }

  it { should be_a Yaks::Resource }
  its(:type)         { should eql 'friend' }
  its(:attributes)   { should eql(id: 1, name: 'john') }
  its(:links)        { should eql [ Yaks::Resource::Link.new(rel: :copyright, uri: '/api/copyright/2024') ] }

  specify {
    subject.subresources == [
      Yaks::Resource.new(
        type:'pet_peeve',
        rels: ['rel:pet_peeve'],
        attributes: {id: 4, type: 'parsing with regexps'}
      ),
      Yaks::CollectionResource.new(
        type: 'pet',
        rels: ['rel:pets'],
        members: [
          Yaks::Resource.new(
            type: 'pet',
            attributes: {:id => 2, :species => 'dog', :name => 'boingboing'}
          ),
          Yaks::Resource.new(
            type: 'pet',
            attributes: {:id => 3, :species => 'cat', :name => 'wassup'}
          )
        ]
      )
    ]
  }

  its(:subresources) {
    should eq(
      [
        Yaks::Resource.new(
          type:'pet_peeve',
          rels: ['rel:pet_peeve'],
          attributes: {id: 4, type: 'parsing with regexps'}
        ),
        Yaks::CollectionResource.new(
          type: 'pet',
          rels: ['rel:pets'],
          members: [
            Yaks::Resource.new(
              type: 'pet',
              attributes: {:id => 2, :species => 'dog', :name => 'boingboing'}
            ),
            Yaks::Resource.new(
              type: 'pet',
              attributes: {:id => 3, :species => 'cat', :name => 'wassup'}
            )
          ]
        )
      ]
    )
  }
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
yaks-0.9.0 spec/integration/map_to_resource_spec.rb
yaks-0.8.3 spec/integration/map_to_resource_spec.rb
yaks-0.8.2 spec/integration/map_to_resource_spec.rb
yaks-0.8.1 spec/integration/map_to_resource_spec.rb
yaks-0.8.0 spec/integration/map_to_resource_spec.rb
yaks-0.8.0.beta2 spec/integration/map_to_resource_spec.rb
yaks-0.8.0.beta1 spec/integration/map_to_resource_spec.rb