Sha256: 29c956bf891b3acde6b82671937b924a446f176260b3bca84e81a3c3b4275acc
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
require 'test_helper' require 'active_model/serializer' module ActiveModel class ArraySerializer class MetaTest < ActiveRecord::TestCase 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
2 entries across 2 versions & 1 rubygems