Sha256: b4148ea47d6428a97e7b3378762058a75609bb02611794b7958dc93ef940156e

Contents?: true

Size: 1.67 KB

Versions: 9

Compression:

Stored size: 1.67 KB

Contents

require 'test_helper'
require 'pathname'

class DefaultScopeNameTest < ActionController::TestCase
  class UserSerializer < ActiveModel::Serializer
    attributes :admin?
    ActiveModelSerializers.silence_warnings do
      def admin?
        current_user.admin
      end
    end
  end

  class UserTestController < ActionController::Base
    protect_from_forgery

    before_filter { request.format = :json }

    def current_user
      User.new(id: 1, name: 'Pete', admin: false)
    end

    def render_new_user
      render json: User.new(id: 1, name: 'Pete', admin: false), serializer: UserSerializer, adapter: :json_api
    end
  end

 tests UserTestController

  def test_default_scope_name
    get :render_new_user
    assert_equal '{"data":{"id":"1","type":"users","attributes":{"admin?":false}}}', @response.body
  end
end

class SerializationScopeNameTest < ActionController::TestCase
  class AdminUserSerializer < ActiveModel::Serializer
    attributes :admin?
    ActiveModelSerializers.silence_warnings do
      def admin?
        current_admin.admin
      end
    end
  end

  class AdminUserTestController < ActionController::Base
    protect_from_forgery

    serialization_scope :current_admin
    before_filter { request.format = :json }

    def current_admin
      User.new(id: 2, name: 'Bob', admin: true)
    end

    def render_new_user
      render json: User.new(id: 1, name: 'Pete', admin: false), serializer: AdminUserSerializer, adapter: :json_api
    end
  end

  tests AdminUserTestController

  def test_override_scope_name_with_controller
    get :render_new_user
    assert_equal '{"data":{"id":"1","type":"users","attributes":{"admin?":true}}}', @response.body
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cheap_ams-0.10.8 test/action_controller/serialization_scope_name_test.rb
cheap_ams-0.10.7 test/action_controller/serialization_scope_name_test.rb
cheap_ams-0.10.6 test/action_controller/serialization_scope_name_test.rb
cheap_ams-0.10.5 test/action_controller/serialization_scope_name_test.rb
cheap_ams-0.10.4 test/action_controller/serialization_scope_name_test.rb
cheap_ams-0.10.3 test/action_controller/serialization_scope_name_test.rb
cheap_ams-0.10.2 test/action_controller/serialization_scope_name_test.rb
cheap_ams-0.10.1 test/action_controller/serialization_scope_name_test.rb
cheap_ams-0.10.0.rc2 test/action_controller/serialization_scope_name_test.rb