From 5f3706b2aac002461213c5526eeefdce12723f49 Mon Sep 17 00:00:00 2001 From: Spencer Olson Date: Wed, 4 Sep 2024 13:50:04 -0500 Subject: [PATCH] handle 0 point assignments in datafixups closes EVAL-4564 flag=none Test Plan: - specs pass Change-Id: I33a4eed7aa5efa6da2368df949230e33e9bd6f46 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/356633 Reviewed-by: Kai Bjorkman QA-Review: Kai Bjorkman Tested-by: Service Cloud Jenkins Product-Review: Cameron Ray --- .../regrade_points_based_scheme_assignments.rb | 2 +- ...grade_versions_for_points_based_scheme_assignments.rb | 2 +- .../regrade_points_based_scheme_assignments_spec.rb | 9 +++++++++ ..._versions_for_points_based_scheme_assignments_spec.rb | 9 +++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/data_fixup/regrade_points_based_scheme_assignments.rb b/lib/data_fixup/regrade_points_based_scheme_assignments.rb index af35bf303de..d0d3e3fd99d 100644 --- a/lib/data_fixup/regrade_points_based_scheme_assignments.rb +++ b/lib/data_fixup/regrade_points_based_scheme_assignments.rb @@ -45,7 +45,7 @@ class DataFixup::RegradePointsBasedSchemeAssignments submissions_with_grades = Submission.where.not(grade: nil).where(assignment_id: assignments.select(:id)) submissions_with_grades.preload(assignment: [:grading_standard, { context: :grading_standard }]).find_in_batches(batch_size: 1000) do |submissions_batch| batched_updates = submissions_batch.each_with_object([]) do |submission, acc| - new_grade = submission.assignment.score_to_grade(submission.score) + new_grade = submission.assignment.score_to_grade(submission.score, submission.grade) grade_has_changed = new_grade != submission.grade || new_grade != submission.published_grade if grade_has_changed acc << submission.attributes.merge("grade" => new_grade, "published_grade" => new_grade, "updated_at" => current_time) diff --git a/lib/data_fixup/regrade_versions_for_points_based_scheme_assignments.rb b/lib/data_fixup/regrade_versions_for_points_based_scheme_assignments.rb index 235f58cef1d..d54e21ba294 100644 --- a/lib/data_fixup/regrade_versions_for_points_based_scheme_assignments.rb +++ b/lib/data_fixup/regrade_versions_for_points_based_scheme_assignments.rb @@ -70,7 +70,7 @@ class DataFixup::RegradeVersionsForPointsBasedSchemeAssignments model = version.model next unless model.grade.present? - new_grade = version.versionable.assignment.score_to_grade(model.score) + new_grade = version.versionable.assignment.score_to_grade(model.score, model.grade) grade_has_changed = new_grade != model.grade || new_grade != model.published_grade next unless grade_has_changed diff --git a/spec/lib/data_fixup/regrade_points_based_scheme_assignments_spec.rb b/spec/lib/data_fixup/regrade_points_based_scheme_assignments_spec.rb index 2b7662af69a..67a2b7e7efb 100644 --- a/spec/lib/data_fixup/regrade_points_based_scheme_assignments_spec.rb +++ b/spec/lib/data_fixup/regrade_points_based_scheme_assignments_spec.rb @@ -60,4 +60,13 @@ describe DataFixup::RegradePointsBasedSchemeAssignments do } expect(@submission3.reload.published_grade).to eq("A") end + + it "handles 0 point assignments using points-based grading standards" do + @submission1.assignment.update!(points_possible: 0) + @submission1.assignment.grade_student(@student, grade: "B", grader: @teacher) + expect { DataFixup::RegradePointsBasedSchemeAssignments.run }.not_to change { + @submission1.reload.grade + }.from("B") + expect(@submission1.reload.published_grade).to eq("B") + end end diff --git a/spec/lib/data_fixup/regrade_versions_for_points_based_scheme_assignments_spec.rb b/spec/lib/data_fixup/regrade_versions_for_points_based_scheme_assignments_spec.rb index 16a7752a1fd..dc5fbc905c7 100644 --- a/spec/lib/data_fixup/regrade_versions_for_points_based_scheme_assignments_spec.rb +++ b/spec/lib/data_fixup/regrade_versions_for_points_based_scheme_assignments_spec.rb @@ -82,4 +82,13 @@ describe DataFixup::RegradeVersionsForPointsBasedSchemeAssignments do } expect(@submission3.reload.versions.first.model.published_grade).to eq("A") end + + it "handles 0 point assignments using points-based grading standards" do + @submission1.assignment.update!(points_possible: 0) + @submission1.assignment.grade_student(@student, grade: "B", grader: @teacher) + expect { DataFixup::RegradeVersionsForPointsBasedSchemeAssignments.run }.not_to change { + @submission1.reload.versions.take.model.grade + }.from("B") + expect(@submission1.reload.versions.take.model.published_grade).to eq("B") + end end