Sha256: a771abb7fa04324493ed880fc0613776878d042f54b3db25bcc1b28014270032
Contents?: true
Size: 1.39 KB
Versions: 2
Compression:
Stored size: 1.39 KB
Contents
require 'test_helper' module ActiveModel class Serializer class FilterAttributesTest < ActiveRecord::TestCase def setup @profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }) @profile_serializer = ProfileSerializer.new(@profile) @profile_serializer.instance_eval do def filter(keys) keys - [:description] end end end def test_filtered_attributes_serialization assert_equal({ 'profile' => { name: 'Name 1' } }, @profile_serializer.as_json) end end class FilterAssociationsTest < ActiveRecord::TestCase def setup @association = PostSerializer._associations[:comments] @old_association = @association.dup @association.embed = :ids @association.embed_in_root = true @post = Post.new({ title: 'Title 1', body: 'Body 1', date: '1/1/2000' }) @post_serializer = PostSerializer.new(@post) @post_serializer.instance_eval do def filter(keys) keys - [:body, :comments] end end end def teardown PostSerializer._associations[:comments] = @old_association end def test_filtered_associations_serialization assert_equal({ 'post' => { title: 'Title 1' } }, @post_serializer.as_json) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems