mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #34012 from abraham-chan/indifferent-access-without
Fix HashWithIndifferentAccess#without bug
This commit is contained in:
commit
7d3f1c414f
3 changed files with 18 additions and 0 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue