Sha256: 1470dba147255b7e896ef8c545a684296a50d370dd0a170dd952df36f0accfed

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

require 'test_helper'

module ActionController
  module Serialization
    class AdapterSelectorTest < ActionController::TestCase
      class MyController < 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 MyController

      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: {
            name: "Name 1",
            description: "Description 1",
            id: assigns(:profile).id.to_s,
            type: "profiles"
          }
        }

        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

2 entries across 2 versions & 2 rubygems

Version Path
cm-active_model_serializers-0.10.0.rc1.1 test/action_controller/adapter_selector_test.rb
active_model_serializers-0.10.0.rc1 test/action_controller/adapter_selector_test.rb