Sha256: f128ac95cef92486ecd8de47dfff574f9a512e7fff2bff527ba719871091f5f3

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

module ActiveModel
  class Serializer
    class AdapterForTest < Minitest::Test
      def setup
        @previous_adapter = ActiveModel::Serializer.config.adapter
      end

      def teardown
        ActiveModel::Serializer.config.adapter = @previous_adapter
      end

      def test_returns_default_adapter
        adapter = ActiveModel::Serializer.adapter
        assert_equal ActiveModel::Serializer::Adapter::FlattenJson, adapter
      end

      def test_overwrite_adapter_with_symbol
        ActiveModel::Serializer.config.adapter = :null

        adapter = ActiveModel::Serializer.adapter
        assert_equal ActiveModel::Serializer::Adapter::Null, adapter
      ensure
      end

      def test_overwrite_adapter_with_class
        ActiveModel::Serializer.config.adapter = ActiveModel::Serializer::Adapter::Null

        adapter = ActiveModel::Serializer.adapter
        assert_equal ActiveModel::Serializer::Adapter::Null, adapter
      end

      def test_raises_exception_if_invalid_symbol_given
        ActiveModel::Serializer.config.adapter = :unknown

        assert_raises ArgumentError do
          ActiveModel::Serializer.adapter
        end
      end

      def test_raises_exception_if_it_does_not_know_hot_to_infer_adapter
        ActiveModel::Serializer.config.adapter = 42

        assert_raises ArgumentError do
          ActiveModel::Serializer.adapter
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cheap_ams-0.10.8 test/serializers/adapter_for_test.rb
cheap_ams-0.10.7 test/serializers/adapter_for_test.rb
cheap_ams-0.10.6 test/serializers/adapter_for_test.rb