aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/time_ext_test.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2013-06-08 08:22:29 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2013-06-08 09:50:15 +0100
commitb7f9de27f0558d6144f982cae83f32ca85a07f7e (patch)
tree1fe372c6c29f65141340cbf2835e0c34e8393e71 /activesupport/test/core_ext/time_ext_test.rb
parentad3d333321d2cfdac87600f6440bc69b0945f37c (diff)
downloadrails-b7f9de27f0558d6144f982cae83f32ca85a07f7e.tar.gz
rails-b7f9de27f0558d6144f982cae83f32ca85a07f7e.tar.bz2
rails-b7f9de27f0558d6144f982cae83f32ca85a07f7e.zip
Override Time.at to work with Time-like values
Time.at allows passing a single Time argument which is then converted to an integer. The conversion code since 1.9.3r429 explicitly checks for an instance of Time so we need to override it to allow DateTime and ActiveSupport::TimeWithZone values.
Diffstat (limited to 'activesupport/test/core_ext/time_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index 4e53aff00b..eefcdbb1b3 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -741,6 +741,28 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
assert_equal(-1, Time.utc(2000) <=> ActiveSupport::TimeWithZone.new( Time.utc(2000, 1, 1, 0, 0, 1), ActiveSupport::TimeZone['UTC'] ))
end
+ def test_at_with_datetime
+ assert_equal Time.utc(2000, 1, 1, 0, 0, 0), Time.at(DateTime.civil(2000, 1, 1, 0, 0, 0))
+
+ # Only test this if the underlying Time.at raises a TypeError
+ begin
+ Time.at_without_coercion(Time.now, 0)
+ rescue TypeError
+ assert_raise(TypeError) { assert_equal(Time.utc(2000, 1, 1, 0, 0, 0), Time.at(DateTime.civil(2000, 1, 1, 0, 0, 0), 0)) }
+ end
+ end
+
+ def test_at_with_time_with_zone
+ assert_equal Time.utc(2000, 1, 1, 0, 0, 0), Time.at(ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC']))
+
+ # Only test this if the underlying Time.at raises a TypeError
+ begin
+ Time.at_without_coercion(Time.now, 0)
+ rescue TypeError
+ assert_raise(TypeError) { assert_equal(Time.utc(2000, 1, 1, 0, 0, 0), Time.at(ActiveSupport::TimeWithZone.new(Time.utc(2000, 1, 1, 0, 0, 0), ActiveSupport::TimeZone['UTC']), 0)) }
+ end
+ end
+
def test_eql?
assert_equal true, Time.utc(2000).eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']) )
assert_equal true, Time.utc(2000).eql?( ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone["Hawaii"]) )