Skip to content

Commit

Permalink
Fix ActiveModel::Type::DateTime#serialize
Browse files Browse the repository at this point in the history
`ActiveModel::Type::DateTime#serialize` should return a `Time` object
so that finding by a datetime column works correctly.
  • Loading branch information
Lisa Ugray committed Jul 5, 2017
1 parent 2ae84d2 commit 7b2dfde
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions activemodel/lib/active_model/type/date_time.rb
Expand Up @@ -10,6 +10,10 @@ def type
:datetime
end

def serialize(value)
super(cast(value))
end

private

def cast_value(value)
Expand Down
13 changes: 13 additions & 0 deletions activerecord/test/cases/date_time_test.rb
Expand Up @@ -58,4 +58,17 @@ def test_assign_in_local_timezone
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

0 comments on commit 7b2dfde

Please sign in to comment.