2020-01-08 10:50:16 +01:00
|
|
|
describe Manager::UsersController, type: :controller do
|
2020-11-05 15:09:11 +01:00
|
|
|
let(:super_admin) { create(:super_admin) }
|
2020-01-08 10:50:16 +01:00
|
|
|
|
2020-03-26 16:17:07 +01:00
|
|
|
describe '#show' do
|
|
|
|
render_views
|
|
|
|
|
2020-11-05 15:09:11 +01:00
|
|
|
let(:super_admin) { create(:super_admin) }
|
2020-03-26 16:17:07 +01:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2020-11-05 15:09:11 +01:00
|
|
|
sign_in(super_admin)
|
2020-03-26 16:17:07 +01:00
|
|
|
get :show, params: { id: user.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response.body).to include(user.email) }
|
|
|
|
end
|
|
|
|
|
2020-01-13 14:35:25 +01:00
|
|
|
describe '#update' do
|
|
|
|
let!(:user) { create(:user, email: 'ancien.email@domaine.fr') }
|
|
|
|
|
|
|
|
before {
|
2020-11-05 15:09:11 +01:00
|
|
|
sign_in super_admin
|
2020-01-13 14:35:25 +01:00
|
|
|
}
|
|
|
|
subject { patch :update, params: { id: user.id, user: { email: nouvel_email } } }
|
|
|
|
|
|
|
|
describe 'with a valid email' do
|
|
|
|
let(:nouvel_email) { 'nouvel.email@domaine.fr' }
|
|
|
|
|
|
|
|
it 'updates the user email' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(User.find_by(id: user.id).email).to eq(nouvel_email)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with an invalid email' do
|
|
|
|
let(:nouvel_email) { 'plop' }
|
|
|
|
|
|
|
|
it 'does not update the user email' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(User.find_by(id: user.id).email).not_to eq(nouvel_email)
|
|
|
|
expect(flash[:error]).to match("« #{nouvel_email} » n'est pas une adresse valide.")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-08 10:50:16 +01:00
|
|
|
describe '#delete' do
|
|
|
|
let!(:user) { create(:user) }
|
|
|
|
|
2020-11-05 15:09:11 +01:00
|
|
|
before { sign_in super_admin }
|
2020-01-08 10:50:16 +01:00
|
|
|
|
|
|
|
subject { delete :delete, params: { id: user.id } }
|
|
|
|
|
|
|
|
it 'deletes the user' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(User.find_by(id: user.id)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|