diff options
Diffstat (limited to 'spec/controllers/profiles/two_factor_auths_controller_spec.rb')
-rw-r--r-- | spec/controllers/profiles/two_factor_auths_controller_spec.rb | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/spec/controllers/profiles/two_factor_auths_controller_spec.rb b/spec/controllers/profiles/two_factor_auths_controller_spec.rb index 1fb0b18622b..59eb33f4bc6 100644 --- a/spec/controllers/profiles/two_factor_auths_controller_spec.rb +++ b/spec/controllers/profiles/two_factor_auths_controller_spec.rb @@ -120,18 +120,46 @@ RSpec.describe Profiles::TwoFactorAuthsController do end describe 'DELETE destroy' do - let(:user) { create(:user, :two_factor) } + subject { delete :destroy } + + context 'for a user that has 2FA enabled' do + let(:user) { create(:user, :two_factor) } + + it 'disables two factor' do + subject + + expect(user.reload.two_factor_enabled?).to eq(false) + end + + it 'redirects to profile_account_path' do + subject + + expect(response).to redirect_to(profile_account_path) + end - it 'disables two factor' do - expect(user).to receive(:disable_two_factor!) + it 'displays a notice on success' do + subject - delete :destroy + expect(flash[:notice]) + .to eq _('Two-factor authentication has been disabled successfully!') + end end - it 'redirects to profile_account_path' do - delete :destroy + context 'for a user that does not have 2FA enabled' do + let(:user) { create(:user) } - expect(response).to redirect_to(profile_account_path) + it 'redirects to profile_account_path' do + subject + + expect(response).to redirect_to(profile_account_path) + end + + it 'displays an alert on failure' do + subject + + expect(flash[:alert]) + .to eq _('Two-factor authentication is not enabled for this user') + end end end end |