Sha256: ba41653b950891875e8255d157161b440c6066108312197e9a065ec36729d1d6

Contents?: true

Size: 1.63 KB

Versions: 6

Compression:

Stored size: 1.63 KB

Contents

require 'test_helper'

module ActionController
  module Serialization
    class AdapterSelectorTest < ActionController::TestCase
      class AdapterSelectorTestController < ActionController::Base
        def render_using_default_adapter
          @profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
          render json: @profile
        end

        def render_using_adapter_override
          @profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
          render json: @profile, adapter: :json_api
        end

        def render_skipping_adapter
          @profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
          render json: @profile, adapter: false
        end
      end

      tests AdapterSelectorTestController

      def test_render_using_default_adapter
        get :render_using_default_adapter
        assert_equal '{"name":"Name 1","description":"Description 1"}', response.body
      end

      def test_render_using_adapter_override
        get :render_using_adapter_override

        expected = {
          data: {
            id: assigns(:profile).id.to_s,
            type: 'profiles',
            attributes: {
              name: 'Name 1',
              description: 'Description 1',
            }
          }
        }

        assert_equal expected.to_json, response.body
      end

      def test_render_skipping_adapter
        get :render_skipping_adapter
        assert_equal '{"attributes":{"name":"Name 1","description":"Description 1","comments":"Comments 1"}}', response.body
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
active_model_serializers-0.10.0.rc3 test/action_controller/adapter_selector_test.rb
cheap_ams-0.10.11 test/action_controller/adapter_selector_test.rb
cheap_ams-0.10.10 test/action_controller/adapter_selector_test.rb
cheap_ams-0.10.8 test/action_controller/adapter_selector_test.rb
cheap_ams-0.10.7 test/action_controller/adapter_selector_test.rb
cheap_ams-0.10.6 test/action_controller/adapter_selector_test.rb