mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Improve tests found by assert_nil
This commit is contained in:
parent
4dfbe2747b
commit
c52af54b4e
@ -33,7 +33,8 @@ module SerializationScopeTesting
|
||||
end
|
||||
end
|
||||
class PostTestController < ActionController::Base
|
||||
attr_accessor :current_user
|
||||
attr_writer :current_user
|
||||
|
||||
def render_post_by_non_admin
|
||||
self.current_user = User.new(id: 3, name: 'Pete', admin: false)
|
||||
render json: new_post, serializer: serializer, adapter: :json
|
||||
@ -44,6 +45,10 @@ module SerializationScopeTesting
|
||||
render json: new_post, serializer: serializer, adapter: :json
|
||||
end
|
||||
|
||||
def current_user
|
||||
defined?(@current_user) ? @current_user : :current_user_not_set
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def new_post
|
||||
@ -75,10 +80,8 @@ module SerializationScopeTesting
|
||||
end
|
||||
|
||||
def test_default_serialization_scope_object
|
||||
expected = @controller.current_user
|
||||
actual = @controller.serialization_scope
|
||||
assert_nil expected
|
||||
assert_nil actual
|
||||
assert_equal :current_user_not_set, @controller.current_user
|
||||
assert_equal :current_user_not_set, @controller.serialization_scope
|
||||
end
|
||||
|
||||
def test_default_scope_non_admin
|
||||
@ -128,7 +131,7 @@ module SerializationScopeTesting
|
||||
end
|
||||
|
||||
def test_defined_serialization_scope_object
|
||||
assert_equal @controller.view_context.class, @controller.serialization_scope.class
|
||||
assert_equal @controller.view_context.controller, @controller.serialization_scope.controller
|
||||
end
|
||||
|
||||
def test_serialization_scope_non_admin
|
||||
|
||||
@ -4,11 +4,13 @@ require 'support/isolated_unit'
|
||||
class RailtieTest < ActiveSupport::TestCase
|
||||
include ActiveSupport::Testing::Isolation
|
||||
|
||||
class WithRails < RailtieTest
|
||||
class WithRailsRequiredFirst < RailtieTest
|
||||
setup do
|
||||
require 'rails'
|
||||
require 'active_model_serializers'
|
||||
make_basic_app
|
||||
make_basic_app do |app|
|
||||
app.config.action_controller.perform_caching = true
|
||||
end
|
||||
end
|
||||
|
||||
test 'mixes ActionController::Serialization into ActionController::Base' do
|
||||
@ -32,17 +34,17 @@ class RailtieTest < ActiveSupport::TestCase
|
||||
|
||||
test 'it is configured for caching' do
|
||||
assert_equal ActionController::Base.cache_store, ActiveModelSerializers.config.cache_store
|
||||
expected = Rails.configuration.action_controller.perform_caching
|
||||
actual = ActiveModelSerializers.config.perform_caching
|
||||
assert_nil expected
|
||||
assert_nil actual
|
||||
assert_equal true, Rails.configuration.action_controller.perform_caching
|
||||
assert_equal true, ActiveModelSerializers.config.perform_caching
|
||||
end
|
||||
end
|
||||
|
||||
class WithoutRails < RailtieTest
|
||||
class WithoutRailsRequiredFirst < RailtieTest
|
||||
setup do
|
||||
require 'active_model_serializers'
|
||||
make_basic_app
|
||||
make_basic_app do |app|
|
||||
app.config.action_controller.perform_caching = true
|
||||
end
|
||||
end
|
||||
|
||||
test 'does not mix ActionController::Serialization into ActionController::Base' do
|
||||
@ -59,8 +61,8 @@ class RailtieTest < ActiveSupport::TestCase
|
||||
test 'it is not configured for caching' do
|
||||
refute_nil ActionController::Base.cache_store
|
||||
assert_nil ActiveModelSerializers.config.cache_store
|
||||
refute Rails.configuration.action_controller.perform_caching
|
||||
refute ActiveModelSerializers.config.perform_caching
|
||||
assert_equal true, Rails.configuration.action_controller.perform_caching
|
||||
assert_nil ActiveModelSerializers.config.perform_caching
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user