mongoid/mongoid — pull request #1893 by svetlins (2012-04-04 12:03:29+00:00)
Title: Make multi params attr module behave more like AR

When you do multi parameters assignment of Date fields in
ActiveRecord the params are first given to Date.civil and then in a case
of invalid date exception they are passed through Time.new which
includes logic to wrap the invalid date to a valid one - i.e 31st
February 1980 becomes 2nd March 1980. For reference see rails source
code which implements this logic:

https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/attribute_assignment.rb#L174

Look at the rescue in the method read_date_parameter_value.

This patch implements the same behaviour in Mongoid. It has been verified to work with Ruby 1.9.3-p125 and JRuby 1.6.7.

You can take a look at a new Rails project that has specs that reproduce the problem at https://github.com/svetlins/mongoid_playground

bundle exec rspec spec/models/person_spec.rb -> mongoid model - fails with exception
bundle exec rspec spec/models/relational_person_spec.rb -> active record model - no exception