mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Address issues in 50950d9533 #1340
- Add changelog entry - Remove superseded and incorrect tests - Fix array serialization test
This commit is contained in:
parent
50950d9533
commit
1cc2e04cf6
@ -3,6 +3,7 @@
|
|||||||
Breaking changes:
|
Breaking changes:
|
||||||
Features:
|
Features:
|
||||||
- [#1018](https://github.com/rails-api/active_model_serializers/pull/1018) Add more tests and docs for top-level links (@leandrocp)
|
- [#1018](https://github.com/rails-api/active_model_serializers/pull/1018) Add more tests and docs for top-level links (@leandrocp)
|
||||||
|
- [#1340](https://github.com/rails-api/active_model_serializers/pull/1340) Add support for resource-level meta (@beauby)
|
||||||
Fixes:
|
Fixes:
|
||||||
- [#1501](https://github.com/rails-api/active_model_serializers/pull/1501) Adds tests for SerializableResource::use_adapter?,doc typos (@domitian)
|
- [#1501](https://github.com/rails-api/active_model_serializers/pull/1501) Adds tests for SerializableResource::use_adapter?,doc typos (@domitian)
|
||||||
- [#1488](https://github.com/rails-api/active_model_serializers/pull/1488) Require ActiveSupport's string inflections (@nate00)
|
- [#1488](https://github.com/rails-api/active_model_serializers/pull/1488) Require ActiveSupport's string inflections (@nate00)
|
||||||
|
|||||||
@ -46,15 +46,20 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_meta_object_resource_in_array
|
def test_meta_object_resource_in_array
|
||||||
|
post2 = Post.new(id: 1339, comments: [Comment.new])
|
||||||
|
posts = [@post, post2]
|
||||||
hash = ActiveModel::SerializableResource.new(
|
hash = ActiveModel::SerializableResource.new(
|
||||||
[@post, @post],
|
posts,
|
||||||
each_serializer: MetaBlockPostSerializer,
|
each_serializer: MetaBlockPostSerializer,
|
||||||
adapter: :json_api
|
adapter: :json_api
|
||||||
).serializable_hash
|
).serializable_hash
|
||||||
expected = {
|
expected = {
|
||||||
comments_count: @post.comments.count
|
:data => [
|
||||||
|
{ :id => '1337', :type => 'posts', :meta => { :comments_count => 0 } },
|
||||||
|
{ :id => '1339', :type => 'posts', :meta => { :comments_count => 1 } }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
assert_equal([expected, expected], hash[:data].map { |obj| obj[:meta] })
|
assert_equal(expected, hash)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -3,8 +3,6 @@ require 'test_helper'
|
|||||||
module ActiveModel
|
module ActiveModel
|
||||||
class Serializer
|
class Serializer
|
||||||
class MetaTest < ActiveSupport::TestCase
|
class MetaTest < ActiveSupport::TestCase
|
||||||
MetaBlogSerializer = Class.new(ActiveModel::Serializer)
|
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@blog = Blog.new(id: 1,
|
@blog = Blog.new(id: 1,
|
||||||
name: 'AMS Hints',
|
name: 'AMS Hints',
|
||||||
@ -127,20 +125,6 @@ module ActiveModel
|
|||||||
}
|
}
|
||||||
assert_equal(expected, actual)
|
assert_equal(expected, actual)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_meta_is_set_with_direct_attributes
|
|
||||||
MetaBlogSerializer.meta stuff: 'value'
|
|
||||||
blog_meta_serializer = MetaBlogSerializer.new(@blog)
|
|
||||||
assert_equal(blog_meta_serializer.meta, stuff: 'value')
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_meta_is_set_with_block
|
|
||||||
MetaBlogSerializer.meta do
|
|
||||||
{ articles_count: object.articles.count }
|
|
||||||
end
|
|
||||||
blog_meta_serializer = MetaBlogSerializer.new(@blog)
|
|
||||||
assert_equal(blog_meta_serializer.meta, articles_count: @blog.articles.count)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user