From 5e9bf9141c83ec4812a858b70e14733f745aeacd Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Fri, 8 Jul 2022 15:23:55 +0200 Subject: [PATCH] Fix Rubocop offenses --- .../admin/dashboard_controller_spec.rb | 4 +-- .../application_controller_spec.rb | 2 +- .../code_ocean/files_controller_spec.rb | 4 +-- .../codeharbor_links_controller_spec.rb | 4 +-- spec/controllers/consumers_controller_spec.rb | 12 ++++----- ...ror_template_attributes_controller_spec.rb | 8 +++--- .../error_templates_controller_spec.rb | 8 +++--- spec/controllers/events_controller_spec.rb | 6 ++--- .../execution_environments_controller_spec.rb | 18 ++++++------- spec/controllers/exercises_controller_spec.rb | 26 +++++++++---------- .../external_users_controller_spec.rb | 4 +-- .../controllers/file_types_controller_spec.rb | 12 ++++----- .../internal_users_controller_spec.rb | 22 ++++++++-------- .../request_for_comments_controller_spec.rb | 6 ++--- spec/controllers/sessions_controller_spec.rb | 4 +-- .../controllers/statistics_controller_spec.rb | 6 ++--- .../submissions_controller_spec.rb | 24 ++++++++--------- spec/support/controllers.rb | 4 +-- 18 files changed, 87 insertions(+), 87 deletions(-) diff --git a/spec/controllers/admin/dashboard_controller_spec.rb b/spec/controllers/admin/dashboard_controller_spec.rb index 21db904e..e0c581b2 100644 --- a/spec/controllers/admin/dashboard_controller_spec.rb +++ b/spec/controllers/admin/dashboard_controller_spec.rb @@ -9,7 +9,7 @@ describe Admin::DashboardController do describe 'with format HTML' do before { get :show } - expect_status(200) + expect_http_status(:ok) expect_template(:show) end @@ -17,7 +17,7 @@ describe Admin::DashboardController do before { get :show, format: :json } expect_json - expect_status(200) + expect_http_status(:ok) end end end diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 307c6498..d6e4f672 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -78,7 +78,7 @@ describe ApplicationController do describe 'GET #welcome' do before { get :welcome } - expect_status(200) + expect_http_status(:ok) expect_template(:welcome) end end diff --git a/spec/controllers/code_ocean/files_controller_spec.rb b/spec/controllers/code_ocean/files_controller_spec.rb index 759ab849..2c555b08 100644 --- a/spec/controllers/code_ocean/files_controller_spec.rb +++ b/spec/controllers/code_ocean/files_controller_spec.rb @@ -25,7 +25,7 @@ describe CodeOcean::FilesController do end expect_json - expect_status(201) + expect_http_status(:created) end context 'with an invalid file' do @@ -36,7 +36,7 @@ describe CodeOcean::FilesController do expect_assigns(file: CodeOcean::File) expect_json - expect_status(422) + expect_http_status(:unprocessable_entity) end end diff --git a/spec/controllers/codeharbor_links_controller_spec.rb b/spec/controllers/codeharbor_links_controller_spec.rb index 092e9f38..fdca2047 100644 --- a/spec/controllers/codeharbor_links_controller_spec.rb +++ b/spec/controllers/codeharbor_links_controller_spec.rb @@ -19,7 +19,7 @@ describe CodeharborLinksController do get :new end - expect_status(200) + expect_http_status(:ok) end describe 'GET #edit' do @@ -27,7 +27,7 @@ describe CodeharborLinksController do before { get :edit, params: {id: codeharbor_link.id} } - expect_status(200) + expect_http_status(:ok) end describe 'POST #create' do diff --git a/spec/controllers/consumers_controller_spec.rb b/spec/controllers/consumers_controller_spec.rb index b5e5a1a8..2766e49f 100644 --- a/spec/controllers/consumers_controller_spec.rb +++ b/spec/controllers/consumers_controller_spec.rb @@ -27,7 +27,7 @@ describe ConsumersController do before { post :create, params: {consumer: {}} } expect_assigns(consumer: Consumer) - expect_status(200) + expect_http_status(:ok) expect_template(:new) end end @@ -49,7 +49,7 @@ describe ConsumersController do before { get :edit, params: {id: consumer.id} } expect_assigns(consumer: Consumer) - expect_status(200) + expect_http_status(:ok) expect_template(:edit) end @@ -60,7 +60,7 @@ describe ConsumersController do end expect_assigns(consumers: Consumer.all) - expect_status(200) + expect_http_status(:ok) expect_template(:index) end @@ -68,7 +68,7 @@ describe ConsumersController do before { get :new } expect_assigns(consumer: Consumer) - expect_status(200) + expect_http_status(:ok) expect_template(:new) end @@ -76,7 +76,7 @@ describe ConsumersController do before { get :show, params: {id: consumer.id} } expect_assigns(consumer: :consumer) - expect_status(200) + expect_http_status(:ok) expect_template(:show) end @@ -92,7 +92,7 @@ describe ConsumersController do before { put :update, params: {consumer: {name: ''}, id: consumer.id} } expect_assigns(consumer: Consumer) - expect_status(200) + expect_http_status(:ok) expect_template(:edit) end end diff --git a/spec/controllers/error_template_attributes_controller_spec.rb b/spec/controllers/error_template_attributes_controller_spec.rb index 521052df..e3e28f44 100644 --- a/spec/controllers/error_template_attributes_controller_spec.rb +++ b/spec/controllers/error_template_attributes_controller_spec.rb @@ -10,13 +10,13 @@ describe ErrorTemplateAttributesController do it 'gets index' do get :index - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) expect(assigns(:error_template_attributes)).not_to be_nil end it 'gets new' do get :new - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) end it 'creates error_template_attribute' do @@ -26,12 +26,12 @@ describe ErrorTemplateAttributesController do it 'shows error_template_attribute' do get :show, params: {id: error_template_attribute} - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) end it 'gets edit' do get :edit, params: {id: error_template_attribute} - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) end it 'updates error_template_attribute' do diff --git a/spec/controllers/error_templates_controller_spec.rb b/spec/controllers/error_templates_controller_spec.rb index 5a79cddf..830cf68f 100644 --- a/spec/controllers/error_templates_controller_spec.rb +++ b/spec/controllers/error_templates_controller_spec.rb @@ -10,13 +10,13 @@ describe ErrorTemplatesController do it 'gets index' do get :index - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) expect(assigns(:error_templates)).not_to be_nil end it 'gets new' do get :new - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) end it 'creates error_template' do @@ -26,12 +26,12 @@ describe ErrorTemplatesController do it 'shows error_template' do get :show, params: {id: error_template} - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) end it 'gets edit' do get :edit, params: {id: error_template} - expect(response.status).to eq(200) + expect(response).to have_http_status(:ok) end it 'updates error_template' do diff --git a/spec/controllers/events_controller_spec.rb b/spec/controllers/events_controller_spec.rb index f9baf1c8..888d9280 100644 --- a/spec/controllers/events_controller_spec.rb +++ b/spec/controllers/events_controller_spec.rb @@ -20,20 +20,20 @@ describe EventsController do expect { perform_request.call }.to change(Event, :count).by(1) end - expect_status(201) + expect_http_status(:created) end context 'with an invalid event' do before { post :create, params: {event: {exercise_id: 847_482}} } expect_assigns(event: Event) - expect_status(422) + expect_http_status(:unprocessable_entity) end context 'with no event' do before { post :create } - expect_status(422) + expect_http_status(:unprocessable_entity) end end end diff --git a/spec/controllers/execution_environments_controller_spec.rb b/spec/controllers/execution_environments_controller_spec.rb index 8ab91cc6..aee51f6d 100644 --- a/spec/controllers/execution_environments_controller_spec.rb +++ b/spec/controllers/execution_environments_controller_spec.rb @@ -46,7 +46,7 @@ describe ExecutionEnvironmentsController do end expect_assigns(execution_environment: ExecutionEnvironment) - expect_status(200) + expect_http_status(:ok) expect_template(:new) it 'does not register the execution environment with the runner management' do @@ -82,7 +82,7 @@ describe ExecutionEnvironmentsController do expect_assigns(docker_images: Array) expect_assigns(execution_environment: :execution_environment) - expect_status(200) + expect_http_status(:ok) expect_template(:edit) end @@ -98,7 +98,7 @@ describe ExecutionEnvironmentsController do expect_assigns(execution_environment: :execution_environment) expect_json - expect_status(200) + expect_http_status(:ok) end describe 'GET #index' do @@ -108,7 +108,7 @@ describe ExecutionEnvironmentsController do end expect_assigns(execution_environments: ExecutionEnvironment.all) - expect_status(200) + expect_http_status(:ok) expect_template(:index) end @@ -119,7 +119,7 @@ describe ExecutionEnvironmentsController do expect_assigns(docker_images: Array) expect_assigns(execution_environment: ExecutionEnvironment) - expect_status(200) + expect_http_status(:ok) expect_template(:new) end @@ -158,7 +158,7 @@ describe ExecutionEnvironmentsController do before { get :shell, params: {id: execution_environment.id} } expect_assigns(execution_environment: :execution_environment) - expect_status(200) + expect_http_status(:ok) expect_template(:shell) end @@ -166,7 +166,7 @@ describe ExecutionEnvironmentsController do before { get :statistics, params: {id: execution_environment.id} } expect_assigns(execution_environment: :execution_environment) - expect_status(200) + expect_http_status(:ok) expect_template(:statistics) end @@ -174,7 +174,7 @@ describe ExecutionEnvironmentsController do before { get :show, params: {id: execution_environment.id} } expect_assigns(execution_environment: :execution_environment) - expect_status(200) + expect_http_status(:ok) expect_template(:show) end @@ -206,7 +206,7 @@ describe ExecutionEnvironmentsController do end expect_assigns(execution_environment: ExecutionEnvironment) - expect_status(200) + expect_http_status(:ok) expect_template(:edit) it 'does not update the execution environment at the runner management' do diff --git a/spec/controllers/exercises_controller_spec.rb b/spec/controllers/exercises_controller_spec.rb index caf76a98..847dc805 100644 --- a/spec/controllers/exercises_controller_spec.rb +++ b/spec/controllers/exercises_controller_spec.rb @@ -20,7 +20,7 @@ describe ExercisesController do end expect_json - expect_status(200) + expect_http_status(:ok) end describe 'POST #clone' do @@ -122,7 +122,7 @@ describe ExercisesController do before { post :create, params: {exercise: {}} } expect_assigns(exercise: Exercise) - expect_status(200) + expect_http_status(:ok) expect_template(:new) end end @@ -144,7 +144,7 @@ describe ExercisesController do before { get :edit, params: {id: exercise.id} } expect_assigns(exercise: :exercise) - expect_status(200) + expect_http_status(:ok) expect_template(:edit) end @@ -173,7 +173,7 @@ describe ExercisesController do end end - expect_status(200) + expect_http_status(:ok) expect_template(:implement) end @@ -195,7 +195,7 @@ describe ExercisesController do end expect_assigns(exercises: :scope) - expect_status(200) + expect_http_status(:ok) expect_template(:index) end @@ -204,7 +204,7 @@ describe ExercisesController do expect_assigns(execution_environments: ExecutionEnvironment.all, exercise: Exercise) expect_assigns(exercise: Exercise) - expect_status(200) + expect_http_status(:ok) expect_template(:new) end @@ -213,7 +213,7 @@ describe ExercisesController do before { get :show, params: {id: exercise.id} } expect_assigns(exercise: :exercise) - expect_status(200) + expect_http_status(:ok) expect_template(:show) end end @@ -223,7 +223,7 @@ describe ExercisesController do before { get :reload, format: :json, params: {id: exercise.id} } expect_assigns(exercise: :exercise) - expect_status(200) + expect_http_status(:ok) expect_template(:reload) end end @@ -232,7 +232,7 @@ describe ExercisesController do before { get :statistics, params: {id: exercise.id} } expect_assigns(exercise: :exercise) - expect_status(200) + expect_http_status(:ok) expect_template(:statistics) end @@ -285,7 +285,7 @@ describe ExercisesController do end expect_json - expect_status(200) + expect_http_status(:ok) end context 'when the score transmission fails' do @@ -301,7 +301,7 @@ describe ExercisesController do end expect_json - expect_status(503) + expect_http_status(:service_unavailable) end end @@ -322,7 +322,7 @@ describe ExercisesController do end expect_json - expect_status(200) + expect_http_status(:ok) end end @@ -340,7 +340,7 @@ describe ExercisesController do before { put :update, params: {exercise: {title: ''}, id: exercise.id} } expect_assigns(exercise: Exercise) - expect_status(200) + expect_http_status(:ok) expect_template(:edit) end end diff --git a/spec/controllers/external_users_controller_spec.rb b/spec/controllers/external_users_controller_spec.rb index d39acb26..4530c78a 100644 --- a/spec/controllers/external_users_controller_spec.rb +++ b/spec/controllers/external_users_controller_spec.rb @@ -12,7 +12,7 @@ describe ExternalUsersController do before { get :index } expect_assigns(users: ExternalUser.all) - expect_status(200) + expect_http_status(:ok) expect_template(:index) end @@ -20,7 +20,7 @@ describe ExternalUsersController do before { get :show, params: {id: users.first.id} } expect_assigns(user: ExternalUser) - expect_status(200) + expect_http_status(:ok) expect_template(:show) end end diff --git a/spec/controllers/file_types_controller_spec.rb b/spec/controllers/file_types_controller_spec.rb index 3f13df2d..45f327b7 100644 --- a/spec/controllers/file_types_controller_spec.rb +++ b/spec/controllers/file_types_controller_spec.rb @@ -29,7 +29,7 @@ describe FileTypesController do expect_assigns(editor_modes: Array) expect_assigns(file_type: FileType) - expect_status(200) + expect_http_status(:ok) expect_template(:new) end end @@ -52,7 +52,7 @@ describe FileTypesController do expect_assigns(editor_modes: Array) expect_assigns(file_type: FileType) - expect_status(200) + expect_http_status(:ok) expect_template(:edit) end @@ -63,7 +63,7 @@ describe FileTypesController do end expect_assigns(file_types: FileType.all) - expect_status(200) + expect_http_status(:ok) expect_template(:index) end @@ -72,7 +72,7 @@ describe FileTypesController do expect_assigns(editor_modes: Array) expect_assigns(file_type: FileType) - expect_status(200) + expect_http_status(:ok) expect_template(:new) end @@ -80,7 +80,7 @@ describe FileTypesController do before { get :show, params: {id: file_type.id} } expect_assigns(file_type: :file_type) - expect_status(200) + expect_http_status(:ok) expect_template(:show) end @@ -98,7 +98,7 @@ describe FileTypesController do expect_assigns(editor_modes: Array) expect_assigns(file_type: FileType) - expect_status(200) + expect_http_status(:ok) expect_template(:edit) end end diff --git a/spec/controllers/internal_users_controller_spec.rb b/spec/controllers/internal_users_controller_spec.rb index 7ff2fb7b..cde7e530 100644 --- a/spec/controllers/internal_users_controller_spec.rb +++ b/spec/controllers/internal_users_controller_spec.rb @@ -33,7 +33,7 @@ describe InternalUsersController do before { get :activate, params: {id: user.id, token: user.activation_token} } expect_assigns(user: InternalUser) - expect_status(200) + expect_http_status(:ok) expect_template(:activate) end end @@ -138,7 +138,7 @@ describe InternalUsersController do before { post :create, params: {internal_user: {}} } expect_assigns(user: InternalUser) - expect_status(200) + expect_http_status(:ok) expect_template(:new) end end @@ -165,7 +165,7 @@ describe InternalUsersController do end expect_assigns(user: InternalUser) - expect_status(200) + expect_http_status(:ok) expect_template(:edit) end @@ -178,7 +178,7 @@ describe InternalUsersController do get :forgot_password end - expect_status(200) + expect_http_status(:ok) expect_template(:forgot_password) end @@ -213,7 +213,7 @@ describe InternalUsersController do context 'without an email address' do before { post :forgot_password } - expect_status(200) + expect_http_status(:ok) expect_template(:forgot_password) end end @@ -225,7 +225,7 @@ describe InternalUsersController do end expect_assigns(users: InternalUser.all) - expect_status(200) + expect_http_status(:ok) expect_template(:index) end @@ -236,7 +236,7 @@ describe InternalUsersController do end expect_assigns(user: InternalUser) - expect_status(200) + expect_http_status(:ok) expect_template(:new) end @@ -256,7 +256,7 @@ describe InternalUsersController do end expect_assigns(user: :user) - expect_status(200) + expect_http_status(:ok) expect_template(:reset_password) end end @@ -295,7 +295,7 @@ describe InternalUsersController do end expect_assigns(user: :user) - expect_status(200) + expect_http_status(:ok) expect_template(:reset_password) end end @@ -308,7 +308,7 @@ describe InternalUsersController do end expect_assigns(user: InternalUser) - expect_status(200) + expect_http_status(:ok) expect_template(:show) end @@ -326,7 +326,7 @@ describe InternalUsersController do before { put :update, params: {internal_user: {email: ''}, id: users.first.id} } expect_assigns(user: InternalUser) - expect_status(200) + expect_http_status(:ok) expect_template(:edit) end end diff --git a/spec/controllers/request_for_comments_controller_spec.rb b/spec/controllers/request_for_comments_controller_spec.rb index 1950ff24..f607fac2 100644 --- a/spec/controllers/request_for_comments_controller_spec.rb +++ b/spec/controllers/request_for_comments_controller_spec.rb @@ -35,14 +35,14 @@ describe RequestForCommentsController do describe 'GET #my_comment_requests' do before { get :my_comment_requests } - expect_status(200) + expect_http_status(:ok) expect_template(:index) end describe 'GET #rfcs_with_my_comments' do before { get :rfcs_with_my_comments } - expect_status(200) + expect_http_status(:ok) expect_template(:index) end @@ -52,7 +52,7 @@ describe RequestForCommentsController do get :rfcs_for_exercise, params: {exercise_id: exercise.id} end - expect_status(200) + expect_http_status(:ok) expect_template(:index) end end diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index 3cf9b490..f4edd27d 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -217,7 +217,7 @@ describe SessionsController do perform_request.call end - expect_status(200) + expect_http_status(:ok) expect_template(:destroy_through_lti) end @@ -230,7 +230,7 @@ describe SessionsController do get :new end - expect_status(200) + expect_http_status(:ok) expect_template(:new) end diff --git a/spec/controllers/statistics_controller_spec.rb b/spec/controllers/statistics_controller_spec.rb index 9a0cbcb6..78d367e6 100644 --- a/spec/controllers/statistics_controller_spec.rb +++ b/spec/controllers/statistics_controller_spec.rb @@ -11,7 +11,7 @@ describe StatisticsController do describe "GET ##{route}" do before { get route } - expect_status(200) + expect_http_status(:ok) expect_template(route) end end @@ -20,7 +20,7 @@ describe StatisticsController do describe "GET ##{route}" do before { get route } - expect_status(200) + expect_http_status(:ok) expect_template(:activity_history) end end @@ -29,7 +29,7 @@ describe StatisticsController do describe "GET ##{route}.json" do before { get route, format: :json } - expect_status(200) + expect_http_status(:ok) expect_json end end diff --git a/spec/controllers/submissions_controller_spec.rb b/spec/controllers/submissions_controller_spec.rb index cb764d86..41539eb3 100644 --- a/spec/controllers/submissions_controller_spec.rb +++ b/spec/controllers/submissions_controller_spec.rb @@ -26,7 +26,7 @@ describe SubmissionsController do end expect_json - expect_status(201) + expect_http_status(:created) end context 'with an invalid submission' do @@ -34,7 +34,7 @@ describe SubmissionsController do expect_assigns(submission: Submission) expect_json - expect_status(422) + expect_http_status(:unprocessable_entity) end end @@ -42,7 +42,7 @@ describe SubmissionsController do context 'with an invalid filename' do before { get :download_file, params: {filename: SecureRandom.hex, id: submission.id} } - expect_status(404) + expect_http_status(:not_found) end context 'with a valid binary filename' do @@ -56,7 +56,7 @@ describe SubmissionsController do expect_assigns(file: :file) expect_assigns(submission: :submission) expect_content_type('application/octet-stream') - expect_status(200) + expect_http_status(:ok) it 'sets the correct filename' do expect(response.headers['Content-Disposition']).to include("attachment; filename=\"#{file.name_with_extension}\"") @@ -75,7 +75,7 @@ describe SubmissionsController do expect_assigns(file: :file) expect_assigns(submission: :submission) expect_content_type('video/mp4') - expect_status(200) + expect_http_status(:ok) it 'sets the correct filename' do expect(response.headers['Content-Disposition']).to include("attachment; filename=\"#{file.name_with_extension}\"") @@ -88,7 +88,7 @@ describe SubmissionsController do expect_assigns(file: :file) expect_assigns(submission: :submission) expect_content_type('text/javascript') - expect_status(200) + expect_http_status(:ok) it 'sets the correct filename' do expect(response.headers['Content-Disposition']).to include("attachment; filename=\"#{file.name_with_extension}\"") @@ -104,7 +104,7 @@ describe SubmissionsController do end expect_assigns(submissions: Submission.all) - expect_status(200) + expect_http_status(:ok) expect_template(:index) end @@ -114,7 +114,7 @@ describe SubmissionsController do context 'with an invalid filename' do before { get :render_file, params: {filename: SecureRandom.hex, id: submission.id} } - expect_status(404) + expect_http_status(:not_found) end context 'with a valid filename' do @@ -128,7 +128,7 @@ describe SubmissionsController do expect_assigns(file: :file) expect_assigns(submission: :submission) expect_content_type('video/mp4') - expect_status(200) + expect_http_status(:ok) it 'renders the file content' do expect(response.body).to eq(file.native_file.read) @@ -141,7 +141,7 @@ describe SubmissionsController do expect_assigns(file: :file) expect_assigns(submission: :submission) expect_content_type('text/javascript') - expect_status(200) + expect_http_status(:ok) it 'renders the file content' do expect(response.body).to eq(file.content) @@ -167,7 +167,7 @@ describe SubmissionsController do before { get :show, params: {id: submission.id} } expect_assigns(submission: :submission) - expect_status(200) + expect_http_status(:ok) expect_template(:show) end @@ -179,7 +179,7 @@ describe SubmissionsController do before { get :show, params: {id: submission.id}, format: :json } expect_assigns(submission: :submission) - expect_status(200) + expect_http_status(:ok) %i[render run test].each do |action| describe "##{action}_url" do diff --git a/spec/support/controllers.rb b/spec/support/controllers.rb index 9246911a..3c50c350 100644 --- a/spec/support/controllers.rb +++ b/spec/support/controllers.rb @@ -49,9 +49,9 @@ def expect_redirect(path = nil) end end -def expect_status(status) +def expect_http_status(status) it "responds with status #{status}" do - expect(response.status).to eq(status) + expect(response).to have_http_status(status) end end