Merge pull request #2017 from bf4/remove_warnings

Fix mt6 assert_nil warnings
This commit is contained in:
Benjamin Fleischer 2017-01-07 16:23:34 -05:00 committed by GitHub
commit 3b155de03f
6 changed files with 46 additions and 30 deletions

View File

@ -33,7 +33,8 @@ module SerializationScopeTesting
end end
end end
class PostTestController < ActionController::Base class PostTestController < ActionController::Base
attr_accessor :current_user attr_writer :current_user
def render_post_by_non_admin def render_post_by_non_admin
self.current_user = User.new(id: 3, name: 'Pete', admin: false) self.current_user = User.new(id: 3, name: 'Pete', admin: false)
render json: new_post, serializer: serializer, adapter: :json render json: new_post, serializer: serializer, adapter: :json
@ -44,6 +45,10 @@ module SerializationScopeTesting
render json: new_post, serializer: serializer, adapter: :json render json: new_post, serializer: serializer, adapter: :json
end end
def current_user
defined?(@current_user) ? @current_user : :current_user_not_set
end
private private
def new_post def new_post
@ -75,7 +80,8 @@ module SerializationScopeTesting
end end
def test_default_serialization_scope_object def test_default_serialization_scope_object
assert_equal @controller.current_user, @controller.serialization_scope assert_equal :current_user_not_set, @controller.current_user
assert_equal :current_user_not_set, @controller.serialization_scope
end end
def test_default_scope_non_admin def test_default_scope_non_admin
@ -125,7 +131,7 @@ module SerializationScopeTesting
end end
def test_defined_serialization_scope_object 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 end
def test_serialization_scope_non_admin def test_serialization_scope_non_admin

View File

@ -4,11 +4,13 @@ require 'support/isolated_unit'
class RailtieTest < ActiveSupport::TestCase class RailtieTest < ActiveSupport::TestCase
include ActiveSupport::Testing::Isolation include ActiveSupport::Testing::Isolation
class WithRails < RailtieTest class WithRailsRequiredFirst < RailtieTest
setup do setup do
require 'rails' require 'rails'
require 'active_model_serializers' require 'active_model_serializers'
make_basic_app make_basic_app do |app|
app.config.action_controller.perform_caching = true
end
end end
test 'mixes ActionController::Serialization into ActionController::Base' do test 'mixes ActionController::Serialization into ActionController::Base' do
@ -32,14 +34,17 @@ class RailtieTest < ActiveSupport::TestCase
test 'it is configured for caching' do test 'it is configured for caching' do
assert_equal ActionController::Base.cache_store, ActiveModelSerializers.config.cache_store assert_equal ActionController::Base.cache_store, ActiveModelSerializers.config.cache_store
assert_equal Rails.configuration.action_controller.perform_caching, ActiveModelSerializers.config.perform_caching assert_equal true, Rails.configuration.action_controller.perform_caching
assert_equal true, ActiveModelSerializers.config.perform_caching
end end
end end
class WithoutRails < RailtieTest class WithoutRailsRequiredFirst < RailtieTest
setup do setup do
require 'active_model_serializers' require 'active_model_serializers'
make_basic_app make_basic_app do |app|
app.config.action_controller.perform_caching = true
end
end end
test 'does not mix ActionController::Serialization into ActionController::Base' do test 'does not mix ActionController::Serialization into ActionController::Base' do
@ -56,8 +61,8 @@ class RailtieTest < ActiveSupport::TestCase
test 'it is not configured for caching' do test 'it is not configured for caching' do
refute_nil ActionController::Base.cache_store refute_nil ActionController::Base.cache_store
assert_nil ActiveModelSerializers.config.cache_store assert_nil ActiveModelSerializers.config.cache_store
refute Rails.configuration.action_controller.perform_caching assert_equal true, Rails.configuration.action_controller.perform_caching
refute ActiveModelSerializers.config.perform_caching assert_nil ActiveModelSerializers.config.perform_caching
end end
end end
end end

View File

@ -146,20 +146,25 @@ module ActiveModel
end end
def test_node_not_included_when_no_link def test_node_not_included_when_no_link
expected = nil expected = { meta: {} }
assert_relationship(:unlinked_tags, expected) assert_relationship(:unlinked_tags, expected, key_transform: :unaltered)
end end
private private
def assert_relationship(relationship_name, expected, opts = {})
actual = relationship_data(relationship_name, opts)
assert_equal(expected, actual)
end
def result(opts) def result(opts)
opts = { adapter: :json_api }.merge(opts) opts = { adapter: :json_api }.merge(opts)
serializable(@author, opts).serializable_hash serializable(@author, opts).serializable_hash
end end
def assert_relationship(relationship_name, expected, opts = {}) def relationship_data(relationship_name, opts = {})
hash = result(opts) hash = result(opts)
assert_equal(expected, hash[:data][:relationships][relationship_name]) hash[:data][:relationships][relationship_name]
end end
end end
end end

View File

@ -128,7 +128,7 @@ module ActiveModelSerializers
def test_cache_key_definition def test_cache_key_definition
assert_equal('post', @post_serializer.class._cache_key) assert_equal('post', @post_serializer.class._cache_key)
assert_equal('writer', @author_serializer.class._cache_key) assert_equal('writer', @author_serializer.class._cache_key)
assert_equal(nil, @comment_serializer.class._cache_key) assert_nil(@comment_serializer.class._cache_key)
end end
def test_cache_key_interpolation_with_updated_at_when_cache_key_is_not_defined_on_object def test_cache_key_interpolation_with_updated_at_when_cache_key_is_not_defined_on_object
@ -171,7 +171,7 @@ module ActiveModelSerializers
def test_cache_options_definition def test_cache_options_definition
assert_equal({ expires_in: 0.1, skip_digest: true }, @post_serializer.class._cache_options) assert_equal({ expires_in: 0.1, skip_digest: true }, @post_serializer.class._cache_options)
assert_equal(nil, @blog_serializer.class._cache_options) assert_nil(@blog_serializer.class._cache_options)
assert_equal({ expires_in: 1.day, skip_digest: true }, @comment_serializer.class._cache_options) assert_equal({ expires_in: 1.day, skip_digest: true }, @comment_serializer.class._cache_options)
end end
@ -182,8 +182,8 @@ module ActiveModelSerializers
def test_associations_separately_cache def test_associations_separately_cache
cache_store.clear cache_store.clear
assert_equal(nil, cache_store.fetch(@post.cache_key)) assert_nil(cache_store.fetch(@post.cache_key))
assert_equal(nil, cache_store.fetch(@comment.cache_key)) assert_nil(cache_store.fetch(@comment.cache_key))
Timecop.freeze(Time.current) do Timecop.freeze(Time.current) do
render_object_with_cache(@post) render_object_with_cache(@post)

View File

@ -69,9 +69,9 @@ class CachingConfigurationTest < ActiveSupport::TestCase
end end
test 'the non-cached serializer cache_store is nil' do test 'the non-cached serializer cache_store is nil' do
assert_equal nil, @non_cached_serializer._cache assert_nil @non_cached_serializer._cache
assert_equal nil, @non_cached_serializer.cache_store assert_nil @non_cached_serializer.cache_store
assert_equal nil, @non_cached_serializer._cache assert_nil @non_cached_serializer._cache
end end
test 'the non-cached serializer does not have cache_enabled?' do test 'the non-cached serializer does not have cache_enabled?' do
@ -136,9 +136,9 @@ class CachingConfigurationTest < ActiveSupport::TestCase
end end
test 'the non-cached serializer cache_store is nil' do test 'the non-cached serializer cache_store is nil' do
assert_equal nil, @non_cached_serializer._cache assert_nil @non_cached_serializer._cache
assert_equal nil, @non_cached_serializer.cache_store assert_nil @non_cached_serializer.cache_store
assert_equal nil, @non_cached_serializer._cache assert_nil @non_cached_serializer._cache
end end
test 'the non-cached serializer does not have cache_enabled?' do test 'the non-cached serializer does not have cache_enabled?' do

View File

@ -59,7 +59,7 @@ module ActiveModel
def test_serializer_for_non_ams_serializer def test_serializer_for_non_ams_serializer
serializer = ActiveModel::Serializer.serializer_for(@tweet) serializer = ActiveModel::Serializer.serializer_for(@tweet)
assert_equal nil, serializer assert_nil serializer
end end
def test_serializer_for_existing_serializer def test_serializer_for_existing_serializer
@ -71,12 +71,12 @@ module ActiveModel
serializer = with_serializer_lookup_disabled do serializer = with_serializer_lookup_disabled do
ActiveModel::Serializer.serializer_for(@profile) ActiveModel::Serializer.serializer_for(@profile)
end end
assert_equal nil, serializer assert_nil serializer
end end
def test_serializer_for_not_existing_serializer def test_serializer_for_not_existing_serializer
serializer = ActiveModel::Serializer.serializer_for(@model) serializer = ActiveModel::Serializer.serializer_for(@model)
assert_equal nil, serializer assert_nil serializer
end end
def test_serializer_inherited_serializer def test_serializer_inherited_serializer
@ -88,7 +88,7 @@ module ActiveModel
serializer = with_serializer_lookup_disabled do serializer = with_serializer_lookup_disabled do
ActiveModel::Serializer.serializer_for(@my_profile) ActiveModel::Serializer.serializer_for(@my_profile)
end end
assert_equal nil, serializer assert_nil serializer
end end
def test_serializer_custom_serializer def test_serializer_custom_serializer
@ -114,7 +114,7 @@ module ActiveModel
serializer = with_serializer_lookup_disabled do serializer = with_serializer_lookup_disabled do
ActiveModel::Serializer.serializer_for(post) ActiveModel::Serializer.serializer_for(post)
end end
assert_equal nil, serializer assert_nil serializer
end end
def test_serializer_for_nested_resource def test_serializer_for_nested_resource
@ -128,7 +128,7 @@ module ActiveModel
serializer = with_serializer_lookup_disabled do serializer = with_serializer_lookup_disabled do
ResourceNamespace::PostSerializer.serializer_for(comment) ResourceNamespace::PostSerializer.serializer_for(comment)
end end
assert_equal nil, serializer assert_nil serializer
end end
end end
end end