fix grade calculator to handle deleted enrollments
The grade calculator was throwing an error when computing scores for a grading period for users with deleted enrollments. It will no longer throw an error in that scenario. closes CNVS-34643 1. Set up a course that is using grading periods with at least two active students. 2. Open a rails console. 3. Find the course. course = Course.find(2) 4. Find an active student in the course. student = course.students.active.first 5. Destroy all the student's enrollments. student.enrollments.destroy_all 6. Get a grading period ID for a grading period being used by the course. grading_period_id = GradingPeriod.for(course).first.id 7. Run the grade calculator for the student in the grading period and verify no errors are thrown. GradeCalculator.recompute_final_score( student.id, course.id, grading_period_id: grading_period_id ) Change-Id: If576c62fed75666c259d4753e8e7e7aeb1a135c9 Reviewed-on: https://gerrit.instructure.com/100961 Reviewed-by: Jeremy Neander <jneander@instructure.com> Reviewed-by: Neil Gupta <ngupta@instructure.com> Reviewed-by: Keith T. Garner <kgarner@instructure.com> Tested-by: Jenkins Reviewed-by: Derek Bender <djbender@instructure.com> Reviewed-by: Rob Orton <rob@instructure.com> QA-Review: KC Naegle <knaegle@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
This commit is contained in:
parent
b7850e6243
commit
2560fba699
|
@ -261,7 +261,7 @@ class GradeCalculator
|
|||
visible_assignments = visible_assignments.select{|a| assignment_ids_visible_to_user(user_id).include?(a.id)}
|
||||
|
||||
if @grading_period
|
||||
user = @course.users.find(user_id)
|
||||
user = User.find(user_id)
|
||||
visible_assignments = @grading_period.assignments_for_student(visible_assignments, user)
|
||||
end
|
||||
assignments_by_group_id = visible_assignments.group_by(&:assignment_group_id)
|
||||
|
|
|
@ -33,6 +33,21 @@ describe GradeCalculator do
|
|||
expect(@user.enrollments.first.computed_final_score).to eql(25.0)
|
||||
end
|
||||
|
||||
it "can compute scores for users with deleted enrollments when grading periods are used" do
|
||||
@course.root_account.enable_feature!(:multiple_grading_periods)
|
||||
grading_period_set = @course.root_account.grading_period_groups.create!
|
||||
grading_period_set.enrollment_terms << @course.enrollment_term
|
||||
period = grading_period_set.grading_periods.create!(
|
||||
title: "A Grading Period",
|
||||
start_date: 10.days.ago,
|
||||
end_date: 10.days.from_now
|
||||
)
|
||||
@user.enrollments.first.destroy
|
||||
expect {
|
||||
GradeCalculator.recompute_final_score(@user.id, @course.id, grading_period_id: period.id)
|
||||
}.not_to raise_error
|
||||
end
|
||||
|
||||
it "should recompute when an assignment's points_possible changes'" do
|
||||
@group = @course.assignment_groups.create!(:name => "some group", :group_weight => 100)
|
||||
@assignment = @course.assignments.create!(:title => "Some Assignment", :points_possible => 10, :assignment_group => @group)
|
||||
|
|
Loading…
Reference in New Issue