1
0

Use framework helpers instead of i-vars in controller specs (#27767)

This commit is contained in:
Matt Jankowski 2023-11-08 03:17:43 -05:00 committed by GitHub
parent 790f6356be
commit e545978076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 17 deletions

View File

@ -7,7 +7,7 @@ describe Auth::ConfirmationsController do
describe 'GET #new' do describe 'GET #new' do
it 'returns http success' do it 'returns http success' do
@request.env['devise.mapping'] = Devise.mappings[:user] request.env['devise.mapping'] = Devise.mappings[:user]
get :new get :new
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
@ -19,7 +19,7 @@ describe Auth::ConfirmationsController do
before do before do
allow(BootstrapTimelineWorker).to receive(:perform_async) allow(BootstrapTimelineWorker).to receive(:perform_async)
@request.env['devise.mapping'] = Devise.mappings[:user] request.env['devise.mapping'] = Devise.mappings[:user]
get :show, params: { confirmation_token: 'foobar' } get :show, params: { confirmation_token: 'foobar' }
end end
@ -37,7 +37,7 @@ describe Auth::ConfirmationsController do
before do before do
allow(BootstrapTimelineWorker).to receive(:perform_async) allow(BootstrapTimelineWorker).to receive(:perform_async)
@request.env['devise.mapping'] = Devise.mappings[:user] request.env['devise.mapping'] = Devise.mappings[:user]
get :show, params: { confirmation_token: 'foobar' } get :show, params: { confirmation_token: 'foobar' }
end end
@ -51,7 +51,7 @@ describe Auth::ConfirmationsController do
before do before do
allow(BootstrapTimelineWorker).to receive(:perform_async) allow(BootstrapTimelineWorker).to receive(:perform_async)
@request.env['devise.mapping'] = Devise.mappings[:user] request.env['devise.mapping'] = Devise.mappings[:user]
sign_in(user, scope: :user) sign_in(user, scope: :user)
get :show, params: { confirmation_token: 'foobar' } get :show, params: { confirmation_token: 'foobar' }
end end
@ -66,7 +66,7 @@ describe Auth::ConfirmationsController do
before do before do
allow(BootstrapTimelineWorker).to receive(:perform_async) allow(BootstrapTimelineWorker).to receive(:perform_async)
@request.env['devise.mapping'] = Devise.mappings[:user] request.env['devise.mapping'] = Devise.mappings[:user]
user.approved = false user.approved = false
user.save! user.save!
sign_in(user, scope: :user) sign_in(user, scope: :user)
@ -83,7 +83,7 @@ describe Auth::ConfirmationsController do
before do before do
allow(BootstrapTimelineWorker).to receive(:perform_async) allow(BootstrapTimelineWorker).to receive(:perform_async)
@request.env['devise.mapping'] = Devise.mappings[:user] request.env['devise.mapping'] = Devise.mappings[:user]
get :show, params: { confirmation_token: 'foobar' } get :show, params: { confirmation_token: 'foobar' }
end end

View File

@ -7,7 +7,7 @@ describe Auth::PasswordsController do
describe 'GET #new' do describe 'GET #new' do
it 'returns http success' do it 'returns http success' do
@request.env['devise.mapping'] = Devise.mappings[:user] request.env['devise.mapping'] = Devise.mappings[:user]
get :new get :new
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end

View File

@ -378,7 +378,7 @@ RSpec.describe Auth::SessionsController do
context 'when using a valid webauthn credential' do context 'when using a valid webauthn credential' do
before do before do
@controller.session[:webauthn_challenge] = challenge controller.session[:webauthn_challenge] = challenge
post :create, params: { user: { credential: fake_credential } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s } post :create, params: { user: { credential: fake_credential } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
end end

View File

@ -10,7 +10,7 @@ RSpec.describe HomeController do
context 'when not signed in' do context 'when not signed in' do
it 'returns http success' do it 'returns http success' do
@request.path = '/' request.path = '/'
expect(subject).to have_http_status(:success) expect(subject).to have_http_status(:success)
end end
end end

View File

@ -130,7 +130,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
it 'stores the challenge on the session' do it 'stores the challenge on the session' do
get :options get :options
expect(@controller.session[:webauthn_challenge]).to be_present expect(controller.session[:webauthn_challenge]).to be_present
end end
it 'does not change webauthn_id' do it 'does not change webauthn_id' do
@ -155,7 +155,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
it 'stores the challenge on the session' do it 'stores the challenge on the session' do
get :options get :options
expect(@controller.session[:webauthn_challenge]).to be_present expect(controller.session[:webauthn_challenge]).to be_present
end end
it 'sets user webauthn_id' do it 'sets user webauthn_id' do
@ -218,7 +218,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
context 'when creation succeeds' do context 'when creation succeeds' do
it 'returns http success' do it 'returns http success' do
@controller.session[:webauthn_challenge] = challenge controller.session[:webauthn_challenge] = challenge
post :create, params: { credential: new_webauthn_credential, nickname: nickname } post :create, params: { credential: new_webauthn_credential, nickname: nickname }
@ -226,7 +226,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
end end
it 'adds a new credential to user credentials' do it 'adds a new credential to user credentials' do
@controller.session[:webauthn_challenge] = challenge controller.session[:webauthn_challenge] = challenge
expect do expect do
post :create, params: { credential: new_webauthn_credential, nickname: nickname } post :create, params: { credential: new_webauthn_credential, nickname: nickname }
@ -234,7 +234,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
end end
it 'does not change webauthn_id' do it 'does not change webauthn_id' do
@controller.session[:webauthn_challenge] = challenge controller.session[:webauthn_challenge] = challenge
expect do expect do
post :create, params: { credential: new_webauthn_credential, nickname: nickname } post :create, params: { credential: new_webauthn_credential, nickname: nickname }
@ -244,7 +244,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
context 'when the nickname is already used' do context 'when the nickname is already used' do
it 'fails' do it 'fails' do
@controller.session[:webauthn_challenge] = challenge controller.session[:webauthn_challenge] = challenge
post :create, params: { credential: new_webauthn_credential, nickname: 'USB Key' } post :create, params: { credential: new_webauthn_credential, nickname: 'USB Key' }
@ -264,7 +264,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
end end
it 'fails' do it 'fails' do
@controller.session[:webauthn_challenge] = challenge controller.session[:webauthn_challenge] = challenge
post :create, params: { credential: new_webauthn_credential, nickname: nickname } post :create, params: { credential: new_webauthn_credential, nickname: nickname }
@ -277,7 +277,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
context 'when user have not enabled webauthn' do context 'when user have not enabled webauthn' do
context 'when creation succeeds' do context 'when creation succeeds' do
it 'creates a webauthn credential' do it 'creates a webauthn credential' do
@controller.session[:webauthn_challenge] = challenge controller.session[:webauthn_challenge] = challenge
expect do expect do
post :create, params: { credential: new_webauthn_credential, nickname: nickname } post :create, params: { credential: new_webauthn_credential, nickname: nickname }