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