From 1955c164b37342de68306b5d2582d9d2c1776149 Mon Sep 17 00:00:00 2001 From: gbuesing Date: Tue, 18 Nov 2008 09:38:12 -0600 Subject: TimeZone offset tests: use current_period, to ensure TimeZone#utc_offset is up-to-date --- activesupport/test/time_zone_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index d999b9f2a8..60313dc2f7 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -51,7 +51,7 @@ class TimeZoneTest < Test::Unit::TestCase define_method("test_utc_offset_for_#{name}") do silence_warnings do # silence warnings raised by tzinfo gem - period = zone.tzinfo.period_for_utc(Time.utc(2009,1,1,0,0,0)) + period = zone.tzinfo.current_period assert_equal period.utc_offset, zone.utc_offset end end -- cgit v1.2.3 From f451f0e5cfa358e88ac9d03d813a9c84facd6648 Mon Sep 17 00:00:00 2001 From: Damian Janowski Date: Tue, 18 Nov 2008 18:53:06 -0200 Subject: Added Enumerable#none? to check that none of the elements match the block [#1408 state:committed] Signed-off-by: David Heinemeier Hansson --- activesupport/test/core_ext/enumerable_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index deb9b7544d..288ce14b2c 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -79,4 +79,14 @@ class EnumerableTests < Test::Unit::TestCase assert ![ 1, 2 ].many? {|x| x > 1 } assert [ 1, 2, 2 ].many? {|x| x > 1 } end + + def test_none + assert [].none? + assert [ 1 ].none? + + assert [].none? {|x| x > 1 } + assert ![ 2 ].none? {|x| x > 1 } + assert ![ 1, 2 ].none? {|x| x > 1 } + assert [ 1, 1 ].none? {|x| x > 1 } + end end -- cgit v1.2.3 From 51730792ca930a896361eb92354a42bc56903de1 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 19 Nov 2008 19:36:42 +0530 Subject: Added Object#try. ( Taken from http://ozmm.org/posts/try.html ) [Chris Wanstrath] --- .../test/core_ext/object_and_class_ext_test.rb | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'activesupport/test') 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 e88dcb52d5..fbdce56ac2 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -247,3 +247,28 @@ class ObjectInstanceVariableTest < Test::Unit::TestCase [arg] + instance_exec('bar') { |v| [reverse, v] } } end end + +class ObjectTryTest < Test::Unit::TestCase + def setup + @string = "Hello" + end + + def test_nonexisting_method + method = :undefined_method + assert !@string.respond_to?(method) + assert_nil @string.try(method) + end + + def test_valid_method + assert_equal 5, @string.try(:size) + end + + def test_valid_private_method + class << @string + private :size + end + + assert_equal 5, @string.try(:size) + end + +end -- cgit v1.2.3 From 7ee9addb6edc6d231ab5d95a24964a56b0b175d0 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 19 Nov 2008 11:51:57 -0800 Subject: Enumerable#none? conforms to Ruby 1.8.7 behavior --- activesupport/test/core_ext/enumerable_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 288ce14b2c..92db977a77 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -82,7 +82,8 @@ class EnumerableTests < Test::Unit::TestCase def test_none assert [].none? - assert [ 1 ].none? + assert [nil, false].none? + assert ![1].none? assert [].none? {|x| x > 1 } assert ![ 2 ].none? {|x| x > 1 } -- cgit v1.2.3