Apply automatic rubocop fixes

This commit is contained in:
Sebastian Serth
2021-05-14 10:51:44 +02:00
parent fe4000916c
commit 6cbecb5b39
440 changed files with 2705 additions and 1853 deletions

View File

@ -11,9 +11,9 @@ describe SessionsController do
let(:user_attributes) { FactoryBot.build(:teacher).attributes }
context 'with valid credentials' do
before(:each) do
before do
user.activate!
post :create, params: { email: user.email, password: password, remember_me: 1 }
post :create, params: {email: user.email, password: password, remember_me: 1}
end
expect_flash_message(:notice, :'sessions.create.success')
@ -21,7 +21,7 @@ describe SessionsController do
end
context 'with invalid credentials' do
before(:each) { post :create, params: { email: user.email, password: '', remember_me: 1 } }
before { post :create, params: {email: user.email, password: '', remember_me: 1} }
expect_flash_message(:danger, :'sessions.create.failure')
expect_template(:new)
@ -32,7 +32,8 @@ describe SessionsController do
let(:exercise) { FactoryBot.create(:dummy) }
let(:exercise2) { FactoryBot.create(:dummy) }
let(:nonce) { SecureRandom.hex }
before(:each) { I18n.locale = I18n.default_locale }
before { I18n.locale = I18n.default_locale }
context 'without OAuth parameters' do
it 'refuses the LTI launch' do
@ -44,14 +45,14 @@ describe SessionsController do
context 'without a valid consumer key' do
it 'refuses the LTI launch' do
expect(controller).to receive(:refuse_lti_launch).with(message: I18n.t('sessions.oauth.invalid_consumer')).and_call_original
post :create_through_lti, params: { oauth_consumer_key: SecureRandom.hex, oauth_signature: SecureRandom.hex }
post :create_through_lti, params: {oauth_consumer_key: SecureRandom.hex, oauth_signature: SecureRandom.hex}
end
end
context 'with an invalid OAuth signature' do
it 'refuses the LTI launch' do
expect(controller).to receive(:refuse_lti_launch).with(message: I18n.t('sessions.oauth.invalid_signature')).and_call_original
post :create_through_lti, params: { oauth_consumer_key: consumer.oauth_key, oauth_signature: SecureRandom.hex }
post :create_through_lti, params: {oauth_consumer_key: consumer.oauth_key, oauth_signature: SecureRandom.hex}
end
end
@ -60,7 +61,7 @@ describe SessionsController do
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:valid_request?).and_return(true)
expect(NonceStore).to receive(:has?).with(nonce).and_return(true)
expect(controller).to receive(:refuse_lti_launch).with(message: I18n.t('sessions.oauth.used_nonce')).and_call_original
post :create_through_lti, params: { oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex }
post :create_through_lti, params: {oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex}
end
end
@ -68,15 +69,16 @@ describe SessionsController do
it 'refuses the LTI launch' do
expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:valid_request?).and_return(true)
expect(controller).to receive(:refuse_lti_launch).with(message: I18n.t('sessions.oauth.invalid_exercise_token')).and_call_original
post :create_through_lti, params: { custom_token: '', oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: '123' }
post :create_through_lti, params: {custom_token: '', oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: '123'}
end
end
context 'with valid launch parameters' do
let(:locale) { :de }
let(:perform_request) { post :create_through_lti, params: { custom_locale: locale, custom_token: exercise.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id } }
let(:perform_request) { post :create_through_lti, params: {custom_locale: locale, custom_token: exercise.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id} }
let(:user) { FactoryBot.create(:external_user, consumer_id: consumer.id) }
before(:each) { expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:valid_request?).and_return(true) }
before { expect_any_instance_of(IMS::LTI::ToolProvider).to receive(:valid_request?).and_return(true) }
it 'assigns the current user' do
perform_request
@ -96,7 +98,7 @@ describe SessionsController do
end
it 'stores LTI parameters in the session' do
#Todo replace session with lti_parameter /should be done already
# Todo replace session with lti_parameter /should be done already
expect(controller).to receive(:store_lti_session_data)
perform_request
end
@ -109,7 +111,7 @@ describe SessionsController do
context 'when LTI outcomes are supported' do
let(:message) { I18n.t('sessions.create_through_lti.session_with_outcome', consumer: consumer) }
before(:each) do
before do
expect(controller).to receive(:lti_outcome_service?).and_return(true)
perform_request
end
@ -120,7 +122,7 @@ describe SessionsController do
context 'when LTI outcomes are not supported' do
let(:message) { I18n.t('sessions.create_through_lti.session_without_outcome', consumer: consumer) }
before(:each) do
before do
expect(controller).to receive(:lti_outcome_service?).and_return(false)
perform_request
end
@ -135,7 +137,7 @@ describe SessionsController do
it 'redirects to recommended exercise if requested token of proxy exercise' do
FactoryBot.create(:proxy_exercise, exercises: [exercise])
post :create_through_lti, params: { custom_locale: locale, custom_token: ProxyExercise.first.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id }
post :create_through_lti, params: {custom_locale: locale, custom_token: ProxyExercise.first.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id}
expect(controller).to redirect_to(implement_exercise_path(exercise.id))
end
@ -146,7 +148,7 @@ describe SessionsController do
exercise.save
exercise2.expected_difficulty = 1
exercise2.save
post :create_through_lti, params: { custom_locale: locale, custom_token: ProxyExercise.first.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id }
post :create_through_lti, params: {custom_locale: locale, custom_token: ProxyExercise.first.token, oauth_consumer_key: consumer.oauth_key, oauth_nonce: nonce, oauth_signature: SecureRandom.hex, user_id: user.external_id}
expect(controller).to redirect_to(implement_exercise_path(exercise2.id))
end
end
@ -154,13 +156,14 @@ describe SessionsController do
describe 'DELETE #destroy' do
let(:user) { double }
before(:each) {
before do
allow(controller).to receive(:set_sentry_context).and_return(nil)
expect(controller).to receive(:current_user).at_least(:once).and_return(user)
}
end
context 'with an internal user' do
before(:each) do
before do
allow(user).to receive(:external_user?).and_return(false)
allow(user).to receive(:forget_me!)
delete :destroy
@ -177,13 +180,13 @@ describe SessionsController do
end
context 'with an external user' do
before(:each) do
before do
allow(user).to receive(:external_user?).and_return(true)
delete :destroy
end
it 'clears the session' do
#Todo replace session with lti_parameter /should be done already
# Todo replace session with lti_parameter /should be done already
expect(controller).to receive(:clear_lti_session_data)
delete :destroy
end
@ -195,19 +198,11 @@ describe SessionsController do
end
describe 'GET #destroy_through_lti' do
let(:perform_request) { proc { get :destroy_through_lti, params: { consumer_id: consumer.id, submission_id: submission.id } } }
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:dummy)) }
before(:each) do
#Todo replace session with lti_parameter
#Todo create LtiParameter Object
# session[:lti_parameters] = {}
end
before(:each) { perform_request.call }
let(:perform_request) { proc { get :destroy_through_lti, params: {consumer_id: consumer.id, submission_id: submission.id} } }
let(:submission) { FactoryBot.create(:submission, exercise: FactoryBot.create(:dummy)) } before { perform_request.call }
it 'clears the session' do
#Todo replace session with lti_parameter /should be done already
# Todo replace session with lti_parameter /should be done already
expect(controller).to receive(:clear_lti_session_data)
perform_request.call
end
@ -218,7 +213,7 @@ describe SessionsController do
describe 'GET #new' do
context 'when no user is logged in' do
before(:each) do
before do
allow(controller).to receive(:set_sentry_context).and_return(nil)
expect(controller).to receive(:current_user).and_return(nil)
@ -230,7 +225,7 @@ describe SessionsController do
end
context 'when a user is already logged in' do
before(:each) do
before do
allow(controller).to receive(:set_sentry_context).and_return(nil)
expect(controller).to receive(:current_user).and_return(FactoryBot.build(:teacher))