Sha256: d69794980ed0218f2a62206744b17aa38ad3ae16b9b1723eee9edea7f343dbce
Contents?: true
Size: 1.52 KB
Versions: 2
Compression:
Stored size: 1.52 KB
Contents
require 'test_helper' require 'pathname' class DefaultScopeNameTest < ActionController::TestCase class UserSerializer < ActiveModel::Serializer attributes :admin? def admin? current_user.admin 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":{"admin?":false,"id":"1","type":"users"}}', @response.body end end class SerializationScopeNameTest < ActionController::TestCase class AdminUserSerializer < ActiveModel::Serializer attributes :admin? def admin? current_admin.admin 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":{"admin?":true,"id":"1","type":"users"}}', @response.body end end
Version data entries
2 entries across 2 versions & 2 rubygems