Permalink
Browse files

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
  • Loading branch information...
2 parents 43f0af4 + 510ef2b commit 9f52d1526c816a35ec7bcc6e85f27b51d010dbae @rafaelfranca rafaelfranca committed Jun 4, 2012
@@ -42,8 +42,9 @@ def #{attr_name}=(original_time)
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
@@ -78,6 +78,17 @@ def test_time_attributes_changes_with_time_zone
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

0 comments on commit 9f52d15

Please sign in to comment.