aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-06-04 07:00:28 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-06-04 07:00:28 -0700
commit9f52d1526c816a35ec7bcc6e85f27b51d010dbae (patch)
treefbc40aa0ac82e16991d9e5d75814d9f9039a3835 /activerecord
parent43f0af4d39a5d8c1191fef589d947fc92a34f7d4 (diff)
parent510ef2be5396fb2cd8209b13e8b8ddac3f7e13a5 (diff)
downloadrails-9f52d1526c816a35ec7bcc6e85f27b51d010dbae.tar.gz
rails-9f52d1526c816a35ec7bcc6e85f27b51d010dbae.tar.bz2
rails-9f52d1526c816a35ec7bcc6e85f27b51d010dbae.zip
Merge pull request #6622 from kennyj/fix_6591-32
[3-2-stable back ported] Fix #6591 Rails 3.2.5 Regression: incorrect _changed? for datetimes
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb3
-rw-r--r--activerecord/test/cases/dirty_test.rb11
2 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
index c9b2edbd8c..7abe29c7d5 100644
--- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
+++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ -42,8 +42,9 @@ module ActiveRecord
time = time.is_a?(String) ? Time.zone.parse(time) : time.to_time rescue time
end
time = time.in_time_zone rescue nil if time
+ changed = read_attribute(:#{attr_name}) != time
write_attribute(:#{attr_name}, original_time)
- #{attr_name}_will_change!
+ #{attr_name}_will_change! if changed
@attributes_cache["#{attr_name}"] = time
end
EOV
diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb
index b1ce846218..2a3d6a6cc1 100644
--- a/activerecord/test/cases/dirty_test.rb
+++ b/activerecord/test/cases/dirty_test.rb
@@ -78,6 +78,17 @@ class DirtyTest < ActiveRecord::TestCase
assert_equal old_created_on, pirate.created_on_was
end
end
+
+ def test_setting_time_attributes_with_time_zone_field_to_itself_should_not_be_marked_as_a_change
+ in_time_zone 'Paris' do
+ target = Class.new(ActiveRecord::Base)
+ target.table_name = 'pirates'
+
+ pirate = target.create
+ pirate.created_on = pirate.created_on
+ assert !pirate.created_on_changed?
+ end
+ end
def test_time_attributes_changes_without_time_zone_by_skip
in_time_zone 'Paris' do