I have a scope that I apply to a Mongoid object in rails, which works fine when developing, but not when running tests. Actually this does not work at all in tests. This is an embedded document.
Parent:
class Person include Mongoid::Document def self.with_appointments where(:appointments.not => { '$size' => 0 }) end embeds_many :appointments, store_as: 'Appointments', class_name: 'Appointment' end
Nested child:
class Appointment include Mongoid::Document embedded_in :person end
When I run tests against my model, it returns to Persons whether they have meetings or not. If I run the same from my controller in development against the database, it filters out people with empty appointments.
What am I missing?
Before asking me to change the database setup -
- I have no control over the data structure
- Suppose I do not have write access to the database
source share