diff options
author | Sen-Zhang <solowolf21@126.com> | 2016-03-14 18:51:25 -0700 |
---|---|---|
committer | Sen-Zhang <solowolf21@126.com> | 2016-11-01 18:17:26 -0700 |
commit | 9bf4583241e189d04a5df143332107ef18857034 (patch) | |
tree | 91b8eb5ba3f8b5108508fe70e0918d94b2478199 | |
parent | 9ebb3558f4bddc2af52829abd2b198bc7fab4a13 (diff) | |
download | rails-9bf4583241e189d04a5df143332107ef18857034.tar.gz rails-9bf4583241e189d04a5df143332107ef18857034.tar.bz2 rails-9bf4583241e189d04a5df143332107ef18857034.zip |
fix datatime error
-rw-r--r-- | activerecord/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/multiparameter_attributes_test.rb | 7 |
3 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 95cdc6bc3f..400f4942c4 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,8 @@ +* Fix an Active Record DateTime field NoMethodError caused by incomplete + datetime. [Bug #24195](https://github.com/rails/rails/issues/24195) + + *Sen Zhang* + * Allow `slice` to take an array of methods (without need for splatting). *Cohen Carlisle* 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 ce9985e2e1..500d903857 100644 --- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb +++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb @@ -39,7 +39,7 @@ module ActiveRecord end def set_time_zone_without_conversion(value) - ::Time.zone.local_to_utc(value).in_time_zone if value + ::Time.zone.local_to_utc(value).try(:in_time_zone) if value end def map_avoiding_infinite_recursion(value) diff --git a/activerecord/test/cases/multiparameter_attributes_test.rb b/activerecord/test/cases/multiparameter_attributes_test.rb index 18ecc67f0b..ceb5724377 100644 --- a/activerecord/test/cases/multiparameter_attributes_test.rb +++ b/activerecord/test/cases/multiparameter_attributes_test.rb @@ -260,6 +260,13 @@ class MultiParameterAttributeTest < ActiveRecord::TestCase topic.attributes = attributes assert_equal Time.zone.local(2000, 1, 1, 16, 24, 0), topic.bonus_time assert_not topic.bonus_time.utc? + + attributes = { + "written_on(1i)" => "2000", "written_on(2i)" => "", "written_on(3i)" => "", + "written_on(4i)" => "", "written_on(5i)" => "" + } + topic.attributes = attributes + assert_nil topic.written_on end ensure Topic.reset_column_information |