aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-08-31 22:11:50 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-08-31 22:11:50 +0100
commitbae00bb1cc392e1cf408369809b9cf85468bef42 (patch)
tree17103af6eeb5de96c72beda1debce28950cc7fea /activesupport/test/core_ext
parent93c76b2fb08668bc4b8364cc8051476e6d1d15ba (diff)
parentffd2cf167040b60c26d97c01598560c87bd4b2d3 (diff)
downloadrails-bae00bb1cc392e1cf408369809b9cf85468bef42.tar.gz
rails-bae00bb1cc392e1cf408369809b9cf85468bef42.tar.bz2
rails-bae00bb1cc392e1cf408369809b9cf85468bef42.zip
Merge commit 'mainstream/master'
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r--activesupport/test/core_ext/array_ext_test.rb7
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb6
-rw-r--r--activesupport/test/core_ext/enumerable_test.rb2
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb19
-rw-r--r--activesupport/test/core_ext/module_test.rb13
-rw-r--r--activesupport/test/core_ext/regexp_ext_test.rb18
6 files changed, 54 insertions, 11 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb
index 24d33896ce..8198b9bd2c 100644
--- a/activesupport/test/core_ext/array_ext_test.rb
+++ b/activesupport/test/core_ext/array_ext_test.rb
@@ -302,6 +302,13 @@ class ArrayToXmlTests < Test::Unit::TestCase
xml = [].to_xml
assert_match(/type="array"\/>/, xml)
end
+
+ def test_to_xml_dups_options
+ options = {:skip_instruct => true}
+ [].to_xml(options)
+ # :builder, etc, shouldn't be added to options
+ assert_equal({:skip_instruct => true}, options)
+ end
end
class ArrayExtractOptionsTests < Test::Unit::TestCase
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb
index 8a7bae5fc6..18422d68bc 100644
--- a/activesupport/test/core_ext/date_ext_test.rb
+++ b/activesupport/test/core_ext/date_ext_test.rb
@@ -251,6 +251,12 @@ class DateExtCalculationsTest < Test::Unit::TestCase
Time.zone_default = nil
end
+ def test_date_advance_should_not_change_passed_options_hash
+ options = { :years => 3, :months => 11, :days => 2 }
+ Date.new(2005,2,28).advance(options)
+ assert_equal({ :years => 3, :months => 11, :days => 2 }, options)
+ end
+
protected
def with_env_tz(new_tz = 'US/Eastern')
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb
index 66507d4652..4170de3dce 100644
--- a/activesupport/test/core_ext/enumerable_test.rb
+++ b/activesupport/test/core_ext/enumerable_test.rb
@@ -64,9 +64,9 @@ class EnumerableTests < Test::Unit::TestCase
def test_enumerable_sums
assert_equal 20, (1..4).sum { |i| i * 2 }
assert_equal 10, (1..4).sum
+ assert_equal 10, (1..4.5).sum
assert_equal 6, (1...4).sum
assert_equal 'abc', ('a'..'c').sum
- assert_raises(NoMethodError) { 1..2.5.sum }
end
def test_each_with_object
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index ece5466abb..eb4c37aaf0 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -265,6 +265,18 @@ class HashExtTest < Test::Unit::TestCase
assert_equal expected, hash_1
end
+ def test_deep_merge_on_indifferent_access
+ hash_1 = HashWithIndifferentAccess.new({ :a => "a", :b => "b", :c => { :c1 => "c1", :c2 => "c2", :c3 => { :d1 => "d1" } } })
+ hash_2 = HashWithIndifferentAccess.new({ :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } })
+ hash_3 = { :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)
+ assert_equal expected, hash_1.deep_merge(hash_3)
+
+ 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 }
@@ -880,6 +892,13 @@ class HashToXmlTest < Test::Unit::TestCase
assert_equal 30, alert_at.min
assert_equal 45, alert_at.sec
end
+
+ def test_to_xml_dups_options
+ options = {:skip_instruct => true}
+ {}.to_xml(options)
+ # :builder, etc, shouldn't be added to options
+ assert_equal({:skip_instruct => true}, options)
+ end
end
class QueryTest < Test::Unit::TestCase
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb
index f8387ae4ab..87f056ea85 100644
--- a/activesupport/test/core_ext/module_test.rb
+++ b/activesupport/test/core_ext/module_test.rb
@@ -32,7 +32,7 @@ end
Somewhere = Struct.new(:street, :city)
Someone = Struct.new(:name, :place) do
- delegate :street, :city, :to => :place
+ delegate :street, :city, :to_f, :to => :place
delegate :state, :to => :@place
delegate :upcase, :to => "place.city"
end
@@ -44,6 +44,7 @@ end
Project = Struct.new(:description, :person) do
delegate :name, :to => :person, :allow_nil => true
+ delegate :to_f, :to => :description, :allow_nil => true
end
class Name
@@ -145,6 +146,16 @@ class ModuleTest < Test::Unit::TestCase
assert_raise(RuntimeError) { david.street }
end
+ def test_delegation_to_method_that_exists_on_nil
+ nil_person = Someone.new(nil)
+ assert_equal 0.0, nil_person.to_f
+ end
+
+ def test_delegation_to_method_that_exists_on_nil_when_allowing_nil
+ nil_project = Project.new(nil)
+ assert_equal 0.0, nil_project.to_f
+ end
+
def test_parent
assert_equal Yz::Zy, Yz::Zy::Cd.parent
assert_equal Yz, Yz::Zy.parent
diff --git a/activesupport/test/core_ext/regexp_ext_test.rb b/activesupport/test/core_ext/regexp_ext_test.rb
index f71099856d..e2d9140bca 100644
--- a/activesupport/test/core_ext/regexp_ext_test.rb
+++ b/activesupport/test/core_ext/regexp_ext_test.rb
@@ -7,20 +7,20 @@ class RegexpExtAccessTests < Test::Unit::TestCase
end
def test_multiline
- assert //m.multiline?
- assert ! //.multiline?
- assert ! /(?m:)/.multiline?
+ assert_equal true, //m.multiline?
+ assert_equal false, //.multiline?
+ assert_equal false, /(?m:)/.multiline?
end
def test_optionalize
- assert "a?", Regexp.optionalize("a")
- assert "(?:foo)?", Regexp.optionalize("foo")
- assert "", Regexp.optionalize("")
+ assert_equal "a?", Regexp.optionalize("a")
+ assert_equal "(?:foo)?", Regexp.optionalize("foo")
+ assert_equal "", Regexp.optionalize("")
end
def test_unoptionalize
- assert "a", Regexp.unoptionalize("a?")
- assert "foo", Regexp.unoptionalize("(?:foo)")
- assert "", Regexp.unoptionalize("")
+ assert_equal "a", Regexp.unoptionalize("a?")
+ assert_equal "foo", Regexp.unoptionalize("(?:foo)?")
+ assert_equal "", Regexp.unoptionalize("")
end
end \ No newline at end of file