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

@ -5,12 +5,14 @@ require 'rails_helper'
describe ExercisesController do
let(:exercise) { FactoryBot.create(:dummy) }
let(:user) { FactoryBot.create(:admin) }
before(:each) { allow(controller).to receive(:current_user).and_return(user) }
before { allow(controller).to receive(:current_user).and_return(user) }
describe 'PUT #batch_update' do
let(:attributes) { { 'public': 'true'} }
let(:perform_request) { proc { put :batch_update, params: { exercises: {0 => attributes.merge(id: exercise.id)} } } }
before(:each) { perform_request.call }
let(:attributes) { {public: 'true'} }
let(:perform_request) { proc { put :batch_update, params: {exercises: {0 => attributes.merge(id: exercise.id)}} } }
before { perform_request.call }
it 'updates the exercises' do
expect_any_instance_of(Exercise).to receive(:update).with(attributes)
@ -22,10 +24,10 @@ describe ExercisesController do
end
describe 'POST #clone' do
let(:perform_request) { proc { post :clone, params: { id: exercise.id } } }
let(:perform_request) { proc { post :clone, params: {id: exercise.id} } }
context 'when saving succeeds' do
before(:each) { perform_request.call }
before { perform_request.call }
expect_assigns(exercise: Exercise)
@ -42,7 +44,7 @@ describe ExercisesController do
end
context 'when saving fails' do
before(:each) do
before do
expect_any_instance_of(Exercise).to receive(:save).and_return(false)
perform_request.call
end
@ -57,8 +59,9 @@ describe ExercisesController do
let(:exercise_attributes) { FactoryBot.build(:dummy).attributes }
context 'with a valid exercise' do
let(:perform_request) { proc { post :create, params: { exercise: exercise_attributes } } }
before(:each) { perform_request.call }
let(:perform_request) { proc { post :create, params: {exercise: exercise_attributes} } }
before { perform_request.call }
expect_assigns(exercise: Exercise)
@ -70,7 +73,7 @@ describe ExercisesController do
end
context 'when including a file' do
let(:perform_request) { proc { post :create, params: { exercise: exercise_attributes.merge(files_attributes: files_attributes) } } }
let(:perform_request) { proc { post :create, params: {exercise: exercise_attributes.merge(files_attributes: files_attributes)} } }
context 'when specifying the file content within the form' do
let(:files_attributes) { {'0' => FactoryBot.build(:file).attributes} }
@ -116,7 +119,7 @@ describe ExercisesController do
end
context 'with an invalid exercise' do
before(:each) { post :create, params: { exercise: { } } }
before { post :create, params: {exercise: {}} }
expect_assigns(exercise: Exercise)
expect_status(200)
@ -125,20 +128,20 @@ describe ExercisesController do
end
describe 'DELETE #destroy' do
before(:each) { delete :destroy, params: { id: exercise.id } }
before { delete :destroy, params: {id: exercise.id} }
expect_assigns(exercise: :exercise)
it 'destroys the exercise' do
exercise = FactoryBot.create(:dummy)
expect { delete :destroy, params: { id: exercise.id } }.to change(Exercise, :count).by(-1)
expect { delete :destroy, params: {id: exercise.id} }.to change(Exercise, :count).by(-1)
end
expect_redirect(:exercises)
end
describe 'GET #edit' do
before(:each) { get :edit, params: { id: exercise.id } }
before { get :edit, params: {id: exercise.id} }
expect_assigns(exercise: :exercise)
expect_status(200)
@ -146,11 +149,12 @@ describe ExercisesController do
end
describe 'GET #implement' do
let(:perform_request) { proc { get :implement, params: { id: exercise.id } } }
let(:perform_request) { proc { get :implement, params: {id: exercise.id} } }
context 'with an exercise with visible files' do
let(:exercise) { FactoryBot.create(:fibonacci) }
before(:each) { perform_request.call }
before { perform_request.call }
expect_assigns(exercise: :exercise)
@ -174,7 +178,7 @@ describe ExercisesController do
end
context 'with an exercise without visible files' do
before(:each) { perform_request.call }
before { perform_request.call }
expect_assigns(exercise: :exercise)
expect_flash_message(:alert, :'exercises.implement.no_files')
@ -184,8 +188,10 @@ describe ExercisesController do
describe 'GET #index' do
let(:scope) { Pundit.policy_scope!(user, Exercise) }
before(:all) { FactoryBot.create_pair(:dummy) }
before(:each) { get :index }
before { get :index }
expect_assigns(exercises: :scope)
expect_status(200)
@ -193,7 +199,7 @@ describe ExercisesController do
end
describe 'GET #new' do
before(:each) { get :new }
before { get :new }
expect_assigns(execution_environments: ExecutionEnvironment.all, exercise: Exercise)
expect_assigns(exercise: Exercise)
@ -203,7 +209,7 @@ describe ExercisesController do
describe 'GET #show' do
context 'as admin' do
before(:each) { get :show, params: { id: exercise.id } }
before { get :show, params: {id: exercise.id} }
expect_assigns(exercise: :exercise)
expect_status(200)
@ -213,7 +219,7 @@ describe ExercisesController do
describe 'GET #reload' do
context 'as anyone' do
before(:each) { get :reload, format: :json, params: { id: exercise.id } }
before { get :reload, format: :json, params: {id: exercise.id} }
expect_assigns(exercise: :exercise)
expect_status(200)
@ -222,7 +228,7 @@ describe ExercisesController do
end
describe 'GET #statistics' do
before(:each) { get :statistics, params: { id: exercise.id } }
before { get :statistics, params: {id: exercise.id} }
expect_assigns(exercise: :exercise)
expect_status(200)
@ -231,23 +237,23 @@ describe ExercisesController do
describe 'POST #submit' do
let(:output) { {} }
let(:perform_request) { post :submit, format: :json, params: { id: exercise.id, submission: {cause: 'submit', exercise_id: exercise.id} } }
let(:perform_request) { post :submit, format: :json, params: {id: exercise.id, submission: {cause: 'submit', exercise_id: exercise.id}} }
let(:user) { FactoryBot.create(:external_user) }
let!(:lti_parameter) { FactoryBot.create(:lti_parameter, external_user: user, exercise: exercise) }
before(:each) do
before do
allow_any_instance_of(Submission).to receive(:normalized_score).and_return(1)
expect(controller).to receive(:collect_test_results).and_return([{score: 1, weight: 1}])
expect(controller).to receive(:score_submission).and_call_original
end
context 'when LTI outcomes are supported' do
before(:each) do
before do
expect(controller).to receive(:lti_outcome_service?).and_return(true)
end
context 'when the score transmission succeeds' do
before(:each) do
before do
expect(controller).to receive(:send_score).and_return(status: 'success')
perform_request
end
@ -263,7 +269,7 @@ describe ExercisesController do
end
context 'when the score transmission fails' do
before(:each) do
before do
expect(controller).to receive(:send_score).and_return(status: 'unsupported')
perform_request
end
@ -280,7 +286,7 @@ describe ExercisesController do
end
context 'when LTI outcomes are not supported' do
before(:each) do
before do
expect(controller).to receive(:lti_outcome_service?).and_return(false)
expect(controller).not_to receive(:send_score)
perform_request
@ -300,14 +306,15 @@ describe ExercisesController do
describe 'PUT #update' do
context 'with a valid exercise' do
let(:exercise_attributes) { FactoryBot.build(:dummy).attributes }
before(:each) { put :update, params: { exercise: exercise_attributes, id: exercise.id } }
before { put :update, params: {exercise: exercise_attributes, id: exercise.id} }
expect_assigns(exercise: Exercise)
expect_redirect(:exercise)
end
context 'with an invalid exercise' do
before(:each) { put :update, params: { exercise: {title: ''}, id: exercise.id } }
before { put :update, params: {exercise: {title: ''}, id: exercise.id} }
expect_assigns(exercise: Exercise)
expect_status(200)
@ -321,7 +328,7 @@ describe ExercisesController do
describe 'POST #export_external_check' do
render_views
let(:post_request) { post :export_external_check, params: { id: exercise.id } }
let(:post_request) { post :export_external_check, params: {id: exercise.id} }
let!(:codeharbor_link) { FactoryBot.create(:codeharbor_link, user: user) }
let(:external_check_hash) { {message: message, exercise_found: true, update_right: update_right, error: error} }
let(:message) { 'message' }
@ -509,7 +516,7 @@ describe ExercisesController do
end
context 'when the imported exercise is invalid' do
before { allow(ProformaService::Import).to receive(:call) { imported_exercise.tap { |e| e.files = [] }.tap { |e| e.title = nil } } }
before { allow(ProformaService::Import).to receive(:call) { imported_exercise.tap {|e| e.files = [] }.tap {|e| e.title = nil } } }
it 'responds with correct status code' do
expect { post_request }.not_to(change { imported_exercise.reload.files.count })