提交 1b0526ea 编写于 作者: S Shuhei Kagawa 提交者: Shuhei Kagawa

Return super in ActionController::Parameters.const_missing

The current implementation of ActionController::Parameters.const_missing
returns `ActionController::Parameters.always_permitted_parameters` even
if its `super` returns a constant without raising error. This prevents its
subclass in a autoloading module/class from taking advantage of
autoloading constants.

    class SomeParameters < ActionController::Parameters
      def do_something
        DefinedSomewhere.do_something
      end
    end

In the code above, `DefinedSomewhere` is to be autoloaded with
`Module.const_missing` but `ActionController::Parameters.const_missing`
returns `always_permitted_parameters` instead of the autoloaded
constant.

This pull request fixes the issue respecting `const_missing`'s `super`.
上级 e1b967e7
......@@ -117,7 +117,7 @@ class Parameters < ActiveSupport::HashWithIndifferentAccess
self.always_permitted_parameters = %w( controller action )
def self.const_missing(const_name)
super unless const_name == :NEVER_UNPERMITTED_PARAMS
return super unless const_name == :NEVER_UNPERMITTED_PARAMS
ActiveSupport::Deprecation.warn(<<-MSG.squish)
`ActionController::Parameters::NEVER_UNPERMITTED_PARAMS` has been deprecated.
Use `ActionController::Parameters.always_permitted_parameters` instead.
......
require 'abstract_unit'
require 'action_controller/metal/strong_parameters'
require 'minitest/mock'
class AlwaysPermittedParametersTest < ActiveSupport::TestCase
def setup
......@@ -14,7 +15,13 @@ def teardown
test "shows deprecations warning on NEVER_UNPERMITTED_PARAMS" do
assert_deprecated do
ActionController::Parameters::NEVER_UNPERMITTED_PARAMS
ActionController::Parameters::NEVER_UNPERMITTED_PARAMS
end
end
test "returns super on missing constant other than NEVER_UNPERMITTED_PARAMS" do
ActionController::Parameters.superclass.stub :const_missing, "super" do
assert_equal "super", ActionController::Parameters::NON_EXISTING_CONSTANT
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册