Sha256: 2d9bf55cabbc287a4c58d0ea2600ae55cad63b32121f9d1eefeb4b912be9f7fb

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require 'spec_helper'

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(:copyright, '/api/copyright/2024', {}) ] }

  its(:subresources) {
    should eq(
      "rel:src=friend&dest=pet_peeve" => Yaks::Resource.new(type:'pet_peeve', attributes: {id: 4, type: 'parsing with regexps'}),
      "rel:src=friend&dest=pets" => Yaks::CollectionResource.new(
        type: 'pet',
        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"})
        ],
        members_rel: 'rel:src=collection&dest=pets'
      )
    )
  }
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yaks-0.4.2 spec/integration/map_to_resource_spec.rb