Cover Settings::TwoFactorAuthenticationsController more (#3376)

This commit is contained in:
Akihiko Odaki 2017-05-30 01:07:07 +09:00 committed by Eugen Rochko
parent dde043f6cd
commit 0e4ca51951
1 changed files with 56 additions and 26 deletions

View File

@ -6,11 +6,13 @@ describe Settings::TwoFactorAuthenticationsController do
render_views render_views
let(:user) { Fabricate(:user) } let(:user) { Fabricate(:user) }
describe 'GET #show' do
context 'when signed in' do
before do before do
sign_in user, scope: :user sign_in user, scope: :user
end end
describe 'GET #show' do
describe 'when user requires otp for login already' do describe 'when user requires otp for login already' do
it 'returns http success' do it 'returns http success' do
user.update(otp_required_for_login: true) user.update(otp_required_for_login: true)
@ -30,7 +32,20 @@ describe Settings::TwoFactorAuthenticationsController do
end end
end end
context 'when not signed in' do
it 'redirects' do
get :show
expect(response).to redirect_to '/auth/sign_in'
end
end
end
describe 'POST #create' do describe 'POST #create' do
context 'when signed in' do
before do
sign_in user, scope: :user
end
describe 'when user requires otp for login already' do describe 'when user requires otp for login already' do
it 'redirects to show page' do it 'redirects to show page' do
user.update(otp_required_for_login: true) user.update(otp_required_for_login: true)
@ -51,16 +66,31 @@ describe Settings::TwoFactorAuthenticationsController do
end end
end end
context 'when not signed in' do
it 'redirects' do
get :show
expect(response).to redirect_to '/auth/sign_in'
end
end
end
describe 'POST #destroy' do describe 'POST #destroy' do
before do before do
user.update(otp_required_for_login: true) user.update(otp_required_for_login: true)
end end
it 'turns off otp requirement' do
it 'turns off otp requirement if signed in' do
sign_in user, scope: :user
post :destroy post :destroy
expect(response).to redirect_to(settings_two_factor_authentication_path) expect(response).to redirect_to(settings_two_factor_authentication_path)
user.reload user.reload
expect(user.otp_required_for_login).to eq(false) expect(user.otp_required_for_login).to eq(false)
end end
it 'redirects if not signed in' do
get :show
expect(response).to redirect_to '/auth/sign_in'
end
end end
end end