Sha256: 07dc75c51b75567c4d4102f1c08a9bc6a2d44a688f291102ca1aed2a7ecb87bb

Contents?: true

Size: 1.76 KB

Versions: 8

Compression:

Stored size: 1.76 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(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

8 entries across 8 versions & 1 rubygems

Version Path
yaks-0.7.7 spec/integration/map_to_resource_spec.rb
yaks-0.7.6 spec/integration/map_to_resource_spec.rb
yaks-0.7.5 spec/integration/map_to_resource_spec.rb
yaks-0.7.4 spec/integration/map_to_resource_spec.rb
yaks-0.7.3 spec/integration/map_to_resource_spec.rb
yaks-0.7.2 spec/integration/map_to_resource_spec.rb
yaks-0.7.1 spec/integration/map_to_resource_spec.rb
yaks-0.7.0 spec/integration/map_to_resource_spec.rb