diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-24 19:47:20 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-02-24 19:50:53 +0900 |
commit | a99e00452b00599f5f8b5289bd17c7fe5e502d2e (patch) | |
tree | 606a282887c33503600af003e8f94335c8e07c03 /activerecord/test/support/stubs/strong_parameters.rb | |
parent | 257564d65a87bd2cccfd4ef78ae4b9a49c476f5d (diff) | |
download | rails-a99e00452b00599f5f8b5289bd17c7fe5e502d2e.tar.gz rails-a99e00452b00599f5f8b5289bd17c7fe5e502d2e.tar.bz2 rails-a99e00452b00599f5f8b5289bd17c7fe5e502d2e.zip |
Remove duplicated protected params definitions
Use "support/stubs/strong_parameters" instead.
Diffstat (limited to 'activerecord/test/support/stubs/strong_parameters.rb')
-rw-r--r-- | activerecord/test/support/stubs/strong_parameters.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/activerecord/test/support/stubs/strong_parameters.rb b/activerecord/test/support/stubs/strong_parameters.rb index 84f93a28b9..da8f9892f9 100644 --- a/activerecord/test/support/stubs/strong_parameters.rb +++ b/activerecord/test/support/stubs/strong_parameters.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true -class Parameters +require "active_support/core_ext/hash/indifferent_access" + +class ProtectedParams + delegate :keys, :key?, :has_key?, :empty?, to: :@parameters + def initialize(parameters = {}) @parameters = parameters.with_indifferent_access @permitted = false @@ -15,7 +19,22 @@ class Parameters self end + def [](key) + @parameters[key] + end + def to_h @parameters.to_h end + alias to_unsafe_h to_h + + def stringify_keys + dup + end + + def dup + super.tap do |duplicate| + duplicate.instance_variable_set :@permitted, @permitted + end + end end |