mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Merge branch 'beauby-resource-level-meta'
Followup concerns: - https://github.com/rails-api/active_model_serializers/pull/1340/files#r47451387 - https://github.com/rails-api/active_model_serializers/pull/1340/files#r48116963 - https://github.com/rails-api/active_model_serializers/pull/1340#discussion_r47451387 - https://github.com/rails-api/active_model_serializers/pull/1340#issuecomment-164306882 - https://github.com/rails-api/active_model_serializers/pull/1340#issuecomment-166202978 - https://github.com/rails-api/active_model_serializers/pull/1340#issuecomment-173028896
This commit is contained in:
@@ -3,6 +3,8 @@ require 'test_helper'
|
||||
module ActiveModel
|
||||
class Serializer
|
||||
class MetaTest < ActiveSupport::TestCase
|
||||
MetaBlogSerializer = Class.new(ActiveModel::Serializer)
|
||||
|
||||
def setup
|
||||
@blog = Blog.new(id: 1,
|
||||
name: 'AMS Hints',
|
||||
@@ -125,6 +127,20 @@ module ActiveModel
|
||||
}
|
||||
assert_equal(expected, actual)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user