Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

force datetime attributes to be changed #5618

Merged
merged 1 commit into from

2 participants

@lest

backport ddb5d2f to 3-2-stable

@drogus drogus merged commit c4048b3 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 27, 2012
  1. @lest

    force datetime attributes to be changed

    lest authored
    backport ddb5d2f to 3-2-stable
This page is out of date. Refresh to see the latest.
View
1  activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ -43,6 +43,7 @@ def #{attr_name}=(original_time)
end
time = time.in_time_zone rescue nil if time
write_attribute(:#{attr_name}, original_time)
+ #{attr_name}_will_change!
@attributes_cache["#{attr_name}"] = time
end
EOV
View
14 activerecord/test/cases/attribute_methods_test.rb
@@ -620,6 +620,20 @@ def test_setting_time_zone_aware_attribute_with_string
end
end
+ def test_time_zone_aware_attribute_saved
+ old_default, ActiveRecord::Base.default_timezone = ActiveRecord::Base.default_timezone, :utc
+
+ in_time_zone 1 do
+ record = @target.create(:written_on => '2012-02-20 10:00')
+
+ record.written_on = '2012-02-20 09:00'
+ record.save
+ assert_equal Time.zone.local(2012, 02, 20, 9), record.reload.written_on
+ end
+ ensure
+ ActiveRecord::Base.default_timezone = old_default
+ end
+
def test_setting_time_zone_aware_attribute_to_blank_string_returns_nil
in_time_zone "Pacific Time (US & Canada)" do
record = @target.new
Something went wrong with that request. Please try again.