spec/result_spec.rb in restpack_serializer-0.4.10 vs spec/result_spec.rb in restpack_serializer-0.4.11
- old
+ new
@@ -34,17 +34,37 @@
context 'a list with side-loaded resources' do
before do
subject.resources[:albums] = [{ id: '1', name: 'AMOK'}]
subject.resources[:songs] = [{ id: '91', name: 'Before Your Very Eyes...', links: { album: '1' }}]
+ subject.meta[:albums] = { count: 1 }
+ subject.meta[:songs] = { count: 1 }
subject.links['albums.songs'] = { type: 'songs', href: '/api/v1/songs?album_id={albums.id}' }
subject.links['songs.album'] = { type: 'albums', href: '/api/v1/albums/{songs.album}' }
end
- it 'returns correct jsonapi.org format, including injected to_many links' do
+ it 'returns correct jsonapi.org format, including injected has_many links' do
result[:albums].should == [{ id: '1', name: 'AMOK', links: { songs: ['91'] } }]
result[:links].should == subject.links
result[:linked][:songs].should == subject.resources[:songs]
+ end
+
+ it 'includes resources in correct order' do
+ result.keys[0].should == :albums
+ result.keys[1].should == :linked
+ result.keys[2].should == :links
+ result.keys[3].should == :meta
+ end
+
+ context 'with multiple calls to serialize' do
+ let(:result) do
+ subject.serialize
+ subject.serialize
+ end
+
+ it 'does not create duplicate has_many links' do
+ result[:albums].first[:links][:songs].count.should == 1
+ end
end
end
end
end
end