Added test case for association propagating options

This commit is contained in:
Raphael Pereira 2015-03-28 13:24:03 -03:00
parent db566b427d
commit fd5cd879f8
2 changed files with 15 additions and 0 deletions

View File

@ -113,6 +113,13 @@ end
class PostSerializer < ActiveModel::Serializer class PostSerializer < ActiveModel::Serializer
attributes :title, :body attributes :title, :body
def title
keyword = serialization_options[:highlight_keyword]
title = object.read_attribute_for_serialization(:title)
title = title.gsub(keyword,"'#{keyword}'") if keyword
title
end
has_many :comments has_many :comments
end end

View File

@ -21,6 +21,9 @@ module ActiveModel
serialization_options[:force_the_description] serialization_options[:force_the_description]
end end
end end
@category = Category.new({name: 'Category 1'})
@category_serializer = CategorySerializer.new(@category)
end end
def test_filtered_attributes_serialization def test_filtered_attributes_serialization
@ -29,6 +32,11 @@ module ActiveModel
'profile' => { name: 'Name 1', description: forced_description } 'profile' => { name: 'Name 1', description: forced_description }
}, @profile_serializer.as_json(force_the_description: forced_description)) }, @profile_serializer.as_json(force_the_description: forced_description))
end end
def test_filtered_attributes_serialization_across_association
assert_equal("'T1'",
@category_serializer.as_json(highlight_keyword: 'T1')['category'][:posts][0][:title])
end
end end
end end
end end