spec/serializer_spec.rb in jsonapi-serializers-0.8.0 vs spec/serializer_spec.rb in jsonapi-serializers-0.9.0
- old
+ new
@@ -379,11 +379,11 @@
expect(JSONAPI::Serializer.serialize(post, meta: meta)).to eq({
'meta' => meta,
'data' => serialize_primary(post, {serializer: MyApp::PostSerializer}),
})
end
- it 'can include a top level errors node' do
+ it 'can include a top level errors node - deprecated' do
post = create(:post)
errors = [
{
"source" => { "pointer" => "/data/attributes/first-name" },
"title" => "Invalid Attribute",
@@ -397,9 +397,24 @@
]
expect(JSONAPI::Serializer.serialize(post, errors: errors)).to eq({
'errors' => errors,
'data' => serialize_primary(post, {serializer: MyApp::PostSerializer}),
})
+ end
+ it 'can include a top level errors node' do
+ errors = [
+ {
+ "source" => { "pointer" => "/data/attributes/first-name" },
+ "title" => "Invalid Attribute",
+ "detail" => "First name must contain at least three characters."
+ },
+ {
+ "source" => { "pointer" => "/data/attributes/first-name" },
+ "title" => "Invalid Attribute",
+ "detail" => "First name must contain an emoji."
+ }
+ ]
+ expect(JSONAPI::Serializer.serialize_errors(errors)).to eq({'errors' => errors})
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"