Sha256: fa1daf594adb19c2e2df2e8cc096a11fb6b47fa05cfaf9deb7780c66aeadeffd
Contents?: true
Size: 1.54 KB
Versions: 1
Compression:
Stored size: 1.54 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":{"id":"1","type":"users","attributes":{"admin?":false}}}', @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":{"id":"1","type":"users","attributes":{"admin?":true}}}', @response.body end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_model_serializers-0.10.0.rc2 | test/action_controller/serialization_scope_name_test.rb |