Skip to content

Commit fd5cd87

Browse files
Added test case for association propagating options
1 parent db566b4 commit fd5cd87

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

test/fixtures/poro.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ class CategorySerializer < ActiveModel::Serializer
113113
class PostSerializer < ActiveModel::Serializer
114114
attributes :title, :body
115115

116+
def title
117+
keyword = serialization_options[:highlight_keyword]
118+
title = object.read_attribute_for_serialization(:title)
119+
title = title.gsub(keyword,"'#{keyword}'") if keyword
120+
title
121+
end
122+
116123
has_many :comments
117124
end
118125

test/unit/active_model/serializer/options_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def description
2121
serialization_options[:force_the_description]
2222
end
2323
end
24+
25+
@category = Category.new({name: 'Category 1'})
26+
@category_serializer = CategorySerializer.new(@category)
2427
end
2528

2629
def test_filtered_attributes_serialization
@@ -29,6 +32,11 @@ def test_filtered_attributes_serialization
2932
'profile' => { name: 'Name 1', description: forced_description }
3033
}, @profile_serializer.as_json(force_the_description: forced_description))
3134
end
35+
36+
def test_filtered_attributes_serialization_across_association
37+
assert_equal("'T1'",
38+
@category_serializer.as_json(highlight_keyword: 'T1')['category'][:posts][0][:title])
39+
end
3240
end
3341
end
3442
end

0 commit comments

Comments
 (0)