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

Version Path
active_model_serializers-0.9.13 test/unit/active_model/array_serializer/meta_test.rb
active_model_serializers-0.9.12 test/unit/active_model/array_serializer/meta_test.rb
active_model_serializers-0.9.11 test/unit/active_model/array_serializer/meta_test.rb
active_model_serializers-0.9.9 test/unit/active_model/array_serializer/meta_test.rb
active_model_serializers-0.9.8 test/unit/active_model/array_serializer/meta_test.rb
active_model_serializers-0.9.7 test/unit/active_model/array_serializer/meta_test.rb
active_model_serializers-0.9.6 test/unit/active_model/array_serializer/meta_test.rb
active_model_serializers-0.9.5 test/unit/active_model/array_serializer/meta_test.rb
active_model_serializers-0.9.4 test/unit/active_model/array_serializer/meta_test.rb
active_model_serializers-0.9.3 test/unit/active_model/array_serializer/meta_test.rb
active_model_serializers-0.9.2 test/unit/active_model/array_serializer/meta_test.rb
active_model_serializers-0.9.1 test/unit/active_model/array_serializer/meta_test.rb
active_model_serializers-0.9.0 test/unit/active_model/array_serializer/meta_test.rb
active_model_serializers_rails_2.3-0.9.0.alpha1 test/unit/active_model/array_serializer/meta_test.rb