aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJay Pignata <john.pignata@gmail.com>2009-08-31 13:02:19 -0500
committerJoshua Peek <josh@joshpeek.com>2009-08-31 13:02:19 -0500
commit7316d029e60f5d531b35af9e66d233ea19e4f240 (patch)
tree1a93425e44c9feb13ef2049c8b99aa2924a131f2 /activesupport
parent80989437dc1502f9194b0600941b6d70a3efa3b2 (diff)
downloadrails-7316d029e60f5d531b35af9e66d233ea19e4f240.tar.gz
rails-7316d029e60f5d531b35af9e66d233ea19e4f240.tar.bz2
rails-7316d029e60f5d531b35af9e66d233ea19e4f240.zip
Duplicating the options hash in Date#advance to prevent modification of the original [#1133 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb1
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb6
2 files changed, 7 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb
index 1fe4ffb8e1..ce3bebc25a 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -82,6 +82,7 @@ class Date
# Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with
# any of these keys: <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>.
def advance(options)
+ options = options.dup
d = self
d = d >> options.delete(:years) * 12 if options[:years]
d = d >> options.delete(:months) if options[:months]
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb
index 8a7bae5fc6..18422d68bc 100644
--- a/activesupport/test/core_ext/date_ext_test.rb
+++ b/activesupport/test/core_ext/date_ext_test.rb
@@ -251,6 +251,12 @@ class DateExtCalculationsTest < Test::Unit::TestCase
Time.zone_default = nil
end
+ def test_date_advance_should_not_change_passed_options_hash
+ options = { :years => 3, :months => 11, :days => 2 }
+ Date.new(2005,2,28).advance(options)
+ assert_equal({ :years => 3, :months => 11, :days => 2 }, options)
+ end
+
protected
def with_env_tz(new_tz = 'US/Eastern')
old_tz, ENV['TZ'] = ENV['TZ'], new_tz