aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/duration_test.rb
diff options
context:
space:
mode:
authorAndrey Novikov <envek@envek.name>2015-12-27 19:32:31 +0300
committerAndrey Novikov <envek@envek.name>2016-04-28 03:45:05 +0300
commit434df0016e228a7d51f1ad0c3d1f89faeffbed9a (patch)
treea4e5f1e5c33cf8ca2fc7e1db8b4dbe5a4e07510c /activesupport/test/core_ext/duration_test.rb
parentda2dc68c86d419a4db29feb6764a9200f71c45f1 (diff)
downloadrails-434df0016e228a7d51f1ad0c3d1f89faeffbed9a.tar.gz
rails-434df0016e228a7d51f1ad0c3d1f89faeffbed9a.tar.bz2
rails-434df0016e228a7d51f1ad0c3d1f89faeffbed9a.zip
Change 1.week to create 1 week durations instead of 7 days durations.
This is just to remove astonishment from getting `3600 seconds` from typing `1.hour`.
Diffstat (limited to 'activesupport/test/core_ext/duration_test.rb')
-rw-r--r--activesupport/test/core_ext/duration_test.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb
index 69c2c0d936..ce69364c68 100644
--- a/activesupport/test/core_ext/duration_test.rb
+++ b/activesupport/test/core_ext/duration_test.rb
@@ -66,8 +66,9 @@ class DurationTest < ActiveSupport::TestCase
assert_equal '10 years, 2 months, and 1 day', (10.years + 2.months + 1.day).inspect
assert_equal '10 years, 2 months, and 1 day', (10.years + 1.month + 1.day + 1.month).inspect
assert_equal '10 years, 2 months, and 1 day', (1.day + 10.years + 2.months).inspect
- assert_equal '7 days', 1.week.inspect
- assert_equal '14 days', 1.fortnight.inspect
+ assert_equal '7 days', 7.days.inspect
+ assert_equal '1 week', 1.week.inspect
+ assert_equal '2 weeks', 1.fortnight.inspect
end
def test_inspect_locale
@@ -87,6 +88,15 @@ class DurationTest < ActiveSupport::TestCase
assert_equal 1 + 1.second, 1.second + 1, "Duration + Numeric should == Numeric + Duration"
end
+ def test_time_plus_duration_returns_same_time_datatype
+ twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone['Moscow'] , Time.utc(2016,4,28,00,45))
+ now = Time.now.utc
+ %w( second minute hour day week month year ).each do |unit|
+ assert_equal((now + 1.send(unit)).class, Time, "Time + 1.#{unit} must be Time")
+ assert_equal((twz + 1.send(unit)).class, ActiveSupport::TimeWithZone, "TimeWithZone + 1.#{unit} must be TimeWithZone")
+ end
+ end
+
def test_argument_error
e = assert_raise ArgumentError do
1.second.ago('')