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

Fix ActiveModel::Type::DateTime#serialize

`ActiveModel::Type::DateTime#serialize` should return a `Time` object
so that finding by a datetime column works correctly.
This commit is contained in:
Lisa Ugray 2017-07-04 14:22:35 -04:00
parent 2ae84d2fa0
commit 7b2dfdeab6
2 changed files with 17 additions and 0 deletions

View file

@ -10,6 +10,10 @@ module ActiveModel
:datetime
end
def serialize(value)
super(cast(value))
end
private
def cast_value(value)

View file

@ -58,4 +58,17 @@ class DateTimeTest < ActiveRecord::TestCase
assert_equal now, task.starting
end
end
def test_date_time_with_string_value_with_subsecond_precision
skip unless subsecond_precision_supported?
string_value = "2017-07-04 14:19:00.5"
topic = Topic.create(written_on: string_value)
assert_equal topic, Topic.find_by(written_on: string_value)
end
def test_date_time_with_string_value_with_non_iso_format
string_value = "04/07/2017 2:19pm"
topic = Topic.create(written_on: string_value)
assert_equal topic, Topic.find_by(written_on: string_value)
end
end