[fix #1709] A user can change its email

This commit is contained in:
simon lehericey 2019-07-08 10:40:50 +02:00 committed by Pierre de La Morinerie
parent 0f9fdf3f75
commit d36f6ebcd7
7 changed files with 125 additions and 7 deletions

View file

@ -1,6 +1,10 @@
require 'spec_helper'
describe Users::ProfilController, type: :controller do
let(:user) { create(:user) }
before { sign_in(user) }
describe 'POST #renew_api_token' do
let(:administrateur) { create(:administrateur) }
@ -16,4 +20,41 @@ describe Users::ProfilController, type: :controller do
it { expect(response.status).to render_template(:show) }
it { expect(flash.notice).to eq('Votre jeton a été regénéré.') }
end
describe 'PATCH #update_email' do
context 'when everything is fine' do
before do
patch :update_email, params: { user: { email: 'loulou@lou.com' } }
user.reload
end
it { expect(user.unconfirmed_email).to eq('loulou@lou.com') }
it { expect(response).to redirect_to(profil_path) }
it { expect(flash.notice).to eq(I18n.t('devise.registrations.update_needs_confirmation')) }
end
context 'when the mail is already taken' do
let!(:user2) { create(:user) }
before do
patch :update_email, params: { user: { email: user2.email } }
user.reload
end
it { expect(response).to redirect_to(profil_path) }
it { expect(flash.notice).to eq(I18n.t('devise.registrations.update_needs_confirmation')) }
end
context 'when the mail is incorrect' do
let!(:user2) { create(:user) }
before do
patch :update_email, params: { user: { email: 'incorrect' } }
user.reload
end
it { expect(response).to redirect_to(profil_path) }
it { expect(flash.alert).to eq(['Email invalide']) }
end
end
end