2018-01-11 14:17:50 +01:00
|
|
|
describe Administration, type: :model do
|
|
|
|
describe '#invite_admin' do
|
|
|
|
let(:administration) { create :administration }
|
|
|
|
let(:valid_email) { 'paul@tps.fr' }
|
2019-08-09 11:41:36 +02:00
|
|
|
|
2018-01-11 14:17:50 +01:00
|
|
|
subject { administration.invite_admin(valid_email) }
|
|
|
|
|
|
|
|
it {
|
2019-08-09 11:41:36 +02:00
|
|
|
user = subject
|
|
|
|
expect(user.errors).to be_empty
|
|
|
|
expect(user).to be_persisted
|
2018-01-11 14:17:50 +01:00
|
|
|
}
|
2019-08-09 11:41:36 +02:00
|
|
|
|
2018-01-11 14:17:50 +01:00
|
|
|
it { expect(administration.invite_admin(nil).errors).not_to be_empty }
|
|
|
|
it { expect(administration.invite_admin('toto').errors).not_to be_empty }
|
2018-04-11 17:14:47 +02:00
|
|
|
|
|
|
|
it 'creates a corresponding user account for the email' do
|
|
|
|
subject
|
|
|
|
user = User.find_by(email: valid_email)
|
|
|
|
expect(user).to be_present
|
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
it 'creates a corresponding instructeur account for the email' do
|
2018-10-30 15:31:13 +01:00
|
|
|
subject
|
2019-10-15 17:44:59 +02:00
|
|
|
instructeur = Instructeur.by_email(valid_email)
|
2019-08-06 11:02:54 +02:00
|
|
|
expect(instructeur).to be_present
|
2018-10-30 15:31:13 +01:00
|
|
|
end
|
|
|
|
|
2018-04-11 17:14:47 +02:00
|
|
|
context 'when there already is a user account with the same email' do
|
|
|
|
before { create(:user, email: valid_email) }
|
|
|
|
it 'still creates an admin account' do
|
|
|
|
expect(subject.errors).to be_empty
|
|
|
|
expect(subject).to be_persisted
|
|
|
|
end
|
|
|
|
end
|
2018-01-11 14:17:50 +01:00
|
|
|
end
|
2020-11-04 16:35:15 +01:00
|
|
|
|
|
|
|
describe 'enable_otp!' do
|
|
|
|
let(:administration) { create(:administration, otp_required_for_login: false) }
|
|
|
|
let(:subject) { administration.enable_otp! }
|
|
|
|
|
|
|
|
it 'updates otp_required_for_login' do
|
|
|
|
expect { subject }.to change { administration.otp_required_for_login? }.from(false).to(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates otp_secret' do
|
|
|
|
expect { subject }.to change { administration.otp_secret }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'disable_otp!' do
|
|
|
|
let(:administration) { create(:administration, otp_required_for_login: true) }
|
|
|
|
let(:subject) { administration.disable_otp! }
|
|
|
|
|
|
|
|
it 'updates otp_required_for_login' do
|
|
|
|
expect { subject }.to change { administration.otp_required_for_login? }.from(true).to(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'nullifies otp_secret' do
|
|
|
|
administration.enable_otp!
|
|
|
|
expect { subject }.to change { administration.reload.otp_secret }.to(nil)
|
|
|
|
end
|
|
|
|
end
|
2018-01-11 14:17:50 +01:00
|
|
|
end
|