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 <kbjorkman@instructure.com>
QA-Review: Kai Bjorkman <kbjorkman@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Product-Review: Cameron Ray <cameron.ray@instructure.com>
This commit is contained in:
Spencer Olson 2024-09-04 13:50:04 -05:00
parent ce5bb18812
commit f83328b07a
4 changed files with 20 additions and 2 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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