Document Matchers

describe Mongoid::Matchers::Document do
subject { Person }
it { must be_document } # if model includes Mongoid::Document
it { must be_paranoid } # if model includes Mongoid::Paranoia (Only in Mongoid <= 4.0.0)
it { must be_versioned } # if model includes Mongoid::Versioning (Only in Mongoid <= 4.0.0)
it { must be_timestamped } # if model includes Mongoid::Timestamps
it { must be_stored_in(:people) } # checks the collection for model's document
it { must have_field(:name) }
it { must have_field(:name).of_type(String) }
it { must have_field(:name).with_default_value("me") }
it { must have_field(:name).of_type(String).with_default_value("me") }
it { must have_fields(:name, :login) }
it { must have_fields(:name, :login).of_type(String) }
it { must have_fields(:name, :login).with_default_value("me") }
it { must have_fields(:name, :login).of_type(String).with_default_value("me") }
it { must have_index_for(:name) }
it { must have_index_for(:account_id, :email) }
end

Association Matchers

describe Mongoid::Matchers::Associations do
describe Person do
subject { Person }
it { must have_one(:account) }
it { must have_many(:pets).of_type(Pet) }
it { must have_and_belong_to_many(:friends) }
it { must embed_one(:profile) }
it { must embed_many(:sites) }
end
describe Pet do
subject { Pet }
it { must belong_to(:person) }
end
describe Site do
subject { Site }
it { must embedded_in(:person) }
end
end