diff options
author | Josh Pencheon <josh.pencheon@googlemail.com> | 2017-04-10 01:50:13 +0100 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2017-04-10 10:20:13 +0930 |
commit | 2144e70a86e6403a6298d61862e2e85615cd2a82 (patch) | |
tree | 70a23c646fde8a0a3fbc8dc0d63599ffc71be7a7 /activesupport/test/hash_with_indifferent_access_test.rb | |
parent | 24ac36be7150f97ac0a61cf7cbe7d212097ef1a6 (diff) | |
download | rails-2144e70a86e6403a6298d61862e2e85615cd2a82.tar.gz rails-2144e70a86e6403a6298d61862e2e85615cd2a82.tar.bz2 rails-2144e70a86e6403a6298d61862e2e85615cd2a82.zip |
Implement `fetch_values` for HashWithIndifferentAccess (#28316)
`fetch_values` was added to Hash in Ruby 2.3.0:
https://bugs.ruby-lang.org/issues/10017
This patch adds an implemention for instances of HWAI, in line
with the existing definitions of `fetch` and `values_at`.
Diffstat (limited to 'activesupport/test/hash_with_indifferent_access_test.rb')
-rw-r--r-- | activesupport/test/hash_with_indifferent_access_test.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/test/hash_with_indifferent_access_test.rb b/activesupport/test/hash_with_indifferent_access_test.rb index b1177c6c15..d68add46cd 100644 --- a/activesupport/test/hash_with_indifferent_access_test.rb +++ b/activesupport/test/hash_with_indifferent_access_test.rb @@ -166,6 +166,18 @@ class HashWithIndifferentAccessTest < ActiveSupport::TestCase assert_equal [1, 2], @mixed.values_at(:a, :b) end + def test_indifferent_fetch_values + skip unless Hash.method_defined?(:fetch_values) + + @mixed = @mixed.with_indifferent_access + + assert_equal [1, 2], @mixed.fetch_values("a", "b") + assert_equal [1, 2], @mixed.fetch_values(:a, :b) + assert_equal [1, 2], @mixed.fetch_values(:a, "b") + assert_equal [1, "c"], @mixed.fetch_values(:a, :c) { |key| key } + assert_raise(KeyError) { @mixed.fetch_values(:a, :c) } + end + def test_indifferent_reading hash = HashWithIndifferentAccess.new hash["a"] = 1 |