Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Sep 11, 2023
1 parent c273a48 commit 95fc3e4
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 25 deletions.
4 changes: 2 additions & 2 deletions app/controllers/annotations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def question_index
authorize Question, :index?
@user = User.find(params[:user_id]) if params[:user_id]

@questions = policy_scope(Question).merge(apply_scopes(Question).all)
@questions = policy_scope(Question).merge(apply_scopes(Question))
@questions = @questions.where(question_state: params[:question_state]) if params[:question_state]

@unfiltered = @user.nil? && params[:course_id].nil?
Expand Down Expand Up @@ -85,7 +85,7 @@ def update

def destroy
@annotation.destroy
render json: {}, status: :no_content
render status: :no_content
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/labels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class LabelsController < ApplicationController

def index
authorize Label
@labels = policy_scope(Label.all).merge(apply_scopes(Label).all)
@labels = policy_scope(Label.all).merge(apply_scopes(Label))
@title = I18n.t('labels.index.title')
@crumbs = [[I18n.t('labels.index.title'), '#']]
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/score_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def destroy
@score_item.destroy
respond_to do |format|
format.js { render 'score_items/index', locals: { new: nil, evaluation_exercise: preload_eval_exercise(@score_item) } }
format.json { render json: {}, status: :no_content }
format.json { render status: :no_content }
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/scores_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def destroy
set_common
respond_to do |format|
format.js { render 'feedbacks/show' }
format.json { render json: {}, status: :no_content }
format.json { render status: :no_content }
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def set_submission
# The logic here is very similar to that of set_activity_read_states in activity_read_states_controller
# changes made here are potentially applicable to both functions
def set_submissions
@submissions = policy_scope(Submission).merge(apply_scopes(Submission).all)
@submissions = policy_scope(Submission).merge(apply_scopes(Submission))
if params[:user_id]
@user = User.find(params[:user_id])
@submissions = @submissions.of_user(@user)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ def set_user

def set_users
authorize User
@users = apply_scopes(User).all.order(permission: :desc, last_name: :asc, first_name: :asc).paginate(page: parse_pagination_param(params[:page]))
@users = apply_scopes(User).order(permission: :desc, last_name: :asc, first_name: :asc).paginate(page: parse_pagination_param(params[:page]))
end
end
2 changes: 1 addition & 1 deletion app/helpers/export_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def bundle
end

def get_submissions_for_series(series, selected_exercises, users)
submissions = policy_scope(Submission).all.where(user_id: users.map(&:id), exercise_id: selected_exercises.map(&:id), course: series.course_id).includes(:user, :exercise)
submissions = policy_scope(Submission).where(user_id: users.map(&:id), exercise_id: selected_exercises.map(&:id), course: series.course_id).includes(:user, :exercise)
submissions = submissions.before_deadline(@options[:deadline]) if deadline?
submissions = submissions.group(:user_id, :exercise_id).most_recent if only_last_submission?
submissions.sort_by { |s| [selected_exercises.map(&:id).index(s.exercise_id), users.map(&:id).index(s.user_id), s.id] }
Expand Down
9 changes: 6 additions & 3 deletions app/helpers/notifications_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ module NotificationsHelper
def base_notifiable_url_params(notification)
return { controller: 'exports', action: 'index' } if notification.notifiable_type == 'Export'
return { controller: 'submissions', action: 'show', id: notification.notifiable_id } if notification.notifiable_type == 'Submission'
return { controller: 'evaluations', action: 'overview', id: notification.notifiable_id } if notification.notifiable_type == 'Evaluation'

{ controller: 'evaluations', action: 'overview', id: notification.notifiable_id } if notification.notifiable_type == 'Evaluation'
end

def notifiable_url(notification)
return exports_path(highlighted: notification.notifiable_id) if notification.notifiable_type == 'Export'
return submission_path(notification.notifiable_id, anchor: 'code') if notification.notifiable_type == 'Submission'
return overview_evaluation_path(notification.notifiable_id) if notification.notifiable_type == 'Evaluation'

overview_evaluation_path(notification.notifiable_id) if notification.notifiable_type == 'Evaluation'
end

def notifiable_icon(notification)
return 'mdi-file-download-outline' if notification.notifiable_type == 'Export'
return 'mdi-comment-account-outline' if notification.notifiable_type == 'Submission'
return 'mdi-comment-multiple-outline' if notification.notifiable_type == 'Evaluation'

'mdi-comment-multiple-outline' if notification.notifiable_type == 'Evaluation'
end
end
2 changes: 1 addition & 1 deletion app/runners/submission_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def execute
while Time.zone.now - before_time < time_limit
before_stats = Time.zone.now
# Check if container is still running
if !Rails.env.test? && (Docker::Container.all.any? { |c| c.id.starts_with?(container.id) || container.id.starts_with?(container.id) } && container.refresh!.info['State']['Running'])
if !Rails.env.test? && (Docker::Container.any? { |c| c.id.starts_with?(container.id) || container.id.starts_with?(container.id) } && container.refresh!.info['State']['Running'])
# If we don't pass these extra options gathering stats takes 1+ seconds (https://github.com/moby/moby/issues/23188#issuecomment-223211481)
stats = container.stats({ 'one-shot': true, stream: false })
memory = [stats['memory_stats']['usage'] / (1024.0 * 1024.0), memory].max if stats['memory_stats']&.fetch('usage', nil)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/activities_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def setup
assert_equal Activity.where(judge: judge).count, response.parsed_body.count
assert_equal @instance.id, response.parsed_body[0]['id']

get activities_url(format: :json, judge_id: Judge.all.last.id + 1)
get activities_url(format: :json, judge_id: Judge.last.id + 1)

assert_equal 0, response.parsed_body.count
end
Expand Down
6 changes: 3 additions & 3 deletions test/controllers/evaluations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ def setup
normal_annotations += 1
end

assert_equal normal_annotations, Notification.all.count, 'only notifications for the annotations without a feedback session'
assert_equal normal_annotations, Notification.count, 'only notifications for the annotations without a feedback session'

evaluation.feedbacks.each do |feedback|
feedback.update(completed: true)
end

assert_equal normal_annotations, Notification.all.count, 'no new notification should be made upon completing a feedback'
assert_equal normal_annotations, Notification.count, 'no new notification should be made upon completing a feedback'

evaluation.update(released: true)

assert_equal normal_annotations + @users.count, Notification.all.count, 'A new notification per user should be made upon releasing a feedback session, along with keeping the notifications made for annotations without a feedback session'
assert_equal normal_annotations + @users.count, Notification.count, 'A new notification per user should be made upon releasing a feedback session, along with keeping the notifications made for annotations without a feedback session'
end

test 'non released annotations are not queryable' do
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/exports_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ExportsControllerTest < ActionDispatch::IntegrationTest
post series_exports_path(@series), params: { all: true }

assert_redirected_to exports_path
assert_zip ActiveStorage::Blob.last.download, solution_count: Submission.all.count, data: @data
assert_zip ActiveStorage::Blob.last.download, solution_count: Submission.count, data: @data
end

test 'all students should be present in the zip' do
Expand Down
2 changes: 1 addition & 1 deletion test/models/course_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class CourseTest < ActiveSupport::TestCase
[create(:institution), i, nil].each do |institution|
u = create :user, institution: institution

Course.all.each do |c|
Course.find_each do |c|
assert_equal c.open_for_user?(u), Course.can_register(u).exists?(c.id)
end
end
Expand Down
12 changes: 6 additions & 6 deletions test/models/repository_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def teardown
end

test 'should create new exercise when config without token is placed in path of removed exercise' do
start = Exercise.all.count
start = Exercise.count
@remote.remove_dir(@echo.path)
@remote.commit('remove exercise')
@repository.reset
Expand All @@ -195,11 +195,11 @@ def teardown
@echo.reload

assert_equal 'removed', @echo.status
assert_equal 1, Exercise.all.count - start
assert_equal 1, Exercise.count - start
end

test 'should create new exercise when exercise is copied' do
start = Exercise.all.count
start = Exercise.count
new_dir = 'echo2'
@remote.copy_dir(@echo.path, new_dir)
@remote.commit('copy exercise')
Expand All @@ -208,11 +208,11 @@ def teardown
@echo.reload

assert_equal 'echo', @echo.path
assert_equal 1, Exercise.all.count - start
assert_equal 1, Exercise.count - start
end

test 'should create only 1 new exercise on copy + rename' do
start = Exercise.all.count
start = Exercise.count
new_dir1 = 'echo2'
new_dir2 = 'echo3'
@remote.copy_dir(@echo.path, new_dir1)
Expand All @@ -223,7 +223,7 @@ def teardown
@echo.reload

assert_includes [new_dir1, new_dir2], @echo.path
assert_equal 1, Exercise.all.count - start
assert_equal 1, Exercise.count - start
end

test 'should copy valid token for new exercise' do
Expand Down
2 changes: 1 addition & 1 deletion test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def setup
CourseMembership.create user: u1, course: c, status: 'student'
CourseMembership.create user: u2, course: c, status: 'student'
s1 = create :series, course: c, exercise_count: 0
s2 = create :series, course: c2, exercise_count: 0
s2 = create :series, course: c2, exercise_count: 0
e1 = create :exercise
e2 = create :exercise
e3 = create :exercise
Expand Down

0 comments on commit 95fc3e4

Please sign in to comment.