aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-06-06 18:42:21 +0200
committerXavier Noria <fxn@hashref.com>2010-06-07 06:59:09 +0200
commitd96efe63681cdf63e7c1a1448387a39af736bab9 (patch)
tree06606e496fb7f52052aa7e89718c21fb704053a1
parentac9f8e1b7bbbfa13ff75c86ef72fe6641ba26eb3 (diff)
downloadrails-d96efe63681cdf63e7c1a1448387a39af736bab9.tar.gz
rails-d96efe63681cdf63e7c1a1448387a39af736bab9.tar.bz2
rails-d96efe63681cdf63e7c1a1448387a39af736bab9.zip
the order in which we apply deltas in Date#advance matters, add test coverage for that
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb
index a3a2f13436..55cd566738 100644
--- a/activesupport/test/core_ext/date_ext_test.rb
+++ b/activesupport/test/core_ext/date_ext_test.rb
@@ -198,6 +198,16 @@ class DateExtCalculationsTest < ActiveSupport::TestCase
assert_equal Date.new(2005,2,28), Date.new(2004,2,29).advance(:years => 1) #leap day plus one year
end
+ def test_advance_does_first_years_and_then_days
+ assert_equal Date.new(2012, 2, 29), Date.new(2011, 2, 28).advance(:years => 1, :days => 1)
+ # If day was done first we would jump to 2012-03-01 instead.
+ end
+
+ def test_advance_does_first_months_and_then_days
+ assert_equal Date.new(2010, 3, 28), Date.new(2010, 2, 28).advance(:months => 1, :day => 1)
+ # If day was done first we would jump to 2010-04-01 instead.
+ end
+
def test_advance_in_calendar_reform
assert_equal Date.new(1582,10,15), Date.new(1582,10,4).advance(:days => 1)
assert_equal Date.new(1582,10,4), Date.new(1582,10,15).advance(:days => -1)