Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2835

losing persistence_options after validates

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.2
    • 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

            Assignee:
            durran Durran Jordan
            Reporter:
            arthurnn Arthur Nogueira Neves
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: