diff --git a/app/controllers/concerns/file_parameters.rb b/app/controllers/concerns/file_parameters.rb index 0903ae74..96491bf0 100644 --- a/app/controllers/concerns/file_parameters.rb +++ b/app/controllers/concerns/file_parameters.rb @@ -6,7 +6,7 @@ module FileParameters params.reject do |_, file_attributes| file = CodeOcean::File.find_by(id: file_attributes[:file_id]) # avoid that public files from other contexts can be created - file.nil? || file.hidden || file.read_only || file.context_type == 'Exercise' && file.context_id != exercise.id + file.nil? || file.hidden || file.read_only || (file.context_type == 'Exercise' && file.context_id != exercise.id) end else [] diff --git a/app/helpers/time_helper.rb b/app/helpers/time_helper.rb index 6db718ba..bf5603e9 100644 --- a/app/helpers/time_helper.rb +++ b/app/helpers/time_helper.rb @@ -5,7 +5,7 @@ module TimeHelper def time_to_f(timestamp) unless timestamp.nil? timestamp = timestamp.split(':') - return timestamp[0].to_i * 60 * 60 + timestamp[1].to_i * 60 + timestamp[2].to_f + return (timestamp[0].to_i * 60 * 60) + (timestamp[1].to_i * 60) + timestamp[2].to_f end nil end diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 16e79717..9aae3476 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -68,7 +68,9 @@ class Exercise < ApplicationRecord if submissions.exists?(cause: 'submit') maximum_scores_query = submissions.select('MAX(score) AS maximum_score').group(:user_id).to_sql.sub('$1', id.to_s) self.class.connection.execute("SELECT AVG(maximum_score) AS average_score FROM (#{maximum_scores_query}) AS maximum_scores").first['average_score'].to_f - else 0 end + else + 0 + end end def average_number_of_submissions diff --git a/app/models/proxy_exercise.rb b/app/models/proxy_exercise.rb index 58708160..6ef8cf7b 100644 --- a/app/models/proxy_exercise.rb +++ b/app/models/proxy_exercise.rb @@ -240,7 +240,7 @@ class ProxyExercise < ApplicationRecord def tag_diminishing_return_function(count_tag, total_count_tag) total_count_tag += 1 # bonus exercise comes on top - 1 / (1 + (Math::E**(-3 / (0.5 * total_count_tag) * (count_tag - 0.5 * total_count_tag)))) + 1 / (1 + (Math::E**(-3 / (0.5 * total_count_tag) * (count_tag - (0.5 * total_count_tag))))) end def select_easiest_exercise(exercises) diff --git a/app/policies/exercise_policy.rb b/app/policies/exercise_policy.rb index a54879e8..2c36b47e 100644 --- a/app/policies/exercise_policy.rb +++ b/app/policies/exercise_policy.rb @@ -6,7 +6,7 @@ class ExercisePolicy < AdminOrAuthorPolicy end %i[show? feedback? statistics? rfcs_for_exercise?].each do |action| - define_method(action) { admin? || teacher_in_study_group? || teacher? && @record.public? || author? } + define_method(action) { admin? || teacher_in_study_group? || (teacher? && @record.public?) || author? } end def study_group_dashboard? diff --git a/app/policies/proxy_exercise_policy.rb b/app/policies/proxy_exercise_policy.rb index 92d6d58f..4112064e 100644 --- a/app/policies/proxy_exercise_policy.rb +++ b/app/policies/proxy_exercise_policy.rb @@ -6,7 +6,7 @@ class ProxyExercisePolicy < AdminOrAuthorPolicy end def show? - admin? || teacher_in_study_group? || teacher? && @record.public? || author? + admin? || teacher_in_study_group? || (teacher? && @record.public?) || author? end %i[clone? destroy? edit? update?].each do |action| diff --git a/app/policies/study_group_policy.rb b/app/policies/study_group_policy.rb index 325401bf..3e62034b 100644 --- a/app/policies/study_group_policy.rb +++ b/app/policies/study_group_policy.rb @@ -6,7 +6,7 @@ class StudyGroupPolicy < AdminOnlyPolicy end %i[show? destroy? edit? update? stream_la?].each do |action| - define_method(action) { admin? || @user.teacher? && @record.present? && @user.study_groups.exists?(@record.id) } + define_method(action) { admin? || (@user.teacher? && @record.present? && @user.study_groups.exists?(@record.id)) } end class Scope < Scope diff --git a/lib/tasks/detect_exercise_anomalies.rake b/lib/tasks/detect_exercise_anomalies.rake index 01c71797..8c180193 100644 --- a/lib/tasks/detect_exercise_anomalies.rake +++ b/lib/tasks/detect_exercise_anomalies.rake @@ -51,7 +51,7 @@ namespace :detect_exercise_anomalies do end def log(message = '', indent_level = 0, prefix = '') - puts("\t" * indent_level + "#{prefix}#{message}") + puts(("\t" * indent_level) + "#{prefix}#{message}") end def get_collections(number_of_exercises, number_of_solutions) diff --git a/spec/models/submission_spec.rb b/spec/models/submission_spec.rb index 3e67d5d0..b4d4eb7b 100644 --- a/spec/models/submission_spec.rb +++ b/spec/models/submission_spec.rb @@ -93,7 +93,7 @@ describe Submission do describe '#redirect_to_feedback?' do context 'with no exercise feedback' do let(:exercise) { FactoryBot.create(:dummy) } - let(:user) { FactoryBot.build(:external_user, id: (11 - exercise.created_at.to_i % 10) % 10) } + let(:user) { FactoryBot.build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) % 10) } let(:submission) { FactoryBot.build(:submission, exercise: exercise, user: user) } it 'sends 10% of users to feedback page' do @@ -102,7 +102,7 @@ describe Submission do it 'does not redirect other users' do 9.times do |i| - submission = FactoryBot.build(:submission, exercise: exercise, user: FactoryBot.build(:external_user, id: (11 - exercise.created_at.to_i % 10) - i - 1)) + submission = FactoryBot.build(:submission, exercise: exercise, user: FactoryBot.build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) - i - 1)) expect(submission.send(:redirect_to_feedback?)).to be_falsey end end @@ -110,7 +110,7 @@ describe Submission do context 'with little exercise feedback' do let(:exercise) { FactoryBot.create(:dummy_with_user_feedbacks) } - let(:user) { FactoryBot.build(:external_user, id: (11 - exercise.created_at.to_i % 10) % 10) } + let(:user) { FactoryBot.build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) % 10) } let(:submission) { FactoryBot.build(:submission, exercise: exercise, user: user) } it 'sends 10% of users to feedback page' do @@ -119,7 +119,7 @@ describe Submission do it 'does not redirect other users' do 9.times do |i| - submission = FactoryBot.build(:submission, exercise: exercise, user: FactoryBot.build(:external_user, id: (11 - exercise.created_at.to_i % 10) - i - 1)) + submission = FactoryBot.build(:submission, exercise: exercise, user: FactoryBot.build(:external_user, id: (11 - (exercise.created_at.to_i % 10)) - i - 1)) expect(submission.send(:redirect_to_feedback?)).to be_falsey end end diff --git a/spec/services/proforma_service/convert_task_to_exercise_spec.rb b/spec/services/proforma_service/convert_task_to_exercise_spec.rb index 6e28b341..05c612e4 100644 --- a/spec/services/proforma_service/convert_task_to_exercise_spec.rb +++ b/spec/services/proforma_service/convert_task_to_exercise_spec.rb @@ -118,7 +118,7 @@ describe ProformaService::ConvertTaskToExercise do end context 'when file is very large' do - let(:content) { 'test' * 10**5 } + let(:content) { 'test' * (10**5) } it 'creates an exercise with a file that has the correct attributes' do expect(convert_to_exercise_service.files.first).to have_attributes(content: content) diff --git a/spec/services/proforma_service/import_spec.rb b/spec/services/proforma_service/import_spec.rb index 8f85cf75..a38212b3 100644 --- a/spec/services/proforma_service/import_spec.rb +++ b/spec/services/proforma_service/import_spec.rb @@ -83,7 +83,7 @@ describe ProformaService::Import do it { is_expected.to be_an_equal_exercise_as exercise } context 'when the mainfile is very large' do - let(:file) { FactoryBot.build(:file, content: 'test' * 10**5) } + let(:file) { FactoryBot.build(:file, content: 'test' * (10**5)) } it { is_expected.to be_an_equal_exercise_as exercise } end