aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
diff options
context:
space:
mode:
authorLilibeth De La Cruz <lilibethdlc@gmail.com>2013-01-25 04:14:27 -0400
committerAndrew White <andyw@pixeltrix.co.uk>2013-01-26 16:57:33 +0000
commitbc982cbcb34129ea2cfe8aa1f8e0b40e444e68db (patch)
tree645b9d67e452ff31e1b69b2643047a17b6bb1ed5 /activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
parent0b5d3f32732f637fe29848a3597852dce9662c6b (diff)
downloadrails-bc982cbcb34129ea2cfe8aa1f8e0b40e444e68db.tar.gz
rails-bc982cbcb34129ea2cfe8aa1f8e0b40e444e68db.tar.bz2
rails-bc982cbcb34129ea2cfe8aa1f8e0b40e444e68db.zip
Fix handling of dirty time zone aware attributes
Previously, when `time_zone_aware_attributes` were enabled, after changing a datetime or timestamp attribute and then changing it back to the original value, `changed_attributes` still tracked the attribute as changed. This caused `[attribute]_changed?` and `changed?` methods to return true incorrectly. Example: in_time_zone 'Paris' do order = Order.new original_time = Time.local(2012, 10, 10) order.shipped_at = original_time order.save order.changed? # => false # changing value order.shipped_at = Time.local(2013, 1, 1) order.changed? # => true # reverting to original value order.shipped_at = original_time order.changed? # => false, used to return true end
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb')
-rw-r--r--activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb4
1 files changed, 2 insertions, 2 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 7701001da9..e3c5dc4823 100644
--- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
+++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ -40,9 +40,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
+ previous_time = attribute_changed?("#{attr_name}") ? changed_attributes["#{attr_name}"] : read_attribute(:#{attr_name})
write_attribute(:#{attr_name}, original_time)
- #{attr_name}_will_change! if changed
+ #{attr_name}_will_change! if previous_time != time
@attributes_cache["#{attr_name}"] = time
end
EOV