aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2017-03-29 17:23:47 -0400
committerGitHub <noreply@github.com>2017-03-29 17:23:47 -0400
commitd5a2e8baa924ba6194ad4e6ae118b4d1ca19c342 (patch)
tree8851deb0159ed80f6258db9a88f014cef9bfec9e /activesupport/test/core_ext
parentf77a6be8d23f048ced4fac54f1f4caea5e0749d7 (diff)
parent0117810cdab34d168b0579a6736c5d58c5ab84c7 (diff)
downloadrails-d5a2e8baa924ba6194ad4e6ae118b4d1ca19c342.tar.gz
rails-d5a2e8baa924ba6194ad4e6ae118b4d1ca19c342.tar.bz2
rails-d5a2e8baa924ba6194ad4e6ae118b4d1ca19c342.zip
Merge pull request #28603 from mikeastock/alias-reverse-merge
Add an alias for reverse_merge to with_defaults
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index 525ea08abd..cb6babfe49 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -535,6 +535,16 @@ class HashExtTest < ActiveSupport::TestCase
assert_equal "clobber", hash[:another]
end
+ def test_indifferent_with_defaults_aliases_reverse_merge
+ hash = HashWithIndifferentAccess.new key: :old_value
+ actual = hash.with_defaults key: :new_value
+ assert_equal :old_value, actual[:key]
+
+ hash = HashWithIndifferentAccess.new key: :old_value
+ hash.with_defaults! key: :new_value
+ assert_equal :old_value, hash[:key]
+ end
+
def test_indifferent_deleting
get_hash = proc { { a: "foo" }.with_indifferent_access }
hash = get_hash.call
@@ -848,6 +858,21 @@ class HashExtTest < ActiveSupport::TestCase
assert_equal expected, merged
end
+ def test_with_defaults_aliases_reverse_merge
+ defaults = { a: "x", b: "y", c: 10 }.freeze
+ options = { a: 1, b: 2 }
+ expected = { a: 1, b: 2, c: 10 }
+
+ # Should be an alias for reverse_merge
+ assert_equal expected, options.with_defaults(defaults)
+ assert_not_equal expected, options
+
+ # Should be an alias for reverse_merge!
+ merged = options.dup
+ assert_equal expected, merged.with_defaults!(defaults)
+ assert_equal expected, merged
+ end
+
def test_slice
original = { a: "x", b: "y", c: 10 }
expected = { a: "x", b: "y" }