2016-12-15 15:09:50 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe AdministrationsController, type: :controller do
|
|
|
|
let(:administration) { create :administration }
|
|
|
|
|
|
|
|
describe 'GET #index' do
|
|
|
|
subject { get :index }
|
|
|
|
|
|
|
|
context 'when administration user is not connect' do
|
|
|
|
it { expect(subject.status).to eq 302 }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when administration user is connect' do
|
|
|
|
before do
|
|
|
|
sign_in administration
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject.status).to eq 200 }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
let(:email) { 'plop@plop.com' }
|
|
|
|
let(:password) { 'password' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in administration
|
|
|
|
end
|
|
|
|
|
2018-01-11 14:18:17 +01:00
|
|
|
subject { post :create, administrateur: {email: email } }
|
2016-12-15 15:09:50 +01:00
|
|
|
|
|
|
|
context 'when email and password are correct' do
|
|
|
|
it 'add new administrateur in database' do
|
|
|
|
expect { subject }.to change(Administrateur, :count).by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'alert new mail are send' do
|
2018-01-03 17:11:47 +01:00
|
|
|
expect(AdministrationMailer).to receive(:new_admin_email).and_return(AdministrationMailer)
|
|
|
|
expect(AdministrationMailer).to receive(:deliver_now!)
|
2018-01-11 14:18:17 +01:00
|
|
|
expect(AdministrationMailer).to receive(:invite_admin).and_return(AdministrationMailer)
|
|
|
|
expect(AdministrationMailer).to receive(:deliver_now!)
|
2016-12-15 15:09:50 +01:00
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when email or password are missing' do
|
|
|
|
let(:email) { '' }
|
|
|
|
|
|
|
|
it { expect { subject }.to change(Administrateur, :count).by(0) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|