aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/time_ext_test.rb
diff options
context:
space:
mode:
authorClemens Kofler <clemens@railway.at>2008-09-11 12:51:16 +0200
committergbuesing <gbuesing@gmail.com>2008-09-14 21:21:19 -0500
commitbfa12d7a02ce0e84fcd2b83f2ce6fee1386757e3 (patch)
treed0b4637922d92bcaec89d9e36cc05c5ff11738e7 /activesupport/test/core_ext/time_ext_test.rb
parentf636c6fda037fbef25e98c81d019a6c600a18f66 (diff)
downloadrails-bfa12d7a02ce0e84fcd2b83f2ce6fee1386757e3.tar.gz
rails-bfa12d7a02ce0e84fcd2b83f2ce6fee1386757e3.tar.bz2
rails-bfa12d7a02ce0e84fcd2b83f2ce6fee1386757e3.zip
Introduce convenience methods past?, today? and future? for Date and Time classes to facilitate Date/Time comparisons.
Diffstat (limited to 'activesupport/test/core_ext/time_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb25
1 files changed, 19 insertions, 6 deletions
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index c1bdee4ca9..c6ebccc343 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -563,6 +563,19 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
assert_nothing_raised { Time.now.xmlschema }
end
+ uses_mocha 'past?, today? and future?' do
+ def test_past_today_future
+ Date.stubs(:current).returns(Date.civil(2000, 1, 1))
+ Time.stubs(:current).returns(Time.local(2000, 1, 1, 1, 0, 1))
+ t1, t2 = Time.local(2000, 1, 1, 1, 0, 0), Time.local(2000, 1, 1, 1, 0, 2)
+
+ assert t1.past?
+ assert t2.future?
+ assert t1.today?
+ assert t2.today?
+ end
+ end
+
def test_acts_like_time
assert Time.new.acts_like_time?
end
@@ -640,24 +653,24 @@ class TimeExtMarshalingTest < Test::Unit::TestCase
assert_equal t, unmarshaled
assert_equal t.zone, unmarshaled.zone
end
-
- def test_marshaling_with_local_instance
+
+ def test_marshaling_with_local_instance
t = Time.local(2000)
marshaled = Marshal.dump t
unmarshaled = Marshal.load marshaled
assert_equal t, unmarshaled
assert_equal t.zone, unmarshaled.zone
end
-
- def test_marshaling_with_frozen_utc_instance
+
+ def test_marshaling_with_frozen_utc_instance
t = Time.utc(2000).freeze
marshaled = Marshal.dump t
unmarshaled = Marshal.load marshaled
assert_equal t, unmarshaled
assert_equal t.zone, unmarshaled.zone
end
-
- def test_marshaling_with_frozen_local_instance
+
+ def test_marshaling_with_frozen_local_instance
t = Time.local(2000).freeze
marshaled = Marshal.dump t
unmarshaled = Marshal.load marshaled