demarches-normaliennes/spec/controllers/manager/users_controller_spec.rb
2021-10-07 15:51:31 +02:00

61 lines
1.4 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

describe Manager::UsersController, type: :controller do
let(:super_admin) { create(:super_admin) }
describe '#show' do
render_views
let(:super_admin) { create(:super_admin) }
let(:user) { create(:user) }
before do
sign_in(super_admin)
get :show, params: { id: user.id }
end
it { expect(response.body).to include(user.email) }
end
describe '#update' do
let!(:user) { create(:user, email: 'ancien.email@domaine.fr') }
before {
sign_in super_admin
}
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} » nest pas une adresse valide.")
end
end
end
describe '#delete' do
let!(:user) { create(:user) }
before { sign_in super_admin }
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