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')
- is duplicated by
-
MONGOID-4752 #create_with parameters are included into search criteria when calling find_or_create_by
-
- Closed
-
- is related to
-
MONGOID-4689 Mongoid::Criteria#find searches globally, does not restrict to criteria
-
- Closed
-