2018-01-17 10:28:59 +01:00
|
|
|
describe Manager::AdministrateursController, type: :controller do
|
2018-12-24 17:28:20 +01:00
|
|
|
let(:administration) { create(:administration) }
|
2020-03-26 16:17:07 +01:00
|
|
|
let(:administrateur) { create(:administrateur) }
|
2018-01-17 10:28:59 +01:00
|
|
|
|
2020-02-18 16:43:05 +01:00
|
|
|
before do
|
|
|
|
sign_in administration
|
|
|
|
end
|
|
|
|
|
2020-03-26 16:17:07 +01:00
|
|
|
describe '#show' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
before do
|
|
|
|
get :show, params: { id: administrateur.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response.body).to include(administrateur.email) }
|
|
|
|
end
|
|
|
|
|
2020-02-18 16:41:56 +01:00
|
|
|
describe 'GET #new' do
|
|
|
|
render_views
|
|
|
|
it 'displays form to create a new admin' do
|
|
|
|
get :new
|
2020-06-29 17:48:01 +02:00
|
|
|
expect(response).to have_http_status(:success)
|
2020-02-18 16:41:56 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-17 10:28:59 +01:00
|
|
|
describe 'POST #create' do
|
|
|
|
let(:email) { 'plop@plop.com' }
|
2020-07-21 16:49:26 +02:00
|
|
|
let(:password) { 'my-s3cure-p4ssword' }
|
2018-01-17 10:28:59 +01:00
|
|
|
|
2018-01-23 18:16:44 +01:00
|
|
|
subject { post :create, params: { administrateur: { email: email } } }
|
2018-01-17 10:28:59 +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
|
|
|
|
expect(AdministrationMailer).to receive(:invite_admin).and_return(AdministrationMailer)
|
2018-05-25 18:05:28 +02:00
|
|
|
expect(AdministrationMailer).to receive(:deliver_later)
|
2018-01-17 10:28:59 +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
|
2019-08-19 10:47:37 +02:00
|
|
|
|
|
|
|
describe '#delete' do
|
2020-03-26 16:17:07 +01:00
|
|
|
subject { delete :delete, params: { id: administrateur.id } }
|
2019-08-19 10:47:37 +02:00
|
|
|
|
|
|
|
it 'deletes the admin' do
|
|
|
|
subject
|
|
|
|
|
2020-03-26 16:17:07 +01:00
|
|
|
expect(Administrateur.find_by(id: administrateur.id)).to be_nil
|
2019-08-19 10:47:37 +02:00
|
|
|
end
|
|
|
|
end
|
2020-02-18 17:40:30 +01:00
|
|
|
|
|
|
|
describe '#index' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
it 'searches admin by email' do
|
2020-03-26 16:17:07 +01:00
|
|
|
get :index, params: { search: administrateur.email }
|
2020-06-29 17:48:01 +02:00
|
|
|
expect(response).to have_http_status(:success)
|
2020-02-18 17:40:30 +01:00
|
|
|
end
|
|
|
|
end
|
2018-01-17 10:28:59 +01:00
|
|
|
end
|