diff options
author | Arthur Nogueira Neves <github@arthurnn.com> | 2016-11-03 12:19:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-03 12:19:01 -0400 |
commit | 264566a1b56de4abace2444dff4c9535744855f0 (patch) | |
tree | 4f894a268fc7b9374a4cb8438afcf4b06babf126 /activerecord | |
parent | 032ab94332fd5496c5af627bc36445cea3ba476a (diff) | |
parent | 9bf4583241e189d04a5df143332107ef18857034 (diff) | |
download | rails-264566a1b56de4abace2444dff4c9535744855f0.tar.gz rails-264566a1b56de4abace2444dff4c9535744855f0.tar.bz2 rails-264566a1b56de4abace2444dff4c9535744855f0.zip |
Merge pull request #24202 from Sen-Zhang/fix_datetime_error
fix datatime error
Diffstat (limited to 'activerecord')
-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 |