diff --git a/Gemfile b/Gemfile index 70e8207f7b..38a8d51bb4 100644 --- a/Gemfile +++ b/Gemfile @@ -180,7 +180,7 @@ group :development do gem 'rubocop-capybara', '~> 2.21.0' gem 'rubocop-factory_bot', '~> 2.26' gem 'rubocop-minitest', '~> 0.35.1' - gem 'rubocop-rails', '~> 2.25.1' + gem 'rubocop-rails', '~> 2.26.0' # for opening letters gem 'letter_opener', '~> 1.10.0' diff --git a/Gemfile.lock b/Gemfile.lock index 7da5e13c8c..52557fac90 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -130,7 +130,7 @@ GEM regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) childprocess (5.0.0) - concurrent-ruby (1.3.3) + concurrent-ruby (1.3.4) connection_pool (2.4.1) counter_culture (3.7.0) activerecord (>= 4.2) @@ -284,7 +284,7 @@ GEM memory_profiler (1.0.2) mini_magick (4.13.2) mini_mime (1.1.5) - minitest (5.24.1) + minitest (5.25.1) minitest-ci (3.4.0) minitest (>= 5.0.6) minitest-utils (0.4.8) @@ -355,8 +355,8 @@ GEM validate_url webfinger (~> 2.0) orm_adapter (0.5.0) - parallel (1.25.1) - parser (3.3.4.0) + parallel (1.26.3) + parser (3.3.4.2) ast (~> 2.4.1) racc premailer (1.18.0) @@ -446,10 +446,10 @@ GEM responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) - rexml (3.3.3) + rexml (3.3.6) strscan rouge (4.3.0) - rubocop (1.65.0) + rubocop (1.65.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -460,7 +460,7 @@ GEM rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.31.3) + rubocop-ast (1.32.1) parser (>= 3.3.1.0) rubocop-capybara (2.21.0) rubocop (~> 1.41) @@ -469,10 +469,10 @@ GEM rubocop-minitest (0.35.1) rubocop (>= 1.61, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rails (2.25.1) + rubocop-rails (2.26.0) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.33.0, < 2.0) + rubocop (>= 1.52.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (1.13.0) ruby-saml (1.16.0) @@ -633,7 +633,7 @@ DEPENDENCIES rubocop-capybara (~> 2.21.0) rubocop-factory_bot (~> 2.26) rubocop-minitest (~> 0.35.1) - rubocop-rails (~> 2.25.1) + rubocop-rails (~> 2.26.0) ruby-saml (~> 1.16.0) rubyzip (~> 2.3.2) selenium-webdriver (~> 4.23.0) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9e11c7e15a..f8ee62a86e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -125,7 +125,7 @@ def user_not_authorized elsif current_user.nil? redirect_to sign_in_path else - flash[:alert] = I18n.t('errors.no_rights') + flash[:alert] = I18n.t('errors.no_rights') # rubocop:disable Rails/ActionControllerFlashBeforeRender if request.referer.present? && URI.parse(request.referer).host == request.host redirect_to(request.referer) else diff --git a/app/models/activity.rb b/app/models/activity.rb index 7c9ed803ed..27f27daa5c 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -42,8 +42,8 @@ class Activity < ApplicationRecord MEDIA_DIR = File.join(DESCRIPTION_DIR, 'media').freeze # We need to prefix, otherwise Rails can't generate the public? method - enum access: { public: 0, private: 1 }, _prefix: true - enum status: { ok: 0, not_valid: 1, removed: 2 } + enum :access, { public: 0, private: 1 }, prefix: true + enum :status, { ok: 0, not_valid: 1, removed: 2 } belongs_to :repository belongs_to :judge, optional: true diff --git a/app/models/activity_read_state.rb b/app/models/activity_read_state.rb index fd8b2a10b7..2ee09d67bf 100644 --- a/app/models/activity_read_state.rb +++ b/app/models/activity_read_state.rb @@ -31,7 +31,7 @@ class ActivityReadState < ApplicationRecord scope :by_activity_name, ->(name) { where(activity: Activity.by_name(name)) } scope :by_username, ->(name) { where(user: User.by_filter(name)) } scope :by_filter, lambda { |filter, skip_user:, skip_content_page:| - filter.split.map(&:strip).select(&:present?).map do |part| + filter.split.map(&:strip).compact_blank.map do |part| scopes = [] scopes << by_activity_name(part) unless skip_content_page scopes << by_username(part) unless skip_user diff --git a/app/models/annotation.rb b/app/models/annotation.rb index cdb0b33107..e0e9d45574 100644 --- a/app/models/annotation.rb +++ b/app/models/annotation.rb @@ -71,7 +71,7 @@ class Annotation < ApplicationRecord after_save :create_notification scope :by_filter, lambda { |filter, skip_user:, skip_exercise:| - filter.split.map(&:strip).select(&:present?).map do |part| + filter.split.map(&:strip).compact_blank.map do |part| scopes = [] scopes << by_exercise_name(part) unless skip_exercise scopes << by_username(part) unless skip_user diff --git a/app/models/announcement.rb b/app/models/announcement.rb index 2cb78c595f..3d3b180aaf 100644 --- a/app/models/announcement.rb +++ b/app/models/announcement.rb @@ -16,8 +16,8 @@ class Announcement < ApplicationRecord has_many :announcement_views, dependent: :destroy belongs_to :institution, optional: true - enum user_group: { everyone: 0, all_users: 1, students: 2, staff: 3, zeus: 4 } - enum style: { primary: 0, success: 1, danger: 2, warning: 3, info: 4 } + enum :user_group, { everyone: 0, all_users: 1, students: 2, staff: 3, zeus: 4 } + enum :style, { primary: 0, success: 1, danger: 2, warning: 3, info: 4 } validates :text_nl, presence: true validates :text_en, presence: true diff --git a/app/models/concerns/filterable.rb b/app/models/concerns/filterable.rb index 1890741021..907efbfe8d 100644 --- a/app/models/concerns/filterable.rb +++ b/app/models/concerns/filterable.rb @@ -3,6 +3,6 @@ module Filterable included do before_save :set_search - scope :by_filter, ->(filter) { filter.split.map(&:strip).select(&:present?).inject(self) { |query, part| query.where("#{table_name}.search LIKE ?", "%#{part}%") } } + scope :by_filter, ->(filter) { filter.split.map(&:strip).compact_blank.inject(self) { |query, part| query.where("#{table_name}.search LIKE ?", "%#{part}%") } } end end diff --git a/app/models/concerns/gitable.rb b/app/models/concerns/gitable.rb index 6b4ad587da..1d5726bccb 100644 --- a/app/models/concerns/gitable.rb +++ b/app/models/concerns/gitable.rb @@ -10,7 +10,7 @@ module Gitable included do before_create :fix_remote - enum clone_status: { queued: 1, running: 2, complete: 3, failed: 4 }, _prefix: :clone + enum :clone_status, { queued: 1, running: 2, complete: 3, failed: 4 }, prefix: :clone end def full_path diff --git a/app/models/course.rb b/app/models/course.rb index f6be23a577..60bc38e774 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -54,8 +54,8 @@ class Course < ApplicationRecord has_many :course_labels, dependent: :destroy - enum visibility: { visible_for_all: 0, visible_for_institution: 1, hidden: 2 } - enum registration: { open_for_all: 3, open_for_institutional_users: 0, open_for_institution: 1, closed: 2 } + enum :visibility, { visible_for_all: 0, visible_for_institution: 1, hidden: 2 } + enum :registration, { open_for_all: 3, open_for_institutional_users: 0, open_for_institution: 1, closed: 2 } # TODO: Remove and use activities? has_many :content_pages, diff --git a/app/models/course_membership.rb b/app/models/course_membership.rb index 4c4f06d547..b4c9063ab9 100644 --- a/app/models/course_membership.rb +++ b/app/models/course_membership.rb @@ -12,7 +12,7 @@ # class CourseMembership < ApplicationRecord - enum status: { pending: 0, course_admin: 1, student: 2, unsubscribed: 3 } + enum :status, { pending: 0, course_admin: 1, student: 2, unsubscribed: 3 } belongs_to :course belongs_to :user diff --git a/app/models/event.rb b/app/models/event.rb index 4d0480ad0f..e06dd8b847 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -11,7 +11,7 @@ # class Event < ApplicationRecord - enum event_type: { rejudge: 0, permission_change: 1, exercise_repository: 2, error: 3 } + enum :event_type, { rejudge: 0, permission_change: 1, exercise_repository: 2, error: 3 } belongs_to :user, optional: true validates :event_type, presence: true diff --git a/app/models/export.rb b/app/models/export.rb index d616e16079..4d35346ca0 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -16,7 +16,7 @@ class Export < ApplicationRecord belongs_to :user has_one_attached :archive - enum status: { started: 0, finished: 1, failed: 2 } + enum :status, { started: 0, finished: 1, failed: 2 } default_scope { order(id: :desc) } diff --git a/app/models/institution.rb b/app/models/institution.rb index 442e16ebc5..2c654dd574 100644 --- a/app/models/institution.rb +++ b/app/models/institution.rb @@ -19,7 +19,7 @@ class Institution < ApplicationRecord IGNORED_DOMAINS_FOR_SIMILARITY = %w[gmail.com hotmail.com outlook.com yahoo.com live.com msn.com aol.com icloud.com telenet.be gmail.be live.be outlook.be hotmail.be].freeze NEW_INSTITUTION_NAME = 'n/a'.freeze - enum category: { secondary: 0, higher: 1, other: 2 } + enum :category, { secondary: 0, higher: 1, other: 2 } has_many :users, dependent: :restrict_with_error has_many :providers, inverse_of: :institution, dependent: :restrict_with_error diff --git a/app/models/label.rb b/app/models/label.rb index 5d1fc943f9..2e49d53578 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -11,7 +11,7 @@ class Label < ApplicationRecord has_many :activity_labels, dependent: :restrict_with_error has_many :activities, through: :activity_labels - enum color: { red: 0, pink: 1, purple: 2, 'deep-purple': 3, indigo: 4, teal: 5, orange: 6, brown: 7, 'blue-gray': 8 } + enum :color, { red: 0, pink: 1, purple: 2, 'deep-purple': 3, indigo: 4, teal: 5, orange: 6, brown: 7, 'blue-gray': 8 } scope :by_name, ->(name) { where('name LIKE ?', "%#{name}%") } diff --git a/app/models/provider.rb b/app/models/provider.rb index f87bc51213..0ee5990973 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -20,7 +20,7 @@ # jwks_uri :string(255) # class Provider < ApplicationRecord - enum mode: { prefer: 0, redirect: 1, link: 2, secondary: 3 } + enum :mode, { prefer: 0, redirect: 1, link: 2, secondary: 3 } PROVIDERS = [Provider::GSuite, Provider::Lti, Provider::Office365, Provider::Oidc, Provider::Saml, Provider::Smartschool, Provider::Surf, Provider::Elixir].freeze diff --git a/app/models/question.rb b/app/models/question.rb index 39c04546c3..b4b806266d 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -27,7 +27,7 @@ class Question < Annotation after_save :schedule_reset_in_progress, if: :saved_change_to_question_state? after_commit :clear_transition - enum question_state: { unanswered: 0, in_progress: 1, answered: 2 } + enum :question_state, { unanswered: 0, in_progress: 1, answered: 2 } alias_attribute :question_text, :annotation_text # Used to authorize the transitions diff --git a/app/models/series.rb b/app/models/series.rb index 653cf6509f..baac7adb6a 100644 --- a/app/models/series.rb +++ b/app/models/series.rb @@ -30,7 +30,7 @@ class Series < ApplicationRecord USER_STARTED_CACHE_STRING = '/series/%s/user/%s/started/%s'.freeze USER_WRONG_CACHE_STRING = '/series/%s/user/%s/wrong/%s'.freeze - enum visibility: { open: 0, hidden: 1, closed: 2, timed: 3 } + enum :visibility, { open: 0, hidden: 1, closed: 2, timed: 3 } before_save :regenerate_activity_tokens, if: :visibility_changed? before_create :generate_access_token diff --git a/app/models/submission.rb b/app/models/submission.rb index a1e8120aed..918fa55a5f 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -28,7 +28,7 @@ class Submission < ApplicationRecord CODE_FILENAME = 'code'.freeze RESULT_FILENAME = 'result.json.gz'.freeze - enum status: { unknown: 0, correct: 1, wrong: 2, 'time limit exceeded': 3, running: 4, queued: 5, 'runtime error': 6, 'compilation error': 7, 'memory limit exceeded': 8, 'internal error': 9, 'output limit exceeded': 10 } + enum :status, { unknown: 0, correct: 1, wrong: 2, 'time limit exceeded': 3, running: 4, queued: 5, 'runtime error': 6, 'compilation error': 7, 'memory limit exceeded': 8, 'internal error': 9, 'output limit exceeded': 10 } belongs_to :exercise, optional: false belongs_to :user, optional: false @@ -70,7 +70,7 @@ class Submission < ApplicationRecord scope :by_status, ->(status) { where(status: status.in?(statuses) ? status : -1) } scope :by_username, ->(name) { where(user: User.by_filter(name)) } scope :by_filter, lambda { |filter, skip_user:, skip_exercise:| - filter.split.map(&:strip).select(&:present?).map do |part| + filter.split.map(&:strip).compact_blank.map do |part| scopes = [] scopes << by_exercise_name(part) unless skip_exercise scopes << by_username(part) unless skip_user diff --git a/app/models/user.rb b/app/models/user.rb index 208f6ee54a..463fcc757f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -33,8 +33,8 @@ class User < ApplicationRecord ATTEMPTED_EXERCISES_CACHE_STRING = '/courses/%s/user/%s/attempted_exercises'.freeze CORRECT_EXERCISES_CACHE_STRING = '/courses/%s/user/%s/correct_exercises'.freeze - enum permission: { student: 0, staff: 1, zeus: 2 } - enum theme: { system: 0, light: 1, dark: 2 } + enum :permission, { student: 0, staff: 1, zeus: 2 } + enum :theme, { system: 0, light: 1, dark: 2 } belongs_to :institution, optional: true diff --git a/test/controllers/exports_controller_test.rb b/test/controllers/exports_controller_test.rb index 3c51d40307..5de9eeb793 100644 --- a/test/controllers/exports_controller_test.rb +++ b/test/controllers/exports_controller_test.rb @@ -34,7 +34,7 @@ class ExportsControllerTest < ActionDispatch::IntegrationTest post series_exports_path(@series), params: { all: true, only_last_submission: true, with_info: true, format: :json } assert_response :success - count = @students.map { |u| @series.exercises.map { |e| e.last_submission(u, @series) } }.flatten.select(&:present?).count + count = @students.map { |u| @series.exercises.map { |e| e.last_submission(u, @series) } }.flatten.compact_blank.count assert_zip ActiveStorage::Blob.last.download, with_info: true, solution_count: count, data: @data end