fix total including unposted on individual grades page

closes EVAL-2228
flag=none

Fixes a bug where teachers viewing the individual grades page for a
student would see totals that included scores for unposted submissions.
Now, the totals that teachers see on that page should match the totals
that students see (totals that do not include scores for unposted
submissions).

Test Plan:
1. Create an assignment that posts manually.
2. Go to the Gradebook and give a student a grade for the assignment.
   Do not post grades for the assignment.
3. Still as the teacher, go to the grades page for that student
   (/courses/:course_id/grades/:student_id)
4. Verify that the assignment group totals and course total do not
   include the score for the unposted assignment.
5. Post grades for the assignment.
6. Go to the grades page for that student and verify the assignment
   group totals and course total now include the score for the
   assignment.

Change-Id: Ic41d97b1af74502909be7e928c0a04b3de12324c
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/284698
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Syed Hussain <shussain@instructure.com>
Product-Review: Syed Hussain <shussain@instructure.com>
Reviewed-by: Dustin Cowles <dustin.cowles@instructure.com>
Reviewed-by: Kai Bjorkman <kbjorkman@instructure.com>
This commit is contained in:
Spencer Olson 2022-02-07 10:55:45 -06:00
parent c434f3968e
commit 72a06181b2
2 changed files with 92 additions and 89 deletions

View File

@ -110,8 +110,7 @@ class GradebooksController < ApplicationController
json = {
assignment_id: submission.assignment_id
}
if submission.user_can_read_grade?(@current_user)
if submission.user_can_read_grade?(@presenter.student)
json.merge!({
excused: submission.excused?,
score: submission.score,

View File

@ -37,6 +37,97 @@ describe GradebooksController do
end
describe "GET 'grade_summary'" do
context "when logged in as a student" do
before do
user_session(@student)
@assignment = @course.assignments.create!(title: "Example Assignment")
end
it "includes muted assignments" do
@assignment.ensure_post_policy(post_manually: true)
get "grade_summary", params: { course_id: @course.id, id: @student.id }
expect(assigns[:js_env][:assignment_groups].first[:assignments].size).to eq 1
expect(assigns[:js_env][:assignment_groups].first[:assignments].first[:muted]).to eq true
end
it "does not include score, excused, or workflow_state of unposted submissions" do
@assignment.ensure_post_policy(post_manually: true)
@assignment.grade_student(@student, grade: 10, grader: @teacher)
get "grade_summary", params: { course_id: @course.id, id: @student.id }
submission = assigns[:js_env][:submissions].find { |s| s[:assignment_id] == @assignment.id }
aggregate_failures do
expect(submission).not_to have_key(:score)
expect(submission).not_to have_key(:excused)
expect(submission).not_to have_key(:workflow_state)
end
end
it "includes score, excused, and workflow_state of posted submissions" do
@assignment.grade_student(@student, grade: 10, grader: @teacher)
get "grade_summary", params: { course_id: @course.id, id: @student.id }
submission = assigns[:js_env][:submissions].find { |s| s[:assignment_id] == @assignment.id }
aggregate_failures do
expect(submission[:score]).to be 10.0
expect(submission[:excused]).to be false
expect(submission[:workflow_state]).to eq "graded"
end
end
end
context "when logged in as a teacher" do
before do
user_session(@teacher)
@assignment = @course.assignments.create!(points_possible: 10)
end
it "includes muted assignments" do
@assignment.ensure_post_policy(post_manually: true)
get "grade_summary", params: { course_id: @course.id, id: @student.id }
expect(assigns[:js_env][:assignment_groups].first[:assignments].size).to eq 1
expect(assigns[:js_env][:assignment_groups].first[:assignments].first[:muted]).to eq true
end
it "does not include score, excused, or workflow_state of unposted submissions" do
@assignment.ensure_post_policy(post_manually: true)
@assignment.grade_student(@student, grade: 10, grader: @teacher)
get "grade_summary", params: { course_id: @course.id, id: @student.id }
submission = assigns[:js_env][:submissions].find { |s| s[:assignment_id] == @assignment.id }
aggregate_failures do
expect(submission).not_to have_key(:score)
expect(submission).not_to have_key(:excused)
expect(submission).not_to have_key(:workflow_state)
end
end
it "includes score, excused, and workflow_state of posted submissions" do
@assignment.grade_student(@student, grade: 10, grader: @teacher)
get "grade_summary", params: { course_id: @course.id, id: @student.id }
submission = assigns[:js_env][:submissions].find { |s| s[:assignment_id] == @assignment.id }
aggregate_failures do
expect(submission[:score]).to be 10.0
expect(submission[:excused]).to be false
expect(submission[:workflow_state]).to eq "graded"
end
end
it "returns submissions for inactive students" do
@assignment.grade_student(@student, grade: 6.6, grader: @teacher)
enrollment = @course.enrollments.find_by(user: @student)
enrollment.deactivate
get :grade_summary, params: { course_id: @course.id, id: @student.id }
expect(assigns.fetch(:js_env).fetch(:submissions).first.fetch(:score)).to be 6.6
end
it "returns assignments for inactive students" do
@assignment.grade_student(@student, grade: 6.6, grader: @teacher)
enrollment = @course.enrollments.find_by(user: @student)
enrollment.deactivate
get :grade_summary, params: { course_id: @course.id, id: @student.id }
assignment_id = assigns.dig(:js_env, :assignment_groups, 0, :assignments, 0, :id)
expect(assignment_id).to eq @assignment.id
end
end
it "redirects to the login page if the user is logged out" do
get "grade_summary", params: { course_id: @course.id, id: @student.id }
expect(response).to redirect_to(login_url)
@ -285,93 +376,6 @@ describe GradebooksController do
end
end
it "includes muted assignments" do
user_session(@student)
assignment = @course.assignments.create!(title: "Example Assignment")
assignment.ensure_post_policy(post_manually: true)
get "grade_summary", params: { course_id: @course.id, id: @student.id }
expect(assigns[:js_env][:assignment_groups].first[:assignments].size).to eq 1
expect(assigns[:js_env][:assignment_groups].first[:assignments].first[:muted]).to eq true
end
it "does not include scores of unposted submissions" do
user_session(@student)
assignment = @course.assignments.create!
assignment.ensure_post_policy(post_manually: true)
assignment.grade_student(@student, grade: 10, grader: @teacher)
get "grade_summary", params: { course_id: @course.id, id: @student.id }
submission = assigns[:js_env][:submissions].find { |s| s[:assignment_id] == assignment.id }
expect(submission).not_to have_key(:score)
end
it "does not include excused of unposted submissions" do
user_session(@student)
assignment = @course.assignments.create!
assignment.ensure_post_policy(post_manually: true)
assignment.grade_student(@student, grade: 10, grader: @teacher)
get "grade_summary", params: { course_id: @course.id, id: @student.id }
submission = assigns[:js_env][:submissions].find { |s| s[:assignment_id] == assignment.id }
expect(submission).not_to have_key(:excused)
end
it "does not include workflow_state of unposted submissions" do
user_session(@student)
assignment = @course.assignments.create!
assignment.ensure_post_policy(post_manually: true)
assignment.grade_student(@student, grade: 10, grader: @teacher)
get "grade_summary", params: { course_id: @course.id, id: @student.id }
submission = assigns[:js_env][:submissions].find { |s| s[:assignment_id] == assignment.id }
expect(submission).not_to have_key(:workflow_state)
end
it "includes scores of posted submissions" do
user_session(@student)
assignment = @course.assignments.create!
assignment.grade_student(@student, grade: 10, grader: @teacher)
get "grade_summary", params: { course_id: @course.id, id: @student.id }
submission = assigns[:js_env][:submissions].find { |s| s[:assignment_id] == assignment.id }
expect(submission[:score]).to be 10.0
end
it "includes excused of posted submissions" do
user_session(@student)
assignment = @course.assignments.create!
assignment.grade_student(@student, grade: 10, grader: @teacher)
get "grade_summary", params: { course_id: @course.id, id: @student.id }
submission = assigns[:js_env][:submissions].find { |s| s[:assignment_id] == assignment.id }
expect(submission[:excused]).to be false
end
it "includes workflow_state of posted submissions" do
user_session(@student)
assignment = @course.assignments.create!
assignment.grade_student(@student, grade: 10, grader: @teacher)
get "grade_summary", params: { course_id: @course.id, id: @student.id }
submission = assigns[:js_env][:submissions].find { |s| s[:assignment_id] == assignment.id }
expect(submission[:workflow_state]).to eq "graded"
end
it "returns submissions for inactive students" do
user_session(@teacher)
assignment = @course.assignments.create!(points_possible: 10)
assignment.grade_student(@student, grade: 6.6, grader: @teacher)
enrollment = @course.enrollments.find_by(user: @student)
enrollment.deactivate
get :grade_summary, params: { course_id: @course.id, id: @student.id }
expect(assigns.fetch(:js_env).fetch(:submissions).first.fetch(:score)).to be 6.6
end
it "returns assignments for inactive students" do
user_session(@teacher)
assignment = @course.assignments.create!(points_possible: 10)
assignment.grade_student(@student, grade: 6.6, grader: @teacher)
enrollment = @course.enrollments.find_by(user: @student)
enrollment.deactivate
get :grade_summary, params: { course_id: @course.id, id: @student.id }
assignment_id = assigns.dig(:js_env, :assignment_groups, 0, :assignments, 0, :id)
expect(assignment_id).to eq assignment.id
end
context "assignment sorting" do
let!(:teacher_session) { user_session(@teacher) }
let!(:assignment1) { @course.assignments.create(title: "Banana", position: 2) }