Fix Rubocop offenses

This commit is contained in:
Sebastian Serth
2023-06-11 20:46:45 +02:00
parent 5a10e04121
commit bcdc71021e
19 changed files with 39 additions and 39 deletions

View File

@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base
MEMBER_ACTIONS = %i[destroy edit show update].freeze MEMBER_ACTIONS = %i[destroy edit show update].freeze
RENDER_HOST = CodeOcean::Config.new(:code_ocean).read[:render_host] RENDER_HOST = CodeOcean::Config.new(:code_ocean).read[:render_host]
LEGAL_SETTINGS = CodeOcean::Config.new(:code_ocean).read[:legal] || {} LEGAL_SETTINGS = CodeOcean::Config.new(:code_ocean).read[:legal] || {}
MONITORING_USER_AGENT = Regexp.compile(/updown\.io/).freeze MONITORING_USER_AGENT = /updown\.io/
before_action :deny_access_from_render_host before_action :deny_access_from_render_host
after_action :verify_authorized, except: %i[welcome] after_action :verify_authorized, except: %i[welcome]

View File

@ -67,7 +67,7 @@ module ProformaService
zip_file.map(&:name) zip_file.map(&:name)
end end
filenames.select {|f| f[/\.xml$/] }.any? filenames.any? {|f| f[/\.xml$/] }
rescue Zip::Error rescue Zip::Error
raise Proforma::InvalidZip raise Proforma::InvalidZip
end end

View File

@ -4,17 +4,17 @@ class MigrateTestruns < ActiveRecord::Migration[6.1]
# We are not changing any tables but only backfilling data. # We are not changing any tables but only backfilling data.
disable_ddl_transaction! disable_ddl_transaction!
SPLIT_OUTPUT = Regexp.compile(/(?<meta>message: (?<message>.*)\n|status: (?<status>.*)\n)? stdout: (?<stdout>.*)\n stderr: ?(?<stderr>.*)/m) SPLIT_OUTPUT = /(?<meta>message: (?<message>.*)\n|status: (?<status>.*)\n)? stdout: (?<stdout>.*)\n stderr: ?(?<stderr>.*)/m
PYTHON_BYTE_OUTPUT = Regexp.compile(/^b'(?<raw_output>.*)'$/) PYTHON_BYTE_OUTPUT = /^b'(?<raw_output>.*)'$/
PYTHON_JSON_OUTPUT = Regexp.compile(/{"cmd":"write","stream":"(?<stream>.*)","data":"(?<data_output>.*)"}/) PYTHON_JSON_OUTPUT = /{"cmd":"write","stream":"(?<stream>.*)","data":"(?<data_output>.*)"}/
RUN_OUTPUT = Regexp.compile(%r{(?<prefix>timeout:)? ?(?>make run\r\n)?(?>python3 /usr/lib/[^\r\n]*\r\n|/usr/bin/python3[^\r\n]*\r\n|ruby [^\r\n]*\r\n)?(?<cleaned_output>[^ "\e][^\e]*?[^#\e])?(?<shell>\r\e.*?)?#?(?<suffix>exit|timeout)?\r?\Z}m) RUN_OUTPUT = %r{(?<prefix>timeout:)? ?(?>make run\r\n)?(?>python3 /usr/lib/[^\r\n]*\r\n|/usr/bin/python3[^\r\n]*\r\n|ruby [^\r\n]*\r\n)?(?<cleaned_output>[^ "\e][^\e]*?[^#\e])?(?<shell>\r\e.*?)?#?(?<suffix>exit|timeout)?\r?\Z}m
REAL_EXIT = Regexp.compile(/\A(?>(?<json>(?<json_output>{".*?)?(?>{"cmd":(?> |"write","stream":"stdout","data":)?"#?exit(?>\\[nr])?"})+(?<more_shell_output_after_json>.*))|(?<program_output>.*?)(?>#?exit\s*)+(?<more_shell_output_after_program>.*))\z/m) REAL_EXIT = /\A(?>(?<json>(?<json_output>{".*?)?(?>{"cmd":(?> |"write","stream":"stdout","data":)?"#?exit(?>\\[nr])?"})+(?<more_shell_output_after_json>.*))|(?<program_output>.*?)(?>#?exit\s*)+(?<more_shell_output_after_program>.*))\z/m
STDERR_WRITTEN = Regexp.compile(/^(?:(?<rb_error>\r*[^\n\r]*\.rb:\d+:.*)|(?<other_error>\r*[^\n\r]*\.java:\d+: error.*|\r*Exception in thread.*|\r*There was .*|\r*[^\n\r]*java\.lang\..*|\r*make: \*\*\* \[.*))\z/m) STDERR_WRITTEN = /^(?:(?<rb_error>\r*[^\n\r]*\.rb:\d+:.*)|(?<other_error>\r*[^\n\r]*\.java:\d+: error.*|\r*Exception in thread.*|\r*There was .*|\r*[^\n\r]*java\.lang\..*|\r*make: \*\*\* \[.*))\z/m
FIND_JSON = Regexp.compile(/{(?:(?:"(?:\\.|[^\\"])+?"\s*:\s*(?:"(?:\\.|[^\\"])*?"|-?\d++(?:\.\d++)?|\[.*?\]|{.*?}|null))+?\s*,?\s*)+}/) FIND_JSON = /{(?:(?:"(?:\\.|[^\\"])+?"\s*:\s*(?:"(?:\\.|[^\\"])*?"|-?\d++(?:\.\d++)?|\[.*?\]|{.*?}|null))+?\s*,?\s*)+}/
# We identify incomplete Unicode characters. Valid unicode characters are: # We identify incomplete Unicode characters. Valid unicode characters are:
# \uXXXX, \u{XXXXX}, \udYXX\udZXX with X = 0-9a-f, Y = 89ab, Z = cdef # \uXXXX, \u{XXXXX}, \udYXX\udZXX with X = 0-9a-f, Y = 89ab, Z = cdef
# Every incomplete prefix of a valid unicode character is identified # Every incomplete prefix of a valid unicode character is identified
REPLACE_INCOMPLETE_UNICODE = Regexp.compile(/(?:\\?\\u[\da-f]{0,3}|\\?\\ud[89ab][\da-f]{2}\\?(?:\\(?:u(?:d(?:[cdef][\da-f]?)?)?)?)?|\\?\\u\{[\da-f]{0,4})"}\z/) REPLACE_INCOMPLETE_UNICODE = /(?:\\?\\u[\da-f]{0,3}|\\?\\ud[89ab][\da-f]{2}\\?(?:\\(?:u(?:d(?:[cdef][\da-f]?)?)?)?)?|\\?\\u\{[\da-f]{0,4})"}\z/
# NOTE: `update_columns` won't run validations nor update the `updated_at` timestamp. # NOTE: `update_columns` won't run validations nor update the `updated_at` timestamp.
# This is what we want here, thus we disable Rubocop for this migration. # This is what we want here, thus we disable Rubocop for this migration.

View File

@ -6,7 +6,7 @@ class Runner::Connection::Buffer
# substring either in single or double quotes (e.g., within a JSON). Originally, each line break consists of `\r\n`. # substring either in single or double quotes (e.g., within a JSON). Originally, each line break consists of `\r\n`.
# We keep the `\r` at the end of the line (keeping "empty" lines) and replace it after buffering. # We keep the `\r` at the end of the line (keeping "empty" lines) and replace it after buffering.
# Inspired by https://stackoverflow.com/questions/13040585/split-string-by-spaces-properly-accounting-for-quotes-and-backslashes-ruby # Inspired by https://stackoverflow.com/questions/13040585/split-string-by-spaces-properly-accounting-for-quotes-and-backslashes-ruby
SPLIT_INDIVIDUAL_LINES = Regexp.compile(/(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|[^\n])+/) SPLIT_INDIVIDUAL_LINES = /(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|[^\n])+/
def initialize def initialize
@global_buffer = +'' @global_buffer = +''

View File

@ -6,15 +6,15 @@ module CodeOcean
FactoryBot.define do FactoryBot.define do
factory :file, class: 'CodeOcean::File' do factory :file, class: 'CodeOcean::File' do
content { '' } content { '' }
association :context, factory: :submission context factory: :submission
association :file_type, factory: :dot_rb file_type factory: :dot_rb
hidden { false } hidden { false }
name { SecureRandom.hex } name { SecureRandom.hex }
read_only { false } read_only { false }
role { 'main_file' } role { 'main_file' }
trait(:image) do trait(:image) do
association :file_type, factory: :dot_png file_type factory: :dot_png
name { 'poster' } name { 'poster' }
native_file { Rack::Test::UploadedFile.new(Rails.root.join('db/seeds/audio_video/poster.png'), 'image/png') } native_file { Rack::Test::UploadedFile.new(Rails.root.join('db/seeds/audio_video/poster.png'), 'image/png') }
end end
@ -22,8 +22,8 @@ module CodeOcean
factory :test_file, class: 'CodeOcean::File' do factory :test_file, class: 'CodeOcean::File' do
content { '' } content { '' }
association :context, factory: :dummy context factory: :dummy
association :file_type, factory: :dot_rb file_type factory: :dot_rb
hidden { true } hidden { true }
name { SecureRandom.hex } name { SecureRandom.hex }
read_only { true } read_only { true }

View File

@ -2,7 +2,7 @@
FactoryBot.define do FactoryBot.define do
factory :codeharbor_link do factory :codeharbor_link do
user { build(:teacher) } user factory: :teacher
push_url { 'https://push.url' } push_url { 'https://push.url' }
check_uuid_url { 'https://check-uuid.url' } check_uuid_url { 'https://check-uuid.url' }
sequence(:api_key) {|n| "api_key#{n}" } sequence(:api_key) {|n| "api_key#{n}" }

View File

@ -2,7 +2,7 @@
FactoryBot.define do FactoryBot.define do
factory :error_template do factory :error_template do
association :execution_environment, factory: :ruby execution_environment factory: :ruby
name { 'MyString' } name { 'MyString' }
signature { 'MyString' } signature { 'MyString' }
end end

View File

@ -2,7 +2,7 @@
FactoryBot.define do FactoryBot.define do
factory :external_user do factory :external_user do
association :consumer consumer
generated_email generated_email
external_id { SecureRandom.uuid } external_id { SecureRandom.uuid }
generated_user_name generated_user_name

View File

@ -3,7 +3,7 @@
FactoryBot.define do FactoryBot.define do
factory :admin, class: 'InternalUser' do factory :admin, class: 'InternalUser' do
activated_user activated_user
association :consumer consumer
email { 'admin@example.org' } email { 'admin@example.org' }
generated_user_name generated_user_name
password { 'admin' } password { 'admin' }
@ -17,7 +17,7 @@ FactoryBot.define do
factory :teacher, class: 'InternalUser' do factory :teacher, class: 'InternalUser' do
activated_user activated_user
association :consumer consumer
generated_email generated_email
generated_user_name generated_user_name
password { 'teacher' } password { 'teacher' }
@ -31,7 +31,7 @@ FactoryBot.define do
factory :learner, class: 'InternalUser' do factory :learner, class: 'InternalUser' do
activated_user activated_user
association :consumer consumer
generated_email generated_email
generated_user_name generated_user_name
password { 'learner' } password { 'learner' }

View File

@ -8,9 +8,9 @@ FactoryBot.define do
}.freeze }.freeze
factory :lti_parameter do factory :lti_parameter do
association :consumer consumer
association :exercise, factory: :math exercise factory: :math
association :external_user external_user
lti_parameters { lti_params } lti_parameters { lti_params }

View File

@ -2,10 +2,10 @@
FactoryBot.define do FactoryBot.define do
factory :rfc, class: 'RequestForComment' do factory :rfc, class: 'RequestForComment' do
association :user, factory: :external_user user factory: :external_user
association :exercise, factory: :math exercise factory: :math
submission { association :submission, exercise:, user: } submission { association :submission, exercise:, user: }
association :file file
sequence :question do |n| sequence :question do |n|
"test question #{n}" "test question #{n}"
end end

View File

@ -4,7 +4,7 @@
FactoryBot.define do FactoryBot.define do
factory :runner do factory :runner do
runner_id { SecureRandom.uuid } runner_id { SecureRandom.uuid }
association :execution_environment, factory: :ruby execution_environment factory: :ruby
association :user, factory: :external_user user factory: :external_user
end end
end end

View File

@ -3,7 +3,7 @@
FactoryBot.define do FactoryBot.define do
%i[admin external_user teacher].each do |factory_name| %i[admin external_user teacher].each do |factory_name|
trait :"created_by_#{factory_name}" do trait :"created_by_#{factory_name}" do
association :user, factory: factory_name user factory: factory_name
end end
end end

View File

@ -2,8 +2,8 @@
FactoryBot.define do FactoryBot.define do
factory :structured_error_attribute do factory :structured_error_attribute do
association :structured_error structured_error
association :error_template_attribute error_template_attribute
value { 'MyString' } value { 'MyString' }
end end
end end

View File

@ -2,7 +2,7 @@
FactoryBot.define do FactoryBot.define do
factory :structured_error do factory :structured_error do
association :error_template error_template
association :submission submission
end end
end end

View File

@ -2,7 +2,7 @@
FactoryBot.define do FactoryBot.define do
factory :study_group, class: 'StudyGroup' do factory :study_group, class: 'StudyGroup' do
association :consumer consumer
sequence :name do |n| sequence :name do |n|
"TestGroup#{n}" "TestGroup#{n}"
end end

View File

@ -4,7 +4,7 @@ FactoryBot.define do
factory :submission do factory :submission do
cause { 'save' } cause { 'save' }
created_by_external_user created_by_external_user
association :exercise, factory: :math exercise factory: :math
after(:create) do |submission| after(:create) do |submission|
submission.exercise.files.editable.visible.each do |file| submission.exercise.files.editable.visible.each do |file|

View File

@ -4,6 +4,6 @@ FactoryBot.define do
factory :user_exercise_feedback, class: 'UserExerciseFeedback' do factory :user_exercise_feedback, class: 'UserExerciseFeedback' do
created_by_external_user created_by_external_user
feedback_text { 'Most suitable exercise ever' } feedback_text { 'Most suitable exercise ever' }
association :exercise, factory: :math exercise factory: :math
end end
end end

View File

@ -184,7 +184,7 @@ describe RequestForCommentPolicy do
end end
it 'does not grant access to authors of another primary study groups' do it 'does not grant access to authors of another primary study groups' do
rfc_other_study_group.author.update(study_groups: [create(:study_group)]) rfc_other_study_group.author.update(study_groups: create_list(:study_group, 1))
expect(policy).not_to permit(rfc_other_study_group.author, rfc_other_study_group) expect(policy).not_to permit(rfc_other_study_group.author, rfc_other_study_group)
end end