Sha256: 6b4bfd318b33029f2999377e669c74b32ff0359050c9eb013bf3934fc176550f
Contents?: true
Size: 1.33 KB
Versions: 14
Compression:
Stored size: 1.33 KB
Contents
require 'test_helper' require 'active_model/serializer' module ActiveModel class ArraySerializer class MetaTest < Minitest::Test def setup @profile1 = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' }) @profile2 = Profile.new({ name: 'Name 2', description: 'Description 2', comments: 'Comments 2' }) @serializer = ArraySerializer.new([@profile1, @profile2], root: 'profiles') end def test_meta @serializer.meta = { total: 10 } assert_equal({ 'profiles' => [ { name: 'Name 1', description: 'Description 1' }, { name: 'Name 2', description: 'Description 2' } ], meta: { total: 10 } }, @serializer.as_json) end def test_meta_using_meta_key @serializer.meta_key = :my_meta @serializer.meta = { total: 10 } assert_equal({ 'profiles' => [ { name: 'Name 1', description: 'Description 1' }, { name: 'Name 2', description: 'Description 2' } ], my_meta: { total: 10 } }, @serializer.as_json) end end end end
Version data entries
14 entries across 14 versions & 2 rubygems