From c7a46c7184c17f49aaf4370e9ba5b0c4e82cb6a5 Mon Sep 17 00:00:00 2001 From: Pranav Rao <56097527+pranavrao145@users.noreply.github.com> Date: Tue, 24 Sep 2024 23:41:33 -0400 Subject: [PATCH] feat(retain-old-grading-data-option): copy automated tests --- app/jobs/submissions_job.rb | 35 +++++++++++++++++++++---- config/locales/views/submissions/en.yml | 4 +-- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/jobs/submissions_job.rb b/app/jobs/submissions_job.rb index ff60f7e338..675595c955 100644 --- a/app/jobs/submissions_job.rb +++ b/app/jobs/submissions_job.rb @@ -18,17 +18,17 @@ def copy_old_grading_data(new_submission, grouping) .where(remark_request_submitted_at: nil) .last - collections = [ + result_data = [ { old: old_result.annotations, new: new_result.annotations }, { old: old_result.marks, new: new_result.marks }, { old: old_result.extra_marks, new: new_result.extra_marks } ] - collections.each do |collection| + result_data.each do |result_set| # get rid of the existing empty records so we can replace them - collection[:new].all.destroy_all + result_set[:new].destroy_all - collection[:old].each do |item| + result_set[:old].each do |item| item_dup = item.dup item_dup.result_id = new_result.id item_dup.save @@ -36,6 +36,32 @@ def copy_old_grading_data(new_submission, grouping) add_warning_messages(item_dup.errors.full_messages) if item_dup.errors.present? end end + + old_submission.test_runs.each do |test_run| + test_run_dup = test_run.dup + test_run_dup.submission_id = new_submission.id + test_run_dup.save + + # don't continue if there are errors at this point + return add_warning_messages(test_run_dup.errors.full_messages) if test_run_dup.errors.present? + + test_run.test_group_results.each do |test_group_result| + test_group_result_dup = test_group_result.dup + test_group_result_dup.test_run_id = test_run_dup.id + test_group_result_dup.save + + # don't continue if there are errors at this point + return add_warning_messages(test_group_result_dup.errors.full_messages) if test_group_result_dup.errors.present? + + test_group_result.test_results.each do |test_result| + test_result_dup = test_result.dup + test_result_dup.test_group_result_id = test_group_result_dup.id + test_result_dup.save + + add_warning_messages(test_result_dup.errors.full_messages) if test_result_dup.errors.present? + end + end + end end def perform(groupings, apply_late_penalty: true, **options) @@ -59,7 +85,6 @@ def perform(groupings, apply_late_penalty: true, **options) new_submission = Submission.create_by_revision_identifier(grouping, options[:revision_identifier]) end - # here is where we would copy over old grading data if options[:retain_existing_grading] copy_old_grading_data(new_submission, grouping) end diff --git a/config/locales/views/submissions/en.yml b/config/locales/views/submissions/en.yml index 7d249f1612..835ec5129d 100644 --- a/config/locales/views/submissions/en.yml +++ b/config/locales/views/submissions/en.yml @@ -18,10 +18,10 @@ en: full_overwrite_warning: Collecting and grading this revision will overwrite any previous collections/grading done for this group on this assignment. Are you sure you want to do this? manual_collection: Manual Collection override_existing: Recollect previously collected submissions? - partial_overwrite_warning: Original marks and annotations will be retained upon collecting this revision, but all remark data and autotest results from previous collections/grading will still be lost for this group on this assignment. Are you sure you want to do this? + partial_overwrite_warning: Original marks, annotations, and test results will be retained upon collecting this revision, but all remark data from previous collections/grading will still be lost for this group on this assignment. Are you sure you want to do this? progress: "%{count}/%{size} submissions collected" results_loss_warning: This action identifies the version of files to grade for each selected group. Instructors and TAs can begin grading after files are collected. - retain_existing_grading: Retain existing grading data (marks and annotations) + retain_existing_grading: Retain existing grading data (marks, annotations, and test results) retain_existing_grading_warning_html: 'Retain existing grading data (Warning: without selecting this option, all old grading data for the collected submissions will be lost)' scanned_exam_latest_warning: For scanned exams, the latest submitted file version for each selected group is used regardless of the due date. status: