From a5423dab20de829fe1a7db2af1a94183b7127999 Mon Sep 17 00:00:00 2001 From: Benjamin Fleischer Date: Sat, 7 Jan 2017 16:23:34 -0500 Subject: [PATCH] Merge pull request #2017 from bf4/remove_warnings Fix mt6 assert_nil warnings --- .../serialization_scope_name_test.rb | 12 +++++++++--- .../railtie_test_isolated.rb | 19 ++++++++++++------- .../include_data_if_sideloaded_test.rb | 13 +++++++++---- test/cache_test.rb | 8 ++++---- .../caching_configuration_test_isolated.rb | 12 ++++++------ test/serializers/serializer_for_test.rb | 12 ++++++------ 6 files changed, 46 insertions(+), 30 deletions(-) diff --git a/test/action_controller/serialization_scope_name_test.rb b/test/action_controller/serialization_scope_name_test.rb index 62959455..e9d6c823 100644 --- a/test/action_controller/serialization_scope_name_test.rb +++ b/test/action_controller/serialization_scope_name_test.rb @@ -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,7 +80,8 @@ module SerializationScopeTesting end 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 def test_default_scope_non_admin @@ -125,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 diff --git a/test/active_model_serializers/railtie_test_isolated.rb b/test/active_model_serializers/railtie_test_isolated.rb index 21f6c178..1044fc8b 100644 --- a/test/active_model_serializers/railtie_test_isolated.rb +++ b/test/active_model_serializers/railtie_test_isolated.rb @@ -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,14 +34,17 @@ class RailtieTest < ActiveSupport::TestCase test 'it is configured for caching' do 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 - 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 @@ -56,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 diff --git a/test/adapter/json_api/include_data_if_sideloaded_test.rb b/test/adapter/json_api/include_data_if_sideloaded_test.rb index 1c97191d..fbbd75ab 100644 --- a/test/adapter/json_api/include_data_if_sideloaded_test.rb +++ b/test/adapter/json_api/include_data_if_sideloaded_test.rb @@ -144,20 +144,25 @@ module ActiveModel end def test_node_not_included_when_no_link - expected = nil - assert_relationship(:unlinked_tags, expected) + expected = { meta: {} } + assert_relationship(:unlinked_tags, expected, key_transform: :unaltered) end private + def assert_relationship(relationship_name, expected, opts = {}) + actual = relationship_data(relationship_name, opts) + assert_equal(expected, actual) + end + def result(opts) opts = { adapter: :json_api }.merge(opts) serializable(@author, opts).serializable_hash end - def assert_relationship(relationship_name, expected, opts = {}) + def relationship_data(relationship_name, opts = {}) hash = result(opts) - assert_equal(expected, hash[:data][:relationships][relationship_name]) + hash[:data][:relationships][relationship_name] end end end diff --git a/test/cache_test.rb b/test/cache_test.rb index c0770cda..bcf078c2 100644 --- a/test/cache_test.rb +++ b/test/cache_test.rb @@ -117,7 +117,7 @@ module ActiveModelSerializers def test_cache_key_definition assert_equal('post', @post_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 def test_cache_key_interpolation_with_updated_at_when_cache_key_is_not_defined_on_object @@ -160,7 +160,7 @@ module ActiveModelSerializers def test_cache_options_definition 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) end @@ -171,8 +171,8 @@ module ActiveModelSerializers def test_associations_separately_cache cache_store.clear - assert_equal(nil, cache_store.fetch(@post.cache_key)) - assert_equal(nil, cache_store.fetch(@comment.cache_key)) + assert_nil(cache_store.fetch(@post.cache_key)) + assert_nil(cache_store.fetch(@comment.cache_key)) Timecop.freeze(Time.current) do render_object_with_cache(@post) diff --git a/test/serializers/caching_configuration_test_isolated.rb b/test/serializers/caching_configuration_test_isolated.rb index 82e497b2..b5698dd1 100644 --- a/test/serializers/caching_configuration_test_isolated.rb +++ b/test/serializers/caching_configuration_test_isolated.rb @@ -69,9 +69,9 @@ class CachingConfigurationTest < ActiveSupport::TestCase end test 'the non-cached serializer cache_store is nil' do - assert_equal nil, @non_cached_serializer._cache - assert_equal nil, @non_cached_serializer.cache_store - assert_equal nil, @non_cached_serializer._cache + assert_nil @non_cached_serializer._cache + assert_nil @non_cached_serializer.cache_store + assert_nil @non_cached_serializer._cache end test 'the non-cached serializer does not have cache_enabled?' do @@ -136,9 +136,9 @@ class CachingConfigurationTest < ActiveSupport::TestCase end test 'the non-cached serializer cache_store is nil' do - assert_equal nil, @non_cached_serializer._cache - assert_equal nil, @non_cached_serializer.cache_store - assert_equal nil, @non_cached_serializer._cache + assert_nil @non_cached_serializer._cache + assert_nil @non_cached_serializer.cache_store + assert_nil @non_cached_serializer._cache end test 'the non-cached serializer does not have cache_enabled?' do diff --git a/test/serializers/serializer_for_test.rb b/test/serializers/serializer_for_test.rb index b7607cfe..9f691708 100644 --- a/test/serializers/serializer_for_test.rb +++ b/test/serializers/serializer_for_test.rb @@ -59,7 +59,7 @@ module ActiveModel def test_serializer_for_non_ams_serializer serializer = ActiveModel::Serializer.serializer_for(@tweet) - assert_equal nil, serializer + assert_nil serializer end def test_serializer_for_existing_serializer @@ -71,12 +71,12 @@ module ActiveModel serializer = with_serializer_lookup_disabled do ActiveModel::Serializer.serializer_for(@profile) end - assert_equal nil, serializer + assert_nil serializer end def test_serializer_for_not_existing_serializer serializer = ActiveModel::Serializer.serializer_for(@model) - assert_equal nil, serializer + assert_nil serializer end def test_serializer_inherited_serializer @@ -88,7 +88,7 @@ module ActiveModel serializer = with_serializer_lookup_disabled do ActiveModel::Serializer.serializer_for(@my_profile) end - assert_equal nil, serializer + assert_nil serializer end def test_serializer_custom_serializer @@ -114,7 +114,7 @@ module ActiveModel serializer = with_serializer_lookup_disabled do ActiveModel::Serializer.serializer_for(post) end - assert_equal nil, serializer + assert_nil serializer end def test_serializer_for_nested_resource @@ -128,7 +128,7 @@ module ActiveModel serializer = with_serializer_lookup_disabled do ResourceNamespace::PostSerializer.serializer_for(comment) end - assert_equal nil, serializer + assert_nil serializer end end end