mongoid/mongoid — Issue #1559: Calling #valid? saves dupped document
Author: gavinhughes
Created: 2012-01-06 02:23:10+00:00
State: open

Using Mongoid 2.3.4, calling #valid? on a dupped document, saves it. The setup:

User
include Mongoid::Document
Sponsor < User

The evidence:

[1] pry(#)> @user = current_user.dup
=> #Sponsor _id: 4f065814421aa90df800001a, _type: "Sponsor", ...
[2] pry(#)> current_user.reload
=> #Sponsor _id: 4f065619421aa90df8000011, _type: "Sponsor", ...
[3] pry(#)> User.count
=> 1
[4] pry(#)> @user.valid?
=> false
[5] pry(#)> User.count
=> 2
6] pry(#)> @user.errors.messages
=> {:password=>["can't be blank", "can't be blank", "can't be blank"],
:email=>["is already taken", "is already taken"],
:birthdate=>["must indicate at least 16 years old"]}
[7] pry(#)> current_user.errors.messages
=> {:birthdate=>["must indicate at least 16 years old"]}