Skip to content

Commit

Permalink
Merge pull request #29676 from lugray/fix_date_time_serialize
Browse files Browse the repository at this point in the history
Fix `ActiveModel::Type::DateTime#serialize`
  • Loading branch information
rafaelfranca committed Jul 5, 2017
2 parents 81492d8 + 7b2dfde commit e3ed243
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 e3ed243

Please sign in to comment.