diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-07-17 11:52:56 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-07-17 11:52:56 -0700 |
commit | 636e6b7138864ceb1e309939cd879e710b287f3e (patch) | |
tree | 2a36dfef02f706302a20bb5b2d428b32e9af97f0 /activesupport/test/core_ext | |
parent | 842917dea0cfdf70f158a312cc1f77f769791d8c (diff) | |
parent | 99930d499e424f4560b371412e05d10476216ece (diff) | |
download | rails-636e6b7138864ceb1e309939cd879e710b287f3e.tar.gz rails-636e6b7138864ceb1e309939cd879e710b287f3e.tar.bz2 rails-636e6b7138864ceb1e309939cd879e710b287f3e.zip |
Merge branch 'master' into i18n-merge
Conflicts:
actionpack/lib/action_view/helpers/form_options_helper.rb
activerecord/lib/active_record/validations.rb
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 31 | ||||
-rw-r--r-- | activesupport/test/core_ext/object_and_class_ext_test.rb | 8 |
2 files changed, 39 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 69028a123f..fc8ed45358 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -245,6 +245,16 @@ class HashExtTest < Test::Unit::TestCase assert(!indiff.keys.any? {|k| k.kind_of? String}, "A key was converted to a string!") end + def test_deep_merge + hash_1 = { :a => "a", :b => "b", :c => { :c1 => "c1", :c2 => "c2", :c3 => { :d1 => "d1" } } } + hash_2 = { :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } } + expected = { :a => 1, :b => "b", :c => { :c1 => 2, :c2 => "c2", :c3 => { :d1 => "d1", :d2 => "d2" } } } + assert_equal expected, hash_1.deep_merge(hash_2) + + hash_1.deep_merge!(hash_2) + assert_equal expected, hash_1 + end + def test_reverse_merge defaults = { :a => "x", :b => "y", :c => 10 }.freeze options = { :a => 1, :b => 2 } @@ -282,6 +292,27 @@ class HashExtTest < Test::Unit::TestCase assert_equal expected, original end + def test_slice_with_an_array_key + original = { :a => 'x', :b => 'y', :c => 10, [:a, :b] => "an array key" } + expected = { [:a, :b] => "an array key", :c => 10 } + + # Should return a new hash with only the given keys when given an array key. + assert_equal expected, original.slice([:a, :b], :c) + assert_not_equal expected, original + + # Should replace the hash with only the given keys when given an array key. + assert_equal expected, original.slice!([:a, :b], :c) + assert_equal expected, original + end + + def test_slice_with_splatted_keys + original = { :a => 'x', :b => 'y', :c => 10, [:a, :b] => "an array key" } + expected = { :a => 'x', :b => "y" } + + # Should grab each of the splatted keys. + assert_equal expected, original.slice(*[:a, :b]) + end + def test_indifferent_slice original = { :a => 'x', :b => 'y', :c => 10 }.with_indifferent_access expected = { :a => 'x', :b => 'y' }.with_indifferent_access diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index 16f4ab888e..b0a746fdc7 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -173,6 +173,14 @@ class ObjectTests < Test::Unit::TestCase assert duck.acts_like?(:time) assert !duck.acts_like?(:date) end + + def test_metaclass + string = "Hello" + string.metaclass.instance_eval do + define_method(:foo) { "bar" } + end + assert_equal "bar", string.foo + end end class ObjectInstanceVariableTest < Test::Unit::TestCase |