Fix Rubocop offenses

This commit is contained in:
Sebastian Serth
2023-09-11 14:10:16 +02:00
parent a542985edd
commit c29256aa81
23 changed files with 27 additions and 27 deletions

View File

@ -21,7 +21,7 @@ module FileConversion
# Optimize SQL queries: We are first fetching all required file types from the database.
# Then, we store them in a hash, so that we can access them by using their file extension.
file_types = {}
FileType.where(file_extension: files.pluck('extension')).each do |file_type|
FileType.where(file_extension: files.pluck('extension')).find_each do |file_type|
file_types[file_type.file_extension] = file_type
end

View File

@ -11,7 +11,7 @@ class ErrorTemplateAttributesController < ApplicationController
# GET /error_template_attributes
# GET /error_template_attributes.json
def index
@error_template_attributes = ErrorTemplateAttribute.all.order('important DESC', :key,
@error_template_attributes = ErrorTemplateAttribute.order('important DESC', :key,
:id).paginate(page: params[:page], per_page: per_page_param)
authorize!
end

View File

@ -11,7 +11,7 @@ class ErrorTemplatesController < ApplicationController
# GET /error_templates
# GET /error_templates.json
def index
@error_templates = ErrorTemplate.all.order(:execution_environment_id, :name).paginate(page: params[:page], per_page: per_page_param)
@error_templates = ErrorTemplate.order(:execution_environment_id, :name).paginate(page: params[:page], per_page: per_page_param)
authorize!
end

View File

@ -15,7 +15,7 @@ class ExecutionEnvironmentsController < ApplicationController
private :authorize!
def index
@execution_environments = ExecutionEnvironment.all.includes(:user).order(:name).paginate(page: params[:page], per_page: per_page_param)
@execution_environments = ExecutionEnvironment.includes(:user).order(:name).paginate(page: params[:page], per_page: per_page_param)
authorize!
end

View File

@ -434,7 +434,7 @@ class ExercisesController < ApplicationController
private :not_authorized_for_exercise
def set_execution_environments
@execution_environments = ExecutionEnvironment.all.order(:name)
@execution_environments = ExecutionEnvironment.order(:name)
end
private :set_execution_environments
@ -456,7 +456,7 @@ class ExercisesController < ApplicationController
private :set_external_user_and_authorize
def set_file_types
@file_types = FileType.all.order(:name)
@file_types = FileType.order(:name)
end
private :set_file_types

View File

@ -19,7 +19,7 @@ class FileTemplatesController < ApplicationController
# GET /file_templates
# GET /file_templates.json
def index
@file_templates = FileTemplate.all.order(:file_type_id).paginate(page: params[:page], per_page: per_page_param)
@file_templates = FileTemplate.order(:file_type_id).paginate(page: params[:page], per_page: per_page_param)
authorize!
end

View File

@ -12,7 +12,7 @@ class FileTypesController < ApplicationController
private :authorize!
def index
@file_types = FileType.all.includes(:user).order(:name).paginate(page: params[:page], per_page: per_page_param)
@file_types = FileType.includes(:user).order(:name).paginate(page: params[:page], per_page: per_page_param)
authorize!
end

View File

@ -150,7 +150,7 @@ class InternalUsersController < ApplicationController
@user ||= InternalUser.new # Only needed for the `create` action
checked_study_group_memberships = @user.study_group_memberships
checked_study_groups = checked_study_group_memberships.collect(&:study_group).sort.to_set
unchecked_study_groups = StudyGroup.all.order(name: :asc).to_set.subtract checked_study_groups
unchecked_study_groups = StudyGroup.order(name: :asc).to_set.subtract checked_study_groups
@study_group_memberships = checked_study_group_memberships + unchecked_study_groups.collect do |study_group|
StudyGroupMembership.new(user: @user, study_group:)
end

View File

@ -377,7 +377,7 @@ class SubmissionsController < ApplicationController
#
# Reloading the ErrorTemplate is necessary to allow preloading the ErrorTemplateAttributes.
# However, this results in less (and faster) SQL queries than performing manual lookups.
ErrorTemplate.where(id: matching_error_templates).joins(:error_template_attributes).includes(:error_template_attributes).each do |template|
ErrorTemplate.where(id: matching_error_templates).joins(:error_template_attributes).includes(:error_template_attributes).find_each do |template|
results << StructuredError.create_from_template(template, @testrun[:output], @submission)
end
end

View File

@ -56,7 +56,7 @@ class TipsController < ApplicationController
end
def set_file_types
@file_types = FileType.all.order(:name)
@file_types = FileType.order(:name)
end
private :set_file_types
end

View File

@ -20,6 +20,6 @@ class Testrun < ApplicationRecord
validates :status, presence: true
def log
testrun_messages.output.select(:log).map(&:log).join.presence
testrun_messages.output.pluck(:log).join.presence
end
end

View File

@ -6,7 +6,7 @@ class AddHashedContentToFiles < ActiveRecord::Migration[4.2]
reversible do |direction|
direction.up do
CodeOcean::File.unscope(:order).all.each(&:save)
CodeOcean::File.unscope(:order).find_each(&:save)
end
end
end

View File

@ -4,7 +4,7 @@ class AddCauseToTestruns < ActiveRecord::Migration[4.2]
def up
add_column :testruns, :cause, :string
Testrun.reset_column_information
Testrun.all.each do |testrun|
Testrun.find_each do |testrun|
if testrun.submission.nil?
say_with_time "#{testrun.id} has no submission"
else

View File

@ -4,7 +4,7 @@ class CreateExerciseCollectionItems < ActiveRecord::Migration[4.2]
def up
rename_table :exercise_collections_exercises, :exercise_collection_items
add_column :exercise_collection_items, :position, :integer, default: 0, null: false
add_column :exercise_collection_items, :id, :primary_key
add_column :exercise_collection_items, :id, :primary_key # rubocop:disable Rails/DangerousColumnNames
end
def down

View File

@ -24,7 +24,7 @@ class DropErrors < ActiveRecord::Migration[5.2]
submissions_controller = SubmissionsController.new
# Iterate only over those Errors containing a message and submission_id
CodeOcean::Error.where.not(message: [nil, '']).where.not(submission_id: [nil, '']).each do |error|
CodeOcean::Error.where.not(message: [nil, '']).where.not(submission_id: [nil, '']).find_each do |error|
raw_output = error.message
submission = Submission.find_by(id: error.submission_id)

View File

@ -7,7 +7,7 @@ class AddNormalizedScoreAndSubmissionToUserExerciseFeedback < ActiveRecord::Migr
# Disable automatic timestamp modification
ActiveRecord::Base.record_timestamps = false
UserExerciseFeedback.all.find_each do |uef|
UserExerciseFeedback.find_each do |uef|
latest_submission = Submission
.where(user_id: uef.user_id, user_type: uef.user_type, exercise_id: uef.exercise_id)
.where('created_at < ?', uef.updated_at)

View File

@ -6,7 +6,7 @@ class ChangeTypeOfExposedPortsInExecutionEnvironment < ActiveRecord::Migration[6
rename_column :execution_environments, :exposed_ports, :exposed_ports_migration
add_column :execution_environments, :exposed_ports, :integer, array: true, default: [], nil: true
ExecutionEnvironment.all.each do |execution_environment|
ExecutionEnvironment.find_each do |execution_environment|
next if execution_environment.exposed_ports_migration.nil?
cleaned = execution_environment.exposed_ports_migration.scan(/\d+/)
@ -21,7 +21,7 @@ class ChangeTypeOfExposedPortsInExecutionEnvironment < ActiveRecord::Migration[6
rename_column :execution_environments, :exposed_ports, :exposed_ports_migration
add_column :execution_environments, :exposed_ports, :string
ExecutionEnvironment.all.each do |execution_environment|
ExecutionEnvironment.find_each do |execution_environment|
next if execution_environment.exposed_ports_migration.empty?
list = execution_environment.exposed_ports_migration

View File

@ -6,13 +6,13 @@ class UnifyLtiParameters < ActiveRecord::Migration[7.0]
dir.up do
# We cannot add a foreign key to a table that has rows that violate the constraint.
LtiParameter.where(external_users_id: nil)
.or(LtiParameter.where.not(external_users_id: ExternalUser.all.select(:id)))
.or(LtiParameter.where.not(external_users_id: ExternalUser.select(:id)))
.or(LtiParameter.where(exercises_id: nil))
.or(LtiParameter.where.not(exercises_id: Exercise.all.select(:id)))
.or(LtiParameter.where.not(exercises_id: Exercise.select(:id)))
.delete_all
# For each user/exercise pair, keep the most recent LtiParameter.
LtiParameter.all.group(:external_users_id, :exercises_id).having('count(*) > 1').count.each do |ids, count|
LtiParameter.group(:external_users_id, :exercises_id).having('count(*) > 1').count.each do |ids, count|
LtiParameter.where(external_users_id: ids.first, exercises_id: ids.second).order(updated_at: :asc).limit(count - 1).delete_all
end
change_column :lti_parameters, :id, :bigint

View File

@ -4,7 +4,7 @@ class AddForeignKeysToAnomalyNotifications < ActiveRecord::Migration[7.0]
def change
up_only do
# We cannot add a foreign key to a table that has rows that violate the constraint.
AnomalyNotification.where.not(exercise_id: Exercise.all.select(:id)).delete_all
AnomalyNotification.where.not(exercise_id: Exercise.select(:id)).delete_all
end
change_column_null :anomaly_notifications, :contributor_id, false

View File

@ -2,7 +2,7 @@
class ConvertReasonToJsonInAnomalyNotifications < ActiveRecord::Migration[7.0]
def up
AnomalyNotification.where("reason LIKE '%value:%'").each do |anomaly_notification|
AnomalyNotification.where("reason LIKE '%value:%'").find_each do |anomaly_notification|
reason = anomaly_notification.reason
reason = reason.gsub('value:', '"value":')
reason = reason.gsub(/"(\d+\.\d+)"/) {|_| Regexp.last_match(1) }

View File

@ -6,7 +6,7 @@ namespace :export_exercises do
codeharbor_link = CodeharborLink.find(args.codeharbor_link_id)
successful_exports = []
failed_exports = []
Exercise.where(public: true).each do |exercise|
Exercise.where(public: true).find_each do |exercise|
puts "Exporting exercise ##{exercise.id}"
error = ExerciseService::PushExternal.call(
zip: ProformaService::ExportTask.call(exercise:),

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe 'Editor', js: true do
describe 'Editor', :js do
let(:exercise) { create(:audio_video, description: Forgery(:lorem_ipsum).sentence) }
let(:scoring_response) do
[{

View File

@ -2,7 +2,7 @@
require 'rails_helper'
describe 'ExternalUserStatistics', js: true do
describe 'ExternalUserStatistics', :js do
let(:learner) { create(:external_user) }
let(:exercise) { create(:dummy, user:) }
let(:study_group) { create(:study_group) }