rails/rails — Issue #3865: date typecast before saving
Author: rogercampos
Created: 2011-12-05 19:07:03+00:00
State: open

Hello, I've run in an error in which an ActiveRecord object is being saved even though a validation is not satisfied. It seems like the typecasting of *Date* values is only processed when we assign strings, but not when we give Time objects directly:

foo = Test.new
foo.a_date_field = "21-5-2011 13:13:13" # In this case this field will be a Date when the validations run
foo.a_date_field = Time.new(2011, 5, 21, 13,13,13, "+01:00") # But in this case it will be a Time not a Date

I wrote an example app here: https://github.com/rogercampos/date_type_cast_showcase. The failing example is in a rake task, you just need to clone the repo and run `rake db:migrate check`.