aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSergey Nartimov <just.lest@gmail.com>2012-02-28 00:29:01 +0300
committerSergey Nartimov <just.lest@gmail.com>2012-02-28 00:33:50 +0300
commitddb5d2f756d9d2655a07791a3b62832efd588474 (patch)
tree90058a9b00d8e829ae823f3a368ba1a4e3822af9 /activerecord
parent2adf78d335dd55ef39559e9e209f1ce96c948095 (diff)
downloadrails-ddb5d2f756d9d2655a07791a3b62832efd588474.tar.gz
rails-ddb5d2f756d9d2655a07791a3b62832efd588474.tar.bz2
rails-ddb5d2f756d9d2655a07791a3b62832efd588474.zip
force datetime attributes to be changed, fix GH #3965
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb1
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb13
2 files changed, 14 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 20372c5c18..ac31b636db 100644
--- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
+++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ -58,6 +58,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 4078b7eb0b..fb51925a38 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -625,6 +625,19 @@ class AttributeMethodsTest < ActiveRecord::TestCase
end
end
+ def test_time_zone_aware_attribute_saved
+ time_string_1 = "2012-02-20 10:00:00"
+ time_string_2 = "2012-02-20 09:00:00"
+
+ 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
+ end
+
def test_setting_time_zone_aware_attribute_to_blank_string_returns_nil
in_time_zone "Pacific Time (US & Canada)" do
record = @target.new