Skip to content

Commit 2a1d934

Browse files
Test to cover serialization_options
1 parent 341d552 commit 2a1d934

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/unit/active_model/serializer/options_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,24 @@ def test_custom_options_are_accessible_from_serializer
1111
assert_equal({foo: :bar}, @serializer.context)
1212
end
1313
end
14+
15+
class SerializationOptionsTest < Minitest::Test
16+
def setup
17+
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
18+
@profile_serializer = ProfileSerializer.new(@profile)
19+
@profile_serializer.instance_eval do
20+
def description
21+
serialization_options[:force_the_description]
22+
end
23+
end
24+
end
25+
26+
def test_filtered_attributes_serialization
27+
forced_description = "This is a test"
28+
assert_equal({
29+
'profile' => { name: 'Name 1', description: forced_description }
30+
}, @profile_serializer.as_json(force_the_description: forced_description))
31+
end
32+
end
1433
end
1534
end

0 commit comments

Comments
 (0)