Skip to content

Commit

Permalink
fix: update model object to work with ruby 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
macite committed Jan 9, 2022
1 parent 164f93e commit 565250a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/helpers/file_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def write_entries_to_zip(entries, disk_root_path, zip_root_path, path, zip)
# puts "subdir: #{subdir}"
write_entries_to_zip(subdir, disk_root_path, zip_root_path, file_path, zip)
else
# puts "Adding file: #{disk_file_path} -- #{File.exists? disk_file_path}"
# puts "Adding file: #{disk_file_path} -- #{File.exist? disk_file_path}"
zip.get_output_stream(zip_file_path) do |f|
f.puts(File.open(disk_file_path, 'rb').read)
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/overseer_assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def self.create_for(task)
end

def has_submission_files?
File.exists? submission_zip_file_name
File.exist? submission_zip_file_name
end

def submission_zip_file_name
Expand Down Expand Up @@ -155,7 +155,7 @@ def send_to_overseer()
return nil
end

unless File.exists? submission_zip_file_name
unless File.exist? submission_zip_file_name
puts "ERROR: Student submission history zip file doesn't exist #{submission_zip_file_name}. Unable to send - OverseerAssessment #{id}"
return nil
end
Expand All @@ -166,7 +166,7 @@ def send_to_overseer()
return nil
end

unless File.exists? assessment_resources_path
unless File.exist? assessment_resources_path
puts "ERROR: Unable to fine assessment resources - OverseerAssessment #{id}"
return nil
end
Expand Down
12 changes: 6 additions & 6 deletions app/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def has_new_files?
end

def has_done_file?
File.exists? zip_file_path_for_done_task
File.exist? zip_file_path_for_done_task
end

#
Expand Down Expand Up @@ -1017,7 +1017,7 @@ def portfolio_evidence_path
def portfolio_evidence_path=(value)
# Strip the student work directory to store in database as relative path
self.portfolio_evidence = value.present? ? value.sub(FileHelper.student_work_dir,'') : nil
end
end

def final_pdf_path
if group_task?
Expand Down Expand Up @@ -1248,7 +1248,7 @@ def accept_submission(current_user, files, _student, ui, contributions, trigger,
enqueued_dir = File.join(FileHelper.student_work_dir(:new, nil, true), id.to_s)

# Move files into place, deleting existing files if present.
if not File.exists? enqueued_dir
if not File.exist? enqueued_dir
logger.debug "Creating student work new dir #{enqueued_dir}"
FileUtils.mkdir_p enqueued_dir
end
Expand All @@ -1259,7 +1259,7 @@ def accept_submission(current_user, files, _student, ui, contributions, trigger,

# Delete the tmp dir
logger.debug "Deleting student work dir: #{tmp_dir}"
FileUtils.rm_rf tmp_dir if File.exists? tmp_dir
FileUtils.rm_rf tmp_dir if File.exist? tmp_dir

logger.info "Submission accepted! Status for task #{id} is now #{trigger}"
end
Expand All @@ -1270,10 +1270,10 @@ def delete_associated_files
group_submission.destroy
else
zip_file = zip_file_path_for_done_task()
if zip_file && File.exists?(zip_file)
if zip_file && File.exist?(zip_file)
FileUtils.rm zip_file
end
if portfolio_evidence_path.present? && File.exists?(portfolio_evidence_path)
if portfolio_evidence_path.present? && File.exist?(portfolio_evidence_path)
FileUtils.rm portfolio_evidence_path
end

Expand Down
10 changes: 5 additions & 5 deletions app/models/task_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ def remove_old_group_submissions

def move_files_on_abbreviation_change
old_abbr = saved_change_to_abbreviation[0] # 0 is original abbreviation
if File.exists? task_sheet_with_abbreviation(old_abbr)
if File.exist? task_sheet_with_abbreviation(old_abbr)
FileUtils.mv(task_sheet_with_abbreviation(old_abbr), task_sheet())
end

if File.exists? task_resources_with_abbreviation(old_abbr)
if File.exist? task_resources_with_abbreviation(old_abbr)
FileUtils.mv(task_resources_with_abbreviation(old_abbr), task_resources())
end

if File.exists? task_assessment_resources_with_abbreviation(old_abbr)
if File.exist? task_assessment_resources_with_abbreviation(old_abbr)
FileUtils.mv(task_assessment_resources_with_abbreviation(old_abbr), task_assessment_resources())
end
end
Expand Down Expand Up @@ -340,8 +340,8 @@ def clear_related_plagiarism
end
end

def self.to_csv(task_definitions, options = {})
CSV.generate(options) do |csv|
def self.to_csv(task_definitions)
CSV.generate() do |csv|
csv << csv_columns
task_definitions.each do |task_definition|
csv << task_definition.to_csv_row
Expand Down
22 changes: 11 additions & 11 deletions app/models/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def update_student_enrolments(changes, import_settings, result)
last_name = last_name || first_name
nickname = nickname || first_name

if !email =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
if email !~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
errors << { row: row, message: "Invalid email address (#{email})" }
next
end
Expand Down Expand Up @@ -1338,12 +1338,12 @@ def tutorial_stream_abbr
tutorial_streams.map{|ts| ts.abbreviation }
end

def task_completion_csv(options = {})
def task_completion_csv
task_def_by_grade = task_definitions_by_grade
streams = tutorial_streams
grp_sets = group_sets

CSV.generate(options) do |csv|
CSV.generate() do |csv|
# Add header row
csv << [
'Student ID',
Expand Down Expand Up @@ -1407,7 +1407,7 @@ def task_completion_csv(options = {})
"#{row['first_name']} #{row['last_name']}",
GradeHelper.grade_for(row['target_grade']),
row['email'],
row['portfolio_production_date'].present? && !row['compile_portfolio'] && File.exists?(FileHelper.student_portfolio_path(self, row['username'], true)),
row['portfolio_production_date'].present? && !row['compile_portfolio'] && File.exist?(FileHelper.student_portfolio_path(self, row['username'], true)),
row['grade'] > 0 ? row['grade'] : nil,
row['grade_rationale']
] + [1].map do
Expand Down Expand Up @@ -1437,7 +1437,7 @@ def get_portfolio_zip(current_user)
filename = FileHelper.sanitized_filename("portfolios-#{code}-#{current_user.username}")
result = "#{FileHelper.tmp_file(filename)}.zip"

return result if File.exists?(result)
return result if File.exist?(result)
# Create a new zip
Zip::File.open(result, Zip::File::CREATE) do |zip|
active_projects.each do |project|
Expand All @@ -1462,7 +1462,7 @@ def get_task_resources_zip
# Get a temp file path
result = FileHelper.tmp_file("task-resources-#{code}.zip")

return result if File.exists?(result)
return result if File.exist?(result)

# Create a new zip
Zip::File.open(result, Zip::File::CREATE) do |zip|
Expand Down Expand Up @@ -1490,7 +1490,7 @@ def get_task_submissions_pdf_zip(current_user, td)

tasks_with_files = td.related_tasks_with_files

return result if File.exists?(result)
return result if File.exist?(result)

# Create a new zip
Zip::File.open(result, Zip::File::CREATE) do |zip|
Expand Down Expand Up @@ -1523,7 +1523,7 @@ def get_task_submissions_zip(current_user, td)

tasks_with_files = td.related_tasks_with_files

return result if File.exists?(result)
return result if File.exist?(result)

# Create a new zip
Zip::File.open(result, Zip::File::CREATE) do |zip|
Expand Down Expand Up @@ -2275,8 +2275,8 @@ def student_grades_csv
end

# Used to calculate the number of assessment each tutor has performed
def tutor_assessment_csv(options = {})
CSV.generate(options) do |csv|
def tutor_assessment_csv
CSV.generate() do |csv|
csv << [
'Username',
'Tutor Name',
Expand Down Expand Up @@ -2322,7 +2322,7 @@ def generate_batch_task_zip(user, tasks)

output_zip = FileHelper.tmp_file("batch_ready_for_feedback_#{code}_#{user.username}.zip")

return result if File.exists?(output_zip)
return result if File.exist?(output_zip)

# Create a new zip
Zip::File.open(output_zip, Zip::File::CREATE) do |zip|
Expand Down
14 changes: 11 additions & 3 deletions config/secrets.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
development: &development
development: &development-settings
secret_key_base: <%= ENV['DF_SECRET_KEY_BASE'] || '9e010ee2f52af762916406fd2ac488c5694a6cc784777136e657511f8bbc7a73f96d59c0a9a778a0d7cf6406f8ecbf77efe4701dfbd63d8248fc7cc7f32dea97' %>
secret_key_attr: <%= ENV['DF_SECRET_KEY_ATTR'] || 'e69fc5960ca0e8700844a3a25fe80373b41c0a265d342eba06950113f3766fd983bad9ec51bf36eb615d9711bfe1dd90b8e35f01841b323f604ffee857e32055' %>
secret_key_devise: <%= ENV['DF_SECRET_KEY_DEVISE'] || 'f4e23c4388dc600e503a09ad057b8271d8fcf4c2cd6723b44f33db638e49075fe96bc545eed9110ded0c5df505625d4e1c838b718349eecf1d39270d0829d5b9' %>
secret_key_aaf: <%= ENV['DF_SECRET_KEY_AAF'] || 'secretsecret12345' %>
secret_key_moss: <%= ENV['DF_SECRET_KEY_MOSS'] %>
test:
<<: *development
secret_key_base: <%= ENV['DF_SECRET_KEY_BASE'] || '9e010ee2f52af762916406fd2ac488c5694a6cc784777136e657511f8bbc7a73f96d59c0a9a778a0d7cf6406f8ecbf77efe4701dfbd63d8248fc7cc7f32dea97' %>
secret_key_attr: <%= ENV['DF_SECRET_KEY_ATTR'] || 'e69fc5960ca0e8700844a3a25fe80373b41c0a265d342eba06950113f3766fd983bad9ec51bf36eb615d9711bfe1dd90b8e35f01841b323f604ffee857e32055' %>
secret_key_devise: <%= ENV['DF_SECRET_KEY_DEVISE'] || 'f4e23c4388dc600e503a09ad057b8271d8fcf4c2cd6723b44f33db638e49075fe96bc545eed9110ded0c5df505625d4e1c838b718349eecf1d39270d0829d5b9' %>
secret_key_aaf: <%= ENV['DF_SECRET_KEY_AAF'] || 'secretsecret12345' %>
secret_key_moss: <%= ENV['DF_SECRET_KEY_MOSS'] %>
staging:
<<: *development
secret_key_base: <%= ENV['DF_SECRET_KEY_BASE'] || '9e010ee2f52af762916406fd2ac488c5694a6cc784777136e657511f8bbc7a73f96d59c0a9a778a0d7cf6406f8ecbf77efe4701dfbd63d8248fc7cc7f32dea97' %>
secret_key_attr: <%= ENV['DF_SECRET_KEY_ATTR'] || 'e69fc5960ca0e8700844a3a25fe80373b41c0a265d342eba06950113f3766fd983bad9ec51bf36eb615d9711bfe1dd90b8e35f01841b323f604ffee857e32055' %>
secret_key_devise: <%= ENV['DF_SECRET_KEY_DEVISE'] || 'f4e23c4388dc600e503a09ad057b8271d8fcf4c2cd6723b44f33db638e49075fe96bc545eed9110ded0c5df505625d4e1c838b718349eecf1d39270d0829d5b9' %>
secret_key_aaf: <%= ENV['DF_SECRET_KEY_AAF'] || 'secretsecret12345' %>
secret_key_moss: <%= ENV['DF_SECRET_KEY_MOSS'] %>
production:
secret_key_base: <%= ENV['DF_SECRET_KEY_BASE'] %>
secret_key_attr: <%= ENV['DF_SECRET_KEY_ATTR'] %>
Expand Down
8 changes: 4 additions & 4 deletions lib/helpers/database_populator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def self.assess_task(proj, task, tutor, status, complete_date)
end

pdf_path = task.final_pdf_path
if pdf_path && !File.exists?(pdf_path)
if pdf_path && !File.exist?(pdf_path)
FileUtils.ln_s(Rails.root.join('test_files', 'unit_files', 'sample-student-submission.pdf'), pdf_path)
end

Expand All @@ -486,7 +486,7 @@ def self.generate_portfolio(project)
FileUtils.mkdir_p(portfolio_tmp_dir)

lsr_path = File.join(portfolio_tmp_dir, "000-document-LearningSummaryReport.pdf")
FileUtils.ln_s(Rails.root.join('test_files', 'unit_files', 'sample-learning-summary.pdf'), lsr_path) unless File.exists? lsr_path
FileUtils.ln_s(Rails.root.join('test_files', 'unit_files', 'sample-learning-summary.pdf'), lsr_path) unless File.exist? lsr_path
project.compile_portfolio = true
project.create_portfolio
end
Expand All @@ -508,7 +508,7 @@ def echo_line *args
def generate_tasks_for_unit(unit, unit_details)
echo "----> Generating #{unit_details[:num_tasks]} tasks"

if File.exists? Rails.root.join('test_files',"#{unit.code}-Tasks.csv")
if File.exist? Rails.root.join('test_files',"#{unit.code}-Tasks.csv")
unit.import_tasks_from_csv File.open(Rails.root.join('test_files',"#{unit.code}-Tasks.csv"))
unit.import_task_files_from_zip Rails.root.join('test_files',"#{unit.code}-Tasks.zip")
return
Expand Down Expand Up @@ -546,7 +546,7 @@ def generate_and_align_ilos_for_unit(unit, unit_details)
# Create the ILOs
echo "----> Adding #{unit_details[:ilos]} ILOs"

if File.exists? Rails.root.join('test_files',"#{unit.code}-Outcomes.csv")
if File.exist? Rails.root.join('test_files',"#{unit.code}-Outcomes.csv")
unit.import_outcomes_from_csv File.open(Rails.root.join('test_files',"#{unit.code}-Outcomes.csv"))
unit.import_task_alignment_from_csv File.open(Rails.root.join('test_files',"#{unit.code}-Alignment.csv")), nil
return
Expand Down

0 comments on commit 565250a

Please sign in to comment.