From 6fbeb9a93ea6e603118b54244bd79f2e1fe4c21d Mon Sep 17 00:00:00 2001 From: Kyle Keesling Date: Tue, 26 Feb 2019 23:26:24 -0500 Subject: [PATCH] Fix deprecation warnings on Rails 6 takes into account suggestions from @bf4 --- lib/action_controller/serialization.rb | 10 +++++++++- test/action_controller/namespace_lookup_test.rb | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/action_controller/serialization.rb b/lib/action_controller/serialization.rb index 45c26ad4..904c758c 100644 --- a/lib/action_controller/serialization.rb +++ b/lib/action_controller/serialization.rb @@ -23,7 +23,15 @@ module ActionController end def namespace_for_serializer - @namespace_for_serializer ||= self.class.parent unless self.class.parent == Object + @namespace_for_serializer ||= namespace_for_class(self.class) unless namespace_for_class(self.class) == Object + end + + def namespace_for_class(klass) + if Module.method_defined?(:module_parent) + klass.module_parent + else + klass.parent + end end def serialization_scope diff --git a/test/action_controller/namespace_lookup_test.rb b/test/action_controller/namespace_lookup_test.rb index cbb267ce..2fe961cf 100644 --- a/test/action_controller/namespace_lookup_test.rb +++ b/test/action_controller/namespace_lookup_test.rb @@ -125,7 +125,12 @@ module ActionController tests Api::V3::LookupTestController setup do - @test_namespace = self.class.parent + @test_namespace = + if Module.method_defined?(:module_parent) + self.class.module_parent + else + self.class.parent + end end test 'uses request headers to determine the namespace' do