spec/unit/yaks/mapper/has_many_spec.rb in yaks-0.6.0.alpha.1 vs spec/unit/yaks/mapper/has_many_spec.rb in yaks-0.6.0
- old
+ new
@@ -8,11 +8,11 @@
let(:closet_mapper_class) do
Class.new(Yaks::Mapper) do
type 'closet'
has_many :shoes,
rel: 'http://foo/shoes',
- mapper: Class.new(Yaks::Mapper) { type 'shoe' ; attributes :size, :color }
+ item_mapper: Class.new(Yaks::Mapper) { type 'shoe' ; attributes :size, :color }
end
end
subject(:shoe_association) { closet_mapper.associations.first }
@@ -68,14 +68,27 @@
end
describe '#collection_mapper' do
let(:collection_mapper) { Yaks::Undefined }
- subject(:has_many) { described_class.new(name: :name, mapper: :mapper, rel: :rel, collection_mapper: collection_mapper) }
+ subject(:has_many) { described_class.new(name: :name, item_mapper: :mapper, rel: :rel, collection_mapper: collection_mapper) }
+
context 'when the collection mapper is undefined' do
it 'should derive one from collection and policy' do
expect(has_many.collection_mapper([], Yaks::DefaultPolicy.new)).to equal Yaks::CollectionMapper
+ end
+
+ it 'should return nil if no policy is given' do
+ expect(has_many.collection_mapper([])).to be_nil
+ end
+
+ it 'should return nil if no collection is given' do
+ expect(has_many.collection_mapper(nil, Yaks::DefaultPolicy.new)).to be_nil
+ end
+
+ it 'should return nil if no params are given' do
+ expect(has_many.collection_mapper).to be_nil
end
end
context 'when the collection mapper is specified' do
let(:collection_mapper) { :foo }