Negate ActiveRecord query scope
I have a slightly complicated scope on a model class Contact < ActiveRecord::Base scope :active, -> { where(inactive: false) } scope :groups, -> { where(contact_type: 2308) } scope :group_search, -> (query) do active.groups.where("last_name LIKE '%' + ? + '%'", query) end end For testing purposes, I want to make sure that all Contacts not returned by group_search are excluded for the right reasons. But to get that list, I have to load Contact.all - Contact.group_search('query') which runs two queries, returns an Array instead of a Relation , and is slower than I'd like. And since I'm testing