spec/serializer_spec.rb in jsonapi-serializers-0.2.4 vs spec/serializer_spec.rb in jsonapi-serializers-0.2.5
- old
+ new
@@ -331,10 +331,19 @@
post = create(:post)
expect(JSONAPI::Serializer.serialize(post)).to eq({
'data' => serialize_primary(post, {serializer: MyApp::PostSerializer}),
})
end
+ it 'can serialize a single object with an `each` method by passing skip_collection_check: true' do
+ post = create(:post)
+ post.define_singleton_method(:each) do
+ "defining this just to defeat the duck-type check"
+ end
+ expect(JSONAPI::Serializer.serialize(post, skip_collection_check: true)).to eq({
+ 'data' => serialize_primary(post, {serializer: MyApp::PostSerializer}),
+ })
+ end
it 'can serialize a collection' do
posts = create_list(:post, 2)
expect(JSONAPI::Serializer.serialize(posts, is_collection: true)).to eq({
'data' => [
serialize_primary(posts.first, {serializer: MyApp::PostSerializer}),
@@ -694,6 +703,6 @@
end
describe 'context' do
xit 'is correctly passed through all serializers' do
end
end
-end
\ No newline at end of file
+end