From a99e00452b00599f5f8b5289bd17c7fe5e502d2e Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sun, 24 Feb 2019 19:47:20 +0900 Subject: Remove duplicated protected params definitions Use "support/stubs/strong_parameters" instead. --- .../test/support/stubs/strong_parameters.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'activerecord/test/support') 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 -- cgit v1.2.3