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

#create_with attrs should not be used in where query

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.1.0.rc0, 6.4.2, 7.0.5
    • Affects Version/s: 6.4.0
    • Component/s: None
    • None

      create_with(x).find_or_create_by(y) should find by y and create with x and y

      However, it finds with x and y

      To reproduce:

      it 'finds the existing person' do
        existing   = Person.create(username: 'Turnip', age: '49')
        found      = Person.create_with(attrs).find_or_create_by(query)
      
        expect(found.username).to eq('Turnip')
        expect(found.id).to eq(existing.id)
        expect(found.age).to eq(49)
      end
      

      Spec result:

        1) Mongoid::Criteria::Modifiable#create_with when called on the class when a method is chained when a write method is chained finds the existing person
           Failure/Error: expect(found.id).to eq(existing.id)
      
             expected: BSON::ObjectId('5ae8e6ba610db9d8a0266661')
                  got: BSON::ObjectId('5ae8e6ba610db9d8a0266662')
      
             (compared using ==)
      
             Diff:
             @@ -1,2 +1,2 @@
             -BSON::ObjectId('5ae8e6ba610db9d8a0266661')
             +BSON::ObjectId('5ae8e6ba610db9d8a0266662')
      

            Assignee:
            sam.rossi@mongodb.com Samuel Rossi (Inactive)
            Reporter:
            malmckay Mal McKay
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: