From 8ae68efcf84d9c9927c4db7dfeb0f41693b9e555 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 11 Sep 2005 08:23:50 +0000 Subject: Added Hash#reverse_merge, Hash#reverse_merge!, and Hash#reverse_update to ease the use of default options. Added :connector and :skip_last_comma options to Array#to_sentence git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2192 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/test/core_ext/array_ext_test.rb | 10 +++++++++- activesupport/test/core_ext/hash_ext_test.rb | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 2ee86c8af9..159dc2a478 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -19,7 +19,15 @@ class ArrayExtConversionTests < Test::Unit::TestCase end def test_to_sentence_with_connector - assert_equal "one, two, and also three", ['one', 'two', 'three'].to_sentence('and also') + assert_equal "one, two, and also three", ['one', 'two', 'three'].to_sentence(:connector => 'and also') + end + + def test_to_sentence_with_skip_last_comma + assert_equal "one, two and three", ['one', 'two', 'three'].to_sentence(:skip_last_comma => true) + end + + def test_two_elements + assert_equal "one and two", ['one', 'two'].to_sentence end def test_one_element diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index f42b6fde2f..4ae2dd8e7c 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -118,4 +118,8 @@ class HashExtTest < Test::Unit::TestCase indiff = original.with_indifferent_access assert(!indiff.keys.any? {|k| k.kind_of? String}, "A key was converted to a string!") end + + def test_reverse_merge + assert_equal({ :a => 1, :b => 2, :c => 10 }, { :a => 1, :b => 2 }.reverse_merge({:a => "x", :b => "y", :c => 10}) ) + end end -- cgit v1.2.3