here is a simplified version of my models:
class Ticket include Mongoid::Document belongs_to :origin, autosave: true scope :by_tenant, ->(tenant_name) { where("origin.owner": tenant_name) }endclass Origin include Mongoid::Document has_many :tickets, dependent: :delete_all field :owner, type: Stringend
And here is the spec that somehow fails:
describe "#by_tenant" do let(:origin_one) { create(:origin, owner: "made-up-1") } let(:origin_two) { create(:origin, owner: "made-up-2") } before do create_list(:ticket, 5, origin: origin_one) create_list(:ticket, 5, origin: origin_two) end it "filters by tenant" do puts described_class.all.count # 10 expect(described_class.by_tenant(origin_one.owner).to_a).to eq(5) endend
I feel like I'm either misunderstanding how Mongoid Criteria works or I missed something, but that scope should return all tickets that belong to the first origin. What am I doing wrong?