diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2012-04-24 06:38:26 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-04-24 06:38:26 -0700 |
commit | 4afdd97fd1508ab36733c18f9b3ea4aeda9ca940 (patch) | |
tree | 34cfa614dc90573a56faab76179dcccc1d0639fb /actionpack/test | |
parent | f7ddbaada95cddd7acb3166110071de29b17f51a (diff) | |
parent | 7322bd45f034ec506a416b26bc1263dc6ee2dc5c (diff) | |
download | rails-4afdd97fd1508ab36733c18f9b3ea4aeda9ca940.tar.gz rails-4afdd97fd1508ab36733c18f9b3ea4aeda9ca940.tar.bz2 rails-4afdd97fd1508ab36733c18f9b3ea4aeda9ca940.zip |
Merge pull request #5927 from avakhov/distance_of_time_in_words-swap
Distance of time in words should work correctly if from_time > to_time
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/template/date_helper_test.rb | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb index c9b8a5bb70..4835bc578f 100644 --- a/actionpack/test/template/date_helper_test.rb +++ b/actionpack/test/template/date_helper_test.rb @@ -125,13 +125,33 @@ class DateHelperTest < ActionView::TestCase start_date = Date.new 1982, 12, 3 end_date = Date.new 2010, 11, 30 assert_equal("almost 28 years", distance_of_time_in_words(start_date, end_date)) + assert_equal("almost 28 years", distance_of_time_in_words(end_date, start_date)) end def test_distance_in_words_with_integers - assert_equal "less than a minute", distance_of_time_in_words(59) + assert_equal "1 minute", distance_of_time_in_words(59) assert_equal "about 1 hour", distance_of_time_in_words(60*60) - assert_equal "less than a minute", distance_of_time_in_words(0, 59) + assert_equal "1 minute", distance_of_time_in_words(0, 59) assert_equal "about 1 hour", distance_of_time_in_words(60*60, 0) + assert_equal "about 3 years", distance_of_time_in_words(10**8) + assert_equal "about 3 years", distance_of_time_in_words(0, 10**8) + end + + def test_distance_in_words_with_times + assert_equal "1 minute", distance_of_time_in_words(30.seconds) + assert_equal "1 minute", distance_of_time_in_words(59.seconds) + assert_equal "2 minutes", distance_of_time_in_words(119.seconds) + assert_equal "2 minutes", distance_of_time_in_words(1.minute + 59.seconds) + assert_equal "3 minutes", distance_of_time_in_words(2.minute + 30.seconds) + assert_equal "44 minutes", distance_of_time_in_words(44.minutes + 29.seconds) + assert_equal "about 1 hour", distance_of_time_in_words(44.minutes + 30.seconds) + assert_equal "about 1 hour", distance_of_time_in_words(60.minutes) + + # include seconds + assert_equal "half a minute", distance_of_time_in_words(39.seconds, 0, true) + assert_equal "less than a minute", distance_of_time_in_words(40.seconds, 0, true) + assert_equal "less than a minute", distance_of_time_in_words(59.seconds, 0, true) + assert_equal "1 minute", distance_of_time_in_words(60.seconds, 0, true) end def test_time_ago_in_words |