Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[3-2-stable back ported] Fix #6591 Rails 3.2.5 Regression: incorrect _changed? for datetimes #6622

Merged
merged 2 commits into from

3 participants

@kennyj
Collaborator

The original PR (on the master) was #6619.

There is a problem when dealing with Time with Timezone field.
If value is not change, definitely _will_change! method is executed.

Please see #6591.

@rafaelfranca rafaelfranca merged commit 9f52d15 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ -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
View
11 activerecord/test/cases/dirty_test.rb
@@ -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
Something went wrong with that request. Please try again.