我有一个带有User
如下模型的 rails 应用程序:
class User
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Paranoia
field :email, type: String
index({ email: 1 }, { unique: true })
validates :email, presence:true, uniqueness:true
end
那是我的测试:
describe User do
it 'has an unique email' do
first_user = Fabricate(:user, email: 'test@fundbase.com')
first_user.valid?.should be_true # good
first_user.save
first_user.delete
second_user = Fabricate(:user, email: 'test@fundbase.com')
second_user.valid?.should be_true # good
second_user.save
first_user.restore
first_user.valid?.should_not be_true # fail
end
end
最后一次测试在这里失败了。由于某种原因,未检查电子邮件字段的唯一性。关于如何强制恢复验证的任何提示?