Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #5196 from lest/patch-3

force datetime attributes to be changed, fix GH #3965
  • Loading branch information...
commit 5bbd2d3aa805965c83b284d85efb17d97ba316b5 2 parents 25aa4c7 + ddb5d2f
José Valim josevalim authored
1  activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
View
@@ -58,6 +58,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
13 activerecord/test/cases/attribute_methods_test.rb
View
@@ -625,6 +625,19 @@ def test_setting_time_zone_aware_attribute_with_string
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
Please sign in to comment.
Something went wrong with that request. Please try again.