aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Nartimov <just.lest@gmail.com>2012-03-27 22:55:50 +0300
committerSergey Nartimov <just.lest@gmail.com>2012-03-27 22:55:50 +0300
commitfdcfc7521f0490aed74f372b90ef5e982b0f7e7a (patch)
tree0bb8ddd60a673e0c2da67eeaa3f0a76d0f38c8e8
parentbd8a9701c27b4261e9d8dd84aebbde6ba784ed83 (diff)
downloadrails-fdcfc7521f0490aed74f372b90ef5e982b0f7e7a.tar.gz
rails-fdcfc7521f0490aed74f372b90ef5e982b0f7e7a.tar.bz2
rails-fdcfc7521f0490aed74f372b90ef5e982b0f7e7a.zip
force datetime attributes to be changed
backport ddb5d2f756d9d2655a07791a3b62832efd588474 to 3-2-stable
-rw-r--r--activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb1
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb14
2 files changed, 15 insertions, 0 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 17cf34cdf6..c9b2edbd8c 100644
--- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
+++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ -43,6 +43,7 @@ module ActiveRecord
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
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index acb9a44305..5e5325b570 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -620,6 +620,20 @@ class AttributeMethodsTest < ActiveRecord::TestCase
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