Sha256: fa7c8214c88e70104d900948cabf62d7b4bf47a8c5b39a11f13fbc30de87456a

Contents?: true

Size: 1.9 KB

Versions: 12

Compression:

Stored size: 1.9 KB

Contents

require 'test_helper'

module ActiveModelSerializers
  module Test
    class SerializerTest < ActionController::TestCase
      include ActiveModelSerializers::Test::Serializer

      class MyController < ActionController::Base
        def render_using_serializer
          render json: Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1')
        end

        def render_some_text
          render(plain: 'ok')
        end
      end

      tests MyController

      def test_supports_specifying_serializers_with_a_serializer_class
        get :render_using_serializer
        assert_serializer ProfileSerializer
      end

      def test_supports_specifying_serializers_with_a_regexp
        get :render_using_serializer
        assert_serializer(/\AProfile.+\Z/)
      end

      def test_supports_specifying_serializers_with_a_string
        get :render_using_serializer
        assert_serializer 'ProfileSerializer'
      end

      def test_supports_specifying_serializers_with_a_symbol
        get :render_using_serializer
        assert_serializer :profile_serializer
      end

      def test_supports_specifying_serializers_with_a_nil
        get :render_some_text
        assert_serializer nil
      end

      def test_raises_descriptive_error_message_when_serializer_was_not_rendered
        get :render_using_serializer
        e = assert_raise ActiveSupport::TestCase::Assertion do
          assert_serializer 'PostSerializer'
        end
        assert_match 'expecting <"PostSerializer"> but rendering with <["ProfileSerializer"]>', e.message
      end

      def test_raises_argument_error_when_asserting_with_invalid_object
        get :render_using_serializer
        e = assert_raise ArgumentError do
          assert_serializer Hash
        end
        assert_match 'assert_serializer only accepts a String, Symbol, Regexp, ActiveModel::Serializer, or nil', e.message
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
active_model_serializers-0.10.8 test/active_model_serializers/test/serializer_test.rb
active_model_serializers-0.10.7 test/active_model_serializers/test/serializer_test.rb
active_model_serializers-0.10.6 test/active_model_serializers/test/serializer_test.rb
active_model_serializers-0.10.5 test/active_model_serializers/test/serializer_test.rb
active_model_serializers-0.10.4 test/active_model_serializers/test/serializer_test.rb
agi_active_model_serializers-0.10.9 test/active_model_serializers/test/serializer_test.rb
agi_active_model_serializers-0.10.8 test/active_model_serializers/test/serializer_test.rb
agi_active_model_serializers-0.10.7 test/active_model_serializers/test/serializer_test.rb
active_model_serializers-0.10.3 test/active_model_serializers/test/serializer_test.rb
active_model_serializers-0.10.2 test/active_model_serializers/test/serializer_test.rb
active_model_serializers-0.10.1 test/active_model_serializers/test/serializer_test.rb
active_model_serializers-0.10.0 test/active_model_serializers/test/serializer_test.rb