1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

fix datatime error

This commit is contained in:
Sen-Zhang 2016-03-14 18:51:25 -07:00
parent 9ebb3558f4
commit 9bf4583241
3 changed files with 13 additions and 1 deletions

View file

@ -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). * Allow `slice` to take an array of methods (without need for splatting).
*Cohen Carlisle* *Cohen Carlisle*

View file

@ -39,7 +39,7 @@ module ActiveRecord
end end
def set_time_zone_without_conversion(value) 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 end
def map_avoiding_infinite_recursion(value) def map_avoiding_infinite_recursion(value)

View file

@ -260,6 +260,13 @@ class MultiParameterAttributeTest < ActiveRecord::TestCase
topic.attributes = attributes topic.attributes = attributes
assert_equal Time.zone.local(2000, 1, 1, 16, 24, 0), topic.bonus_time assert_equal Time.zone.local(2000, 1, 1, 16, 24, 0), topic.bonus_time
assert_not topic.bonus_time.utc? 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 end
ensure ensure
Topic.reset_column_information Topic.reset_column_information