Skip to content

Instantly share code, notes, and snippets.

@lucassus
Created September 12, 2012 10:18
Show Gist options
  • Save lucassus/3705764 to your computer and use it in GitHub Desktop.
Save lucassus/3705764 to your computer and use it in GitHub Desktop.
Testing indexes for mongoid
describe 'indexes' do
it { should have_index_for({ company: 1, advisor_company: 1 }).with_options(unique: true) }
describe 'unique index for :company and :advisor_company' do
let!(:first_advisor_company) { create(:company, :advisor) }
let!(:second_advisor_company) { create(:company, :advisor) }
let!(:company) { create(:company) }
before { Rails::Mongoid.create_indexes("app/models/company/**/*.rb") }
it 'should ensure uniques' do
company.invite_advisor(first_advisor_company)
expect do
company.invite_advisor(first_advisor_company)
end.not_to change(Company::Relation::AdvisorCompany, :count)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment