diff options
author | Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp> | 2017-05-30 01:05:20 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2017-05-29 18:05:20 +0200 |
commit | c778a60e4fe47647d97f64855fa8555fd5a5a0c8 (patch) | |
tree | f7c83f7367909f0aa4e8bc243c4e72447bd79f9a /spec/controllers | |
parent | c347327d54571f3e3e5ac2a01e6ad9e164e1d802 (diff) |
Cover Settings::TwoFactorAuthentication::RecoveryCodesController more (#3383)
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/settings/two_factor_authentication/recovery_codes_controller_spec.rb | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/spec/controllers/settings/two_factor_authentication/recovery_codes_controller_spec.rb b/spec/controllers/settings/two_factor_authentication/recovery_codes_controller_spec.rb index 3d6f5faab..aa28cdf3f 100644 --- a/spec/controllers/settings/two_factor_authentication/recovery_codes_controller_spec.rb +++ b/spec/controllers/settings/two_factor_authentication/recovery_codes_controller_spec.rb @@ -5,21 +5,27 @@ require 'rails_helper' describe Settings::TwoFactorAuthentication::RecoveryCodesController do render_views - let(:user) { Fabricate(:user) } - before do - sign_in user, scope: :user - end - describe 'POST #create' do - it 'updates the codes and shows them on a view' do - before = user.otp_backup_codes + it 'updates the codes and shows them on a view when signed in' do + user = Fabricate(:user) + otp_backup_codes = user.generate_otp_backup_codes! + expect_any_instance_of(User).to receive(:generate_otp_backup_codes!) do |value| + expect(value).to eq user + otp_backup_codes + end + sign_in user, scope: :user post :create - user.reload - expect(user.otp_backup_codes).not_to eq(before) + expect(assigns(:recovery_codes)).to eq otp_backup_codes + expect(flash[:notice]).to eq 'Recovery codes successfully regenerated' expect(response).to have_http_status(:success) expect(response).to render_template(:index) end + + it 'redirects when not signed in' do + post :create + expect(response).to redirect_to '/auth/sign_in' + end end end |