-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
After adding:
index({ ssn: 1 }, { unique: true })
to https://github.com/mongoid/echo/blob/master/app/models/user.rb
This spec should pass:
describe "save" do let(:user) do Fabricate.build(:admin, ssn: 1) end let(:user2) do Fabricate.build(:admin, ssn: 1, email: 'arthurnn@gmail.com') end before do User.create_indexes user.save! end it do expect { user2.with(safe: true).save }.to raise_error(Moped::Errors::OperationFailure) end end
After debugging https://github.com/mongoid/mongoid/issues/2832 , realize that https://github.com/mongoid/mongoid/blob/master/lib/mongoid/validations/uniqueness.rb#L269 is reseting the persistence_options