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

View file

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