Sha256: 2925db202cc9184522b7c56b7a85a40e2c525332293f902906da27b28032153b
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
require 'test_helper' module ActiveModel class Serializer class FilterAttributesTest < ActiveModel::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 < ActiveModel::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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_model_serializers-0.9.0.alpha1 | test/unit/active_model/serializer/filter_test.rb |