Sha256: 38f1e3e8270511c036546376a946bdee31d62d7583908ba7a401934183c34651

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require 'test_helper'
require 'active_model/serializer'

module ActiveModel
  class ArraySerializer
    class MetaTest < ActiveModel::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

1 entries across 1 versions & 1 rubygems

Version Path
active_model_serializers-0.9.0.alpha1 test/unit/active_model/array_serializer/meta_test.rb