spec/unit/yaks/mapper/has_many_spec.rb in yaks-0.4.0.rc1 vs spec/unit/yaks/mapper/has_many_spec.rb in yaks-0.4.0

- old
+ new

@@ -1,13 +1,14 @@ require 'spec_helper' RSpec.describe Yaks::Mapper::HasMany do let(:closet_mapper) do Class.new(Yaks::Mapper) do + type 'closet' has_many :shoes, rel: 'http://foo/shoes', - mapper: Class.new(Yaks::Mapper) { type 'shoes' ; attributes :size, :color } + mapper: Class.new(Yaks::Mapper) { type 'shoe' ; attributes :size, :color } end end let(:closet) { double( @@ -17,30 +18,36 @@ ] ) } it 'should map the subresources' do - expect(closet_mapper.new(closet, policy: Yaks::DefaultPolicy.new, env: {}).map_subresources).to eql( + expect(closet_mapper.new(policy: Yaks::DefaultPolicy.new, env: {}).call(closet).subresources).to eql( "http://foo/shoes" => Yaks::CollectionResource.new( - type: 'shoes', + type: 'shoe', members: [ - Yaks::Resource.new(type: 'shoes', attributes: {:size => 9, :color => :blue}), - Yaks::Resource.new(type: 'shoes', attributes: {:size => 11.5, :color => :red}) - ] + Yaks::Resource.new(type: 'shoe', attributes: {:size => 9, :color => :blue}), + Yaks::Resource.new(type: 'shoe', attributes: {:size => 11.5, :color => :red}) + ], + members_rel: 'rel:src=collection&dest=shoes' ) ) end describe '#collection_mapper' do let(:collection_mapper) { Yaks::Undefined } subject(:has_many) { described_class.new(:name, :mapper, :rel, collection_mapper) } context 'when the collection mapper is undefined' do - its(:collection_mapper) { should equal Yaks::CollectionMapper } + it 'should derive one from collection and policy' do + expect(has_many.collection_mapper([], Yaks::DefaultPolicy.new)).to equal Yaks::CollectionMapper + end end context 'when the collection mapper is specified' do let(:collection_mapper) { :foo } - its(:collection_mapper) { should equal :foo } + + it 'should use the given collection mapper' do + expect(has_many.collection_mapper([], Yaks::DefaultPolicy.new)).to equal :foo + end end end end