aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbraham Chan <abraham@rangeme.com>2018-09-28 18:28:30 +1000
committerAbraham Chan <abraham@rangeme.com>2018-09-28 18:28:56 +1000
commitb2ea8310734b734c29b806f272c866045fc9bca7 (patch)
treeb60fe55248cb8ce1f0065e756e010d07854439e9
parent2ab0df00b69335986f1116b7bea17c1ed0f52d9f (diff)
downloadrails-b2ea8310734b734c29b806f272c866045fc9bca7.tar.gz
rails-b2ea8310734b734c29b806f272c866045fc9bca7.tar.bz2
rails-b2ea8310734b734c29b806f272c866045fc9bca7.zip
Fix HashWithIndifferentAccess#without bug
-rw-r--r--activesupport/CHANGELOG.md5
-rw-r--r--activesupport/lib/active_support/hash_with_indifferent_access.rb2
-rw-r--r--activesupport/test/hash_with_indifferent_access_test.rb11
3 files changed, 18 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 39f366bc88..3a348a26bf 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Fix bug where `#without` for `ActiveSupport::HashWithIndifferentAccess` would fail
+ with symbol arguments
+
+ *Abraham Chan*
+
* Treat `#delete_prefix`, `#delete_suffix` and `#unicode_normalize` results as non-`html_safe`.
Ensure safety of arguments for `#insert`, `#[]=` and `#replace` calls on `html_safe` Strings.
diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb
index e4afc8af93..b9e64ed05d 100644
--- a/activesupport/lib/active_support/hash_with_indifferent_access.rb
+++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb
@@ -279,6 +279,8 @@ module ActiveSupport
super(convert_key(key))
end
+ alias_method :without, :except
+
def stringify_keys!; self end
def deep_stringify_keys!; self end
def stringify_keys; dup end
diff --git a/activesupport/test/hash_with_indifferent_access_test.rb b/activesupport/test/hash_with_indifferent_access_test.rb
index eebff18ef1..af67ed21c8 100644
--- a/activesupport/test/hash_with_indifferent_access_test.rb
+++ b/activesupport/test/hash_with_indifferent_access_test.rb
@@ -672,6 +672,17 @@ class HashWithIndifferentAccessTest < ActiveSupport::TestCase
assert_equal "bender", slice["login"]
end
+ def test_indifferent_without
+ original = { a: "x", b: "y", c: 10 }.with_indifferent_access
+ expected = { c: 10 }.with_indifferent_access
+
+ [["a", "b"], [:a, :b]].each do |keys|
+ # Should return a new hash without the given keys.
+ assert_equal expected, original.without(*keys), keys.inspect
+ assert_not_equal expected, original
+ end
+ end
+
def test_indifferent_extract
original = { :a => 1, "b" => 2, :c => 3, "d" => 4 }.with_indifferent_access
expected = { a: 1, b: 2 }.with_indifferent_access