Fix rubocop offenses - Requires Ruby 3.1+

This commit is contained in:
Sebastian Serth
2022-11-25 10:53:14 +01:00
parent bdf474e684
commit 574e99eddd
93 changed files with 315 additions and 315 deletions

View File

@ -115,16 +115,16 @@ class ApplicationController < ActionController::Base
redirect_back fallback_location: :root, allow_other_host: false, alert: message
end
end
format.json { render json: {error: message}, status: status }
format.json { render json: {error: message}, status: }
end
end
private :render_error
def switch_locale(&action)
def switch_locale(&)
session[:locale] = sanitize_locale(params[:custom_locale] || params[:locale] || session[:locale])
locale = session[:locale] || I18n.default_locale
Sentry.set_extras(locale: locale)
I18n.with_locale(locale, &action)
Sentry.set_extras(locale:)
I18n.with_locale(locale, &)
end
private :switch_locale

View File

@ -60,7 +60,7 @@ module CodeOcean
yield if block_given?
path = options[:path].try(:call) || @object
respond_with_valid_object(format, notice: t('shared.object_created', model: @object.class.model_name.human),
path: path, status: :created)
path:, status: :created)
else
filename = "#{@object.path || ''}/#{@object.name || ''}#{@object.file_type.try(:file_extension) || ''}"
format.html do

View File

@ -11,7 +11,7 @@ module CommonBehavior
notice = result if result.present?
end
path = options[:path].try(:call) || @object
respond_with_valid_object(format, notice: notice, path: path, status: :created)
respond_with_valid_object(format, notice:, path:, status: :created)
else
respond_with_invalid_object(format, template: :new)
end
@ -51,7 +51,7 @@ module CommonBehavior
notice = result if result.present?
end
path = options[:path] || @object
respond_with_valid_object(format, notice: notice, path: path, status: :ok)
respond_with_valid_object(format, notice:, path:, status: :ok)
else
respond_with_invalid_object(format, template: :edit)
end

View File

@ -16,14 +16,14 @@ module FileConversion
path = File.dirname(file['name']).sub(%r{^(?>\./|\.)}, '').presence
file_type = all_file_types.detect {|ft| ft.file_extension == extension } || FileType.new(file_extension: extension)
CodeOcean::File.new(
name: name,
path: path,
name:,
path:,
size: file['size'],
owner: file['owner'],
group: file['group'],
permissions: file['permissions'],
updated_at: file['modificationTime'],
file_type: file_type
file_type:
)
end
[augment_files_for_download(files), directories]

View File

@ -124,7 +124,7 @@ module RedirectBehavior
session: session.to_hash,
submission: @submission.inspect,
params: params.as_json,
current_user: current_user,
current_user:,
lti_exercise_id: session[:lti_exercise_id],
lti_parameters_id: session[:lti_parameters_id]
)

View File

@ -115,8 +115,8 @@ class ExecutionEnvironmentsController < ApplicationController
end
render locals: {
working_time_statistics: working_time_statistics,
user_statistics: user_statistics,
working_time_statistics:,
user_statistics:,
}
end
@ -132,7 +132,7 @@ class ExecutionEnvironmentsController < ApplicationController
params[:execution_environment]
.permit(:docker_image, :editor_mode, :file_extension, :file_type_id, :help, :indent_size, :memory_limit, :cpu_limit, :name,
:network_enabled, :privileged_execution, :permitted_execution_time, :pool_size, :run_command, :test_command, :testing_framework)
.merge(user_id: current_user.id, user_type: current_user.class.name, exposed_ports: exposed_ports)
.merge(user_id: current_user.id, user_type: current_user.class.name, exposed_ports:)
end
end
private :execution_environment_params

View File

@ -128,15 +128,15 @@ class ExercisesController < ApplicationController
status: 'success',
message: t('exercises.export_codeharbor.successfully_exported', id: @exercise.id, title: @exercise.title),
actions: render_to_string(partial: 'export_actions',
locals: {exercise: @exercise, exported: true, error: error}),
locals: {exercise: @exercise, exported: true, error:}),
}
@exercise.save
else
render json: {
status: 'fail',
message: t('exercises.export_codeharbor.export_failed', id: @exercise.id, title: @exercise.title, error: error),
message: t('exercises.export_codeharbor.export_failed', id: @exercise.id, title: @exercise.title, error:),
actions: render_to_string(partial: 'export_actions',
locals: {exercise: @exercise, exported: true, error: error}),
locals: {exercise: @exercise, exported: true, error:}),
}
end
end
@ -146,7 +146,7 @@ class ExercisesController < ApplicationController
return render json: {}, status: :unauthorized if user.nil?
uuid = params[:uuid]
exercise = Exercise.find_by(uuid: uuid)
exercise = Exercise.find_by(uuid:)
return render json: {uuid_found: false} if exercise.nil?
return render json: {uuid_found: true, update_right: false} unless ExercisePolicy.new(user, exercise).update?
@ -163,7 +163,7 @@ class ExercisesController < ApplicationController
return render json: {}, status: :unauthorized if user.nil?
ActiveRecord::Base.transaction do
exercise = ::ProformaService::Import.call(zip: tempfile, user: user)
exercise = ::ProformaService::Import.call(zip: tempfile, user:)
exercise.save!
render json: {}, status: :created
end
@ -185,7 +185,7 @@ class ExercisesController < ApplicationController
private :user_from_api_key
def user_by_codeharbor_token(api_key)
link = CodeharborLink.find_by(api_key: api_key)
link = CodeharborLink.find_by(api_key:)
link&.user
end
@ -394,8 +394,8 @@ class ExercisesController < ApplicationController
def working_times
working_time_accumulated = @exercise.accumulated_working_time_for_only(current_user)
working_time_75_percentile = @exercise.get_quantiles([0.75]).first
render(json: {working_time_75_percentile: working_time_75_percentile,
working_time_accumulated: working_time_accumulated})
render(json: {working_time_75_percentile:,
working_time_accumulated:})
end
def intervention
@ -404,7 +404,7 @@ class ExercisesController < ApplicationController
render(json: {success: 'false', error: "undefined intervention #{params[:intervention_type]}"})
else
uei = UserExerciseIntervention.new(
user: current_user, exercise: @exercise, intervention: intervention,
user: current_user, exercise: @exercise, intervention:,
accumulated_worktime_s: @exercise.accumulated_working_time_for_only(current_user)
)
uei.save
@ -483,7 +483,7 @@ class ExercisesController < ApplicationController
checked_tags = checked_exercise_tags.collect(&:tag).to_set
unchecked_tags = Tag.all.to_set.subtract checked_tags
@exercise_tags = checked_exercise_tags + unchecked_tags.collect do |tag|
ExerciseTag.new(exercise: @exercise, tag: tag)
ExerciseTag.new(exercise: @exercise, tag:)
end
end
@ -522,7 +522,7 @@ class ExercisesController < ApplicationController
end
render locals: {
user_statistics: user_statistics,
user_statistics:,
}
end

View File

@ -72,7 +72,7 @@ class ExternalUsersController < ApplicationController
end
render locals: {
statistics: statistics,
statistics:,
}
end

View File

@ -41,7 +41,7 @@ class FileTypesController < ApplicationController
end
def set_editor_modes
@editor_modes = Dir.glob('vendor/assets/javascripts/ace/mode-*.js').sort.map do |filename|
@editor_modes = Dir.glob('vendor/assets/javascripts/ace/mode-*.js').map do |filename|
name = filename.gsub(%r{\w+/|mode-|.js$}, '')
[name, "ace/mode/#{name}"]
end

View File

@ -28,7 +28,7 @@ class FlowrController < ApplicationController
# once the programming language model becomes available, the language name can be added to the query to
# produce more relevant results
query = attributes.map(&:value).join(' ')
{submission: submission, error: error, attributes: attributes, query: query}
{submission:, error:, attributes:, query:}
end
# Always return JSON

View File

@ -151,7 +151,7 @@ class InternalUsersController < ApplicationController
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
@study_group_memberships = checked_study_group_memberships + unchecked_study_groups.collect do |study_group|
StudyGroupMembership.new(user: @user, study_group: study_group)
StudyGroupMembership.new(user: @user, study_group:)
end
end

View File

@ -26,14 +26,14 @@ class LiveStreamsController < ApplicationController
runner = Runner.for(current_user, @execution_environment)
fallback_location = shell_execution_environment_path(@execution_environment)
privileged = params[:sudo] || @execution_environment.privileged_execution?
send_runner_file(runner, desired_file, fallback_location, privileged: privileged)
send_runner_file(runner, desired_file, fallback_location, privileged:)
end
private
def send_runner_file(runner, desired_file, redirect_fallback = root_path, privileged: false)
filename = File.basename(desired_file)
send_stream(filename: filename, type: 'application/octet-stream', disposition: 'attachment') do |stream|
send_stream(filename:, type: 'application/octet-stream', disposition: 'attachment') do |stream|
runner.download_file desired_file, privileged_execution: privileged do |chunk, overall_size, _content_type|
unless response.committed?
# Disable Rack::ETag, which would otherwise cause the response to be cached

View File

@ -15,7 +15,7 @@ class RemoteEvaluationController < ApplicationController
else
201
end
render json: result, status: status
render json: result, status:
end
# POST /submit
@ -29,7 +29,7 @@ class RemoteEvaluationController < ApplicationController
status = result[:status]
end
render json: result, status: status
render json: result, status:
end
def try_lti
@ -62,7 +62,7 @@ class RemoteEvaluationController < ApplicationController
def create_and_score_submission(cause)
validation_token = remote_evaluation_params[:validation_token]
if (remote_evaluation_mapping = RemoteEvaluationMapping.find_by(validation_token: validation_token))
if (remote_evaluation_mapping = RemoteEvaluationMapping.find_by(validation_token:))
@submission = Submission.create(build_submission_params(cause, remote_evaluation_mapping))
@submission.calculate_score
else

View File

@ -146,7 +146,7 @@ class SubmissionsController < ApplicationController
end
else
Rails.logger.info("Unknown command from client: #{event[:cmd]}")
Sentry.set_extras(event: event)
Sentry.set_extras(event:)
Sentry.capture_message("Unknown command from client: #{event[:cmd]}")
end
rescue JSON::ParserError => e
@ -183,19 +183,19 @@ class SubmissionsController < ApplicationController
exit_statement =
if @testrun[:output].empty? && exit_code.zero?
@testrun[:status] = :ok
t('exercises.implement.no_output_exit_successful', timestamp: l(Time.zone.now, format: :short), exit_code: exit_code)
t('exercises.implement.no_output_exit_successful', timestamp: l(Time.zone.now, format: :short), exit_code:)
elsif @testrun[:output].empty?
@testrun[:status] = :failed
t('exercises.implement.no_output_exit_failure', timestamp: l(Time.zone.now, format: :short), exit_code: exit_code)
t('exercises.implement.no_output_exit_failure', timestamp: l(Time.zone.now, format: :short), exit_code:)
elsif exit_code.zero?
@testrun[:status] = :ok
"\n#{t('exercises.implement.exit_successful', timestamp: l(Time.zone.now, format: :short), exit_code: exit_code)}"
"\n#{t('exercises.implement.exit_successful', timestamp: l(Time.zone.now, format: :short), exit_code:)}"
else
@testrun[:status] = :failed
"\n#{t('exercises.implement.exit_failure', timestamp: l(Time.zone.now, format: :short), exit_code: exit_code)}"
"\n#{t('exercises.implement.exit_failure', timestamp: l(Time.zone.now, format: :short), exit_code:)}"
end
stream = @testrun[:status] == :ok ? :stdout : :stderr
send_and_store client_socket, {cmd: :write, stream: stream, data: "#{exit_statement}\n"}
send_and_store client_socket, {cmd: :write, stream:, data: "#{exit_statement}\n"}
if exit_code == 137
send_and_store client_socket, {cmd: :status, status: :out_of_memory}
@testrun[:status] = :out_of_memory
@ -307,8 +307,8 @@ class SubmissionsController < ApplicationController
exercise_id = @submission.exercise_id
remote_evaluation_mapping = RemoteEvaluationMapping.create(
user: user,
exercise_id: exercise_id,
user:,
exercise_id:,
study_group_id: session[:study_group_id]
)
@ -370,7 +370,7 @@ class SubmissionsController < ApplicationController
testrun = Testrun.create!(
file: @file,
passed: @testrun[:passed],
cause: cause,
cause:,
submission: @submission,
exit_code: @testrun[:exit_code], # might be nil, e.g., when the run did not finish
status: @testrun[:status] || :failed,
@ -379,7 +379,7 @@ class SubmissionsController < ApplicationController
waiting_for_container_time: @testrun[:waiting_for_container_time]
)
TestrunMessage.create_for(testrun, @testrun[:messages])
TestrunExecutionEnvironment.create(testrun: testrun, execution_environment: @submission.used_execution_environment)
TestrunExecutionEnvironment.create(testrun:, execution_environment: @submission.used_execution_environment)
end
def send_hints(tubesock, errors)
@ -430,10 +430,10 @@ class SubmissionsController < ApplicationController
parsed[:stream] = parsed[:stream].to_sym if parsed.key? :stream
parsed
else
{cmd: :write, stream: stream, data: data}
{cmd: :write, stream:, data:}
end
rescue JSON::ParserError
{cmd: :write, stream: stream, data: data}
{cmd: :write, stream:, data:}
end
def augment_files_for_download(files)

View File

@ -58,7 +58,7 @@ class SubscriptionsController < ApplicationController
study_group_id = current_user.try(:current_study_group_id)
if params[:subscription].present?
params[:subscription].permit(:request_for_comment_id, :subscription_type).merge(user_id: current_user_id,
user_type: current_user_class_name, study_group_id: study_group_id, deleted: false)
user_type: current_user_class_name, study_group_id:, deleted: false)
end
end
private :subscription_params

View File

@ -82,7 +82,7 @@ class UserExerciseFeedbacksController < ApplicationController
else
implement_exercise_path(@exercise)
end
update_and_respond(object: @uef, params: uef_params, path: path)
update_and_respond(object: @uef, params: uef_params, path:)
else
flash.now[:danger] = t('shared.message_failure')
redirect_back fallback_location: user_exercise_feedback_path(@uef)
@ -126,15 +126,15 @@ class UserExerciseFeedbacksController < ApplicationController
user_id = current_user.id
user_type = current_user.class.name
latest_submission = Submission
.where(user_id: user_id, user_type: user_type, exercise_id: exercise_id)
.where(user_id:, user_type:, exercise_id:)
.order(created_at: :desc).final.first
authorize(latest_submission, :show?)
params[:user_exercise_feedback]
.permit(:feedback_text, :difficulty, :exercise_id, :user_estimated_worktime)
.merge(user_id: user_id,
user_type: user_type,
.merge(user_id:,
user_type:,
submission: latest_submission,
normalized_score: latest_submission&.normalized_score)
end

View File

@ -8,7 +8,7 @@ module ActionCableHelper
ActionCable.server.broadcast(
"la_exercises_#{exercise_id}_channel_study_group_#{submission.study_group_id}",
type: :rfc,
id: id,
id:,
html: ApplicationController.render(partial: 'request_for_comments/list_entry',
locals: {request_for_comment: self})
)

View File

@ -53,9 +53,9 @@ module ApplicationHelper
ActionController::Base.helpers.sanitize Kramdown::Document.new(markdown).to_html
end
def row(options = {}, &block)
def row(options = {}, &)
tag.div(class: 'attribute-row row') do
label_column(options[:label]) + value_column(options[:value], &block)
label_column(options[:label]) + value_column(options[:value], &)
end
end

View File

@ -11,7 +11,7 @@ module AuthenticatedUrlHelper
COOKIE_EXPIRATION = 30.seconds
def sign(url, object)
payload = {object_id: object.id, object_type: object.class.name, url: url, exp: TOKEN_EXPIRATION.from_now.to_i}
payload = {object_id: object.id, object_type: object.class.name, url:, exp: TOKEN_EXPIRATION.from_now.to_i}
token = JWT.encode payload, TOKEN_SECRET, TOKEN_ALGORITHM
add_query_parameters(url, {TOKEN_PARAM => token})
@ -58,7 +58,7 @@ module AuthenticatedUrlHelper
def prepare_short_living_cookie(value)
{
value: value,
value:,
expires: COOKIE_EXPIRATION.from_now,
httponly: true,
same_site: :strict,

View File

@ -9,9 +9,9 @@ class AuthenticationToken < ApplicationRecord
def self.generate!(user, study_group)
create!(
shared_secret: SecureRandom.hex(32),
user: user,
user:,
expire_at: 7.days.from_now,
study_group: study_group
study_group:
)
end
end

View File

@ -40,7 +40,7 @@ module CodeOcean
scope :visible, -> { where(hidden: false) }
ROLES.each do |role|
scope :"#{role}s", -> { where(role: role) }
scope :"#{role}s", -> { where(role:) }
end
scope :teacher_defined_assessments, -> { where(role: %w[teacher_defined_test teacher_defined_linter]) }

View File

@ -48,7 +48,7 @@ class ExecutionEnvironment < ApplicationRecord
def to_json(*_args)
{
id: id,
id:,
image: docker_image,
prewarmingPoolSize: pool_size,
cpuLimit: cpu_limit,

View File

@ -79,7 +79,7 @@ class Exercise < ApplicationRecord
end
def time_maximum_score(user)
submissions.where(user: user).where("cause IN ('submit','assess')").where.not(score: nil).order('score DESC, created_at ASC').first.created_at
submissions.where(user:).where("cause IN ('submit','assess')").where.not(score: nil).order('score DESC, created_at ASC').first.created_at
rescue StandardError
Time.zone.at(0)
end
@ -251,7 +251,7 @@ class Exercise < ApplicationRecord
end
end
{user_progress: user_progress, additional_user_data: additional_user_data}
{user_progress:, additional_user_data:}
end
def get_quantiles(quantiles)
@ -495,7 +495,7 @@ class Exercise < ApplicationRecord
description = task_node.xpath('p:description/text()')[0].content
self.attributes = {
title: task_node.xpath('p:meta-data/p:title/text()')[0].content,
description: description,
description:,
instructions: description,
}
task_node.xpath('p:files/p:file').all? do |file|
@ -508,7 +508,7 @@ class Exercise < ApplicationRecord
content: file.xpath('text()').first.content,
read_only: false,
hidden: file_class == 'internal',
role: role,
role:,
feedback_message: role == 'teacher_defined_test' ? feedback_message_nodes.first.content : nil,
file_type: FileType.find_by(
file_extension: ".#{file_name_split.second}"
@ -527,7 +527,7 @@ class Exercise < ApplicationRecord
if user
# FIXME: where(user: user) will not work here!
begin
submissions.where(user: user).where("cause IN ('submit','assess')").where.not(score: nil).order('score DESC').first.score || 0
submissions.where(user:).where("cause IN ('submit','assess')").where.not(score: nil).order('score DESC').first.score || 0
rescue StandardError
0
end

View File

@ -14,7 +14,7 @@ class ExerciseTip < ApplicationRecord
def tip_chain?
# Ensure each referenced parent exercise tip is set for this exercise
unless ExerciseTip.exists?(
exercise: exercise, id: parent_exercise_tip
exercise:, id: parent_exercise_tip
)
errors.add :parent_exercise_tip,
I18n.t('activerecord.errors.messages.together',

View File

@ -10,7 +10,7 @@ class Intervention < ApplicationRecord
def self.create_default_interventions
%w[BreakIntervention QuestionIntervention].each do |name|
Intervention.find_or_create_by(name: name)
Intervention.find_or_create_by(name:)
end
end
end

View File

@ -19,12 +19,12 @@ class LinterCheckRun < ApplicationRecord
result: linter_result[:result],
line: linter_result[:line],
scope: linter_result[:scope],
testrun: testrun,
file: file
testrun:,
file:
)
rescue ActiveRecord::RecordInvalid
# Something bad happened. Probably, the RegEx in lib/py_lint_adapter.rb didn't work.
Sentry.set_extras(testrun: testrun.inspect, linter_result: linter_result)
Sentry.set_extras(testrun: testrun.inspect, linter_result:)
end
end
end

View File

@ -42,7 +42,7 @@ class ProxyExercise < ApplicationRecord
end
def get_matching_exercise(user)
assigned_user_proxy_exercise = user_proxy_exercise_exercises.find_by(user: user)
assigned_user_proxy_exercise = user_proxy_exercise_exercises.find_by(user:)
if assigned_user_proxy_exercise
Rails.logger.debug { "retrieved assigned exercise for user #{user.id}: Exercise #{assigned_user_proxy_exercise.exercise}" }
assigned_user_proxy_exercise.exercise
@ -57,7 +57,7 @@ class ProxyExercise < ApplicationRecord
@reason[:error] = "#{$ERROR_INFO}:\n\t#{e.backtrace.join("\n\t")}"
exercises.where('expected_difficulty > 1').sample # difficulty should be > 1 to prevent dummy exercise from being chosen.
end
user.user_proxy_exercise_exercises << UserProxyExerciseExercise.create(user: user,
user.user_proxy_exercise_exercises << UserProxyExerciseExercise.create(user:,
exercise: matching_exercise, proxy_exercise: self, reason: @reason.to_json)
matching_exercise
end
@ -105,9 +105,9 @@ class ProxyExercise < ApplicationRecord
relative_knowledge_improvement[potex] = 0.0
Rails.logger.debug { "review potential exercise #{potex.id}" }
tags.each do |tag|
tag_ratio = potex.exercise_tags.find_by(tag: tag).factor.to_f / potex.exercise_tags.inject(0) do |sum, et|
sum + et.factor
end
tag_ratio = potex.exercise_tags.find_by(tag:).factor.to_f / potex.exercise_tags.inject(0) do |sum, et|
sum + et.factor
end
max_topic_knowledge_ratio = potex.expected_difficulty * tag_ratio
old_relative_loss_tag = topic_knowledge_user[tag] / topic_knowledge_max[tag]
new_relative_loss_tag = topic_knowledge_user[tag] / (topic_knowledge_max[tag] + max_topic_knowledge_ratio)

View File

@ -31,9 +31,9 @@ class Runner < ApplicationRecord
end
def self.for(user, execution_environment)
runner = find_by(user: user, execution_environment: execution_environment)
runner = find_by(user:, execution_environment:)
if runner.nil?
runner = Runner.create(user: user, execution_environment: execution_environment)
runner = Runner.create(user:, execution_environment:)
# The `strategy` is added through the before_validation hook `:request_id`.
raise Runner::Error::Unknown.new("Runner could not be saved: #{runner.errors.inspect}") unless runner.persisted?
else
@ -52,8 +52,8 @@ class Runner < ApplicationRecord
@strategy.copy_files(files)
end
def download_file(path, **options, &block)
@strategy.download_file(path, **options, &block)
def download_file(path, **options, &)
@strategy.download_file(path, **options, &)
end
def retrieve_files(raise_exception: true, **options)
@ -93,7 +93,7 @@ class Runner < ApplicationRecord
# initializing its Runner::Connection with the given event loop. The Runner::Connection class ensures that
# this event loop is stopped after the socket was closed.
event_loop = Runner::EventLoop.new
socket = @strategy.attach_to_execution(command, event_loop, starting_time, privileged_execution: privileged_execution, &block)
socket = @strategy.attach_to_execution(command, event_loop, starting_time, privileged_execution:, &block)
event_loop.wait
raise socket.error if socket.error.present?
rescue Runner::Error => e
@ -120,7 +120,7 @@ class Runner < ApplicationRecord
save
end
execution_time = attach_to_execution(command, privileged_execution: privileged_execution) do |socket, starting_time|
execution_time = attach_to_execution(command, privileged_execution:) do |socket, starting_time|
socket.on :stderr do |data|
output[:stderr] << data
output[:messages].push({cmd: :write, stream: :stderr, log: data, timestamp: Time.zone.now - starting_time})

View File

@ -7,7 +7,7 @@ class StructuredError < ApplicationRecord
has_many :structured_error_attributes
def self.create_from_template(template, message_buffer, submission)
instance = create(error_template: template, submission: submission)
instance = create(error_template: template, submission:)
template.error_template_attributes.each do |attribute|
StructuredErrorAttribute.create_from_template(attribute, instance, message_buffer)
end

View File

@ -10,7 +10,7 @@ class StructuredErrorAttribute < ApplicationRecord
if !result.nil? && result.captures.size.positive?
value = result.captures[0]
end
create(structured_error: structured_error, error_template_attribute: attribute, value: value,
create(structured_error:, error_template_attribute: attribute, value:,
match: !result.nil?)
end
end

View File

@ -88,7 +88,7 @@ class Submission < ApplicationRecord
end
def siblings
user.submissions.where(exercise_id: exercise_id)
user.submissions.where(exercise_id:)
end
def to_s
@ -129,7 +129,7 @@ class Submission < ApplicationRecord
end
def own_unsolved_rfc
RequestForComment.unsolved.find_by(exercise_id: exercise, user_id: user_id)
RequestForComment.unsolved.find_by(exercise_id: exercise, user_id:)
end
def unsolved_rfc
@ -162,11 +162,11 @@ class Submission < ApplicationRecord
# @raise [Runner::Error] if the code could not be run due to a failure with the runner.
# See the specific type and message for more details.
def run(file, &block)
def run(file, &)
run_command = command_for execution_environment.run_command, file.filepath
durations = {}
prepared_runner do |runner, waiting_duration|
durations[:execution_duration] = runner.attach_to_execution(run_command, &block)
durations[:execution_duration] = runner.attach_to_execution(run_command, &)
durations[:waiting_duration] = waiting_duration
rescue Runner::Error => e
e.waiting_duration = waiting_duration
@ -237,13 +237,13 @@ class Submission < ApplicationRecord
def command_substitutions(filename)
{
class_name: File.basename(filename, File.extname(filename)).upcase_first,
filename: filename,
filename:,
module_name: File.basename(filename, File.extname(filename)).underscore,
}
end
def score_file(output, file)
assessor = Assessor.new(execution_environment: execution_environment)
assessor = Assessor.new(execution_environment:)
assessment = assessor.assess(output)
passed = ((assessment[:passed] == assessment[:count]) and (assessment[:score]).positive?)
testrun_output = passed ? nil : "status: #{output[:status]}\n stdout: #{output[:stdout]}\n stderr: #{output[:stderr]}"
@ -256,8 +256,8 @@ class Submission < ApplicationRecord
testrun = Testrun.create(
submission: self,
cause: 'assess', # Required to differ run and assess for RfC show
file: file, # Test file that was executed
passed: passed,
file:, # Test file that was executed
passed:,
exit_code: output[:exit_code],
status: output[:status],
output: testrun_output.presence,
@ -265,7 +265,7 @@ class Submission < ApplicationRecord
waiting_for_container_time: output[:waiting_for_container_time]
)
TestrunMessage.create_for(testrun, output[:messages])
TestrunExecutionEnvironment.create(testrun: testrun, execution_environment: @used_execution_environment)
TestrunExecutionEnvironment.create(testrun:, execution_environment: @used_execution_environment)
filename = file.filepath
@ -278,7 +278,7 @@ class Submission < ApplicationRecord
end
output.merge!(assessment)
output.merge!(filename: filename, message: feedback_message(file, output), weight: file.weight)
output.merge!(filename:, message: feedback_message(file, output), weight: file.weight)
output.except!(:messages)
end
@ -308,7 +308,7 @@ class Submission < ApplicationRecord
update(score: score.to_d)
if normalized_score.to_d == BigDecimal('1.0')
Thread.new do
RequestForComment.where(exercise_id: exercise_id, user_id: user_id, user_type: user_type).find_each do |rfc|
RequestForComment.where(exercise_id:, user_id:, user_type:).find_each do |rfc|
rfc.full_score_reached = true
rfc.save
end

View File

@ -73,7 +73,7 @@ class User < ApplicationRecord
def to_sentry_context
{
id: id,
id:,
type: self.class.name,
username: displayname,
consumer: consumer.name,

View File

@ -17,7 +17,7 @@ class UserExerciseFeedback < ApplicationRecord
end
def anomaly_notification
AnomalyNotification.where({exercise_id: exercise.id, user_id: user_id, user_type: user_type})
AnomalyNotification.where({exercise_id: exercise.id, user_id:, user_type:})
.where('created_at < ?', created_at).order('created_at DESC').to_a.first
end
end

View File

@ -23,12 +23,12 @@ module ProformaService
title: @exercise.title,
description: @exercise.description,
internal_description: nil,
proglang: proglang,
proglang:,
files: task_files,
tests: tests,
uuid: uuid,
tests:,
uuid:,
language: DEFAULT_LANGUAGE,
model_solutions: model_solutions,
model_solutions:,
meta_data: {
CodeOcean: {
public: @exercise.public,

View File

@ -26,9 +26,9 @@ module ProformaService
allow_file_creation: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_file_creation)) || false,
allow_auto_completion: string_to_bool(@task.meta_data[:CodeOcean]&.dig(:allow_auto_completion)) || false,
expected_difficulty: @task.meta_data[:CodeOcean]&.dig(:expected_difficulty) || 1,
execution_environment_id: execution_environment_id,
execution_environment_id:,
files: files
files:
)
end

View File

@ -17,7 +17,7 @@ module ProformaService
exercise = base_exercise
exercise_files = exercise&.files&.to_a
exercise = ConvertTaskToExercise.call(task: @task, user: @user, exercise: exercise)
exercise = ConvertTaskToExercise.call(task: @task, user: @user, exercise:)
exercise_files&.each(&:destroy) # feels suboptimal
exercise

View File

@ -8,7 +8,7 @@ json.download_file_url download_file_submission_path(@submission, 'a.', format:
unless @embed_options[:disable_download]
json.render_url @submission.collect_files.select(&:visible) do |files|
host = ApplicationController::RENDER_HOST || request.host
url = render_submission_url(@submission, files.filepath, host: host)
url = render_submission_url(@submission, files.filepath, host:)
json.filepath files.filepath
json.url AuthenticatedUrlHelper.sign(url, @submission)