Sha256: 2e3dadadfdb133c1a5a72554ce3a3daca484d229008169a10dcce4361140cb66

Contents?: true

Size: 1.72 KB

Versions: 6

Compression:

Stored size: 1.72 KB

Contents

require 'test_helper'

module ActiveModel
  class SerializableTest
    class InstrumentationTest < Minitest::Test
      def setup
        @events = []

        @subscriber = ActiveSupport::Notifications.subscribe('!serialize.active_model_serializers') do |name, start, finish, id, payload|
          @events << { name: name, serializer: payload[:serializer] }
        end
      end

      def teardown
        ActiveSupport::Notifications.unsubscribe(@subscriber) if defined?(@subscriber)
      end

      def test_instruments_default_serializer
        DefaultSerializer.new(1).as_json

        assert_equal [{ name: '!serialize.active_model_serializers', serializer: 'ActiveModel::DefaultSerializer' }], @events
      end

      def test_instruments_serializer
        profile = Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
        serializer = ProfileSerializer.new(profile)

        serializer.as_json

        assert_equal [{ name: '!serialize.active_model_serializers', serializer: 'ProfileSerializer' }], @events
      end

      def test_instruments_array_serializer
        profiles = [
          Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1'),
          Profile.new(name: 'Name 2', description: 'Description 2', comments: 'Comments 2')
        ]
        serializer = ArraySerializer.new(profiles)

        serializer.as_json

        assert_equal [
          { name: '!serialize.active_model_serializers', serializer: 'ProfileSerializer' },
          { name: '!serialize.active_model_serializers', serializer: 'ProfileSerializer' },
          { name: '!serialize.active_model_serializers', serializer: 'ActiveModel::ArraySerializer' }
        ], @events
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
active_model_serializers-0.9.13 test/unit/active_model/serilizable_test.rb
active_model_serializers-0.9.12 test/unit/active_model/serilizable_test.rb
active_model_serializers-0.9.11 test/unit/active_model/serilizable_test.rb
active_model_serializers-0.9.9 test/unit/active_model/serilizable_test.rb
active_model_serializers-0.9.8 test/unit/active_model/serilizable_test.rb
active_model_serializers-0.9.7 test/unit/active_model/serilizable_test.rb