demarches-normaliennes/spec/models/invite_spec.rb

39 lines
1,004 B
Ruby
Raw Normal View History

require 'spec_helper'
describe Invite do
describe 'database columns' do
it { is_expected.to have_db_column(:email) }
end
describe 'associations' do
it { is_expected.to belong_to(:dossier) }
it { is_expected.to belong_to(:user) }
end
describe 'an email can be used for multiple dossier' do
let(:email1) { 'plop@octo.com' }
let!(:dossier1) { create(:dossier) }
let!(:dossier2) { create(:dossier) }
context 'when an email is invite on two dossier' do
subject do
create(:invite, email: email1, dossier: dossier1)
create(:invite, email: email1, dossier: dossier2)
end
it { expect{ subject }.to change(Invite, :count).by(2) }
end
context 'when an email is invite twice on a dossier' do
subject do
create(:invite, email: email1, dossier: dossier1)
create(:invite, email: email1, dossier: dossier1)
end
it { expect{ subject }.to raise_error ActiveRecord::RecordInvalid }
end
end
2017-04-04 15:27:04 +02:00
end