guard grade_distribution to fix error on concluded student's grade page
fixes CNVS-17901 The GradeSummaryAssignmentPresenter#grade_distribution would throw an error when it was triggered with a concluded student, because its call to GradeSummaryPresenter#assignment_stats returned an empty hash, instead of one which contains the assignment's id as a key. A NoMethodError was triggered off of a nil provided by the hash. To fix this, I wrapped the offending code in an if clause to guard against this case. Test Plan: 1. Create a published course that has a student and at least 1 graded assignment 2. Give the student a grade for the assignment 3. Conclude the student's enrollment on the course's user show page 4. Go to the course people page and select "View Prior Enrollments" 5. Select the grade under the Total column for the concluded student 6. Confirm that the page loads and displays a grade. Change-Id: I1bb6b4ba4b64ccdb976634fd68b916f1814b539d Reviewed-on: https://gerrit.instructure.com/48001 Tested-by: Jenkins Reviewed-by: Josh Simpson <jsimpson@instructure.com> QA-Review: Amber Taniuchi <amber@instructure.com> Product-Review: Strand McCutchen <smccutchen@instructure.com>
This commit is contained in:
parent
a0c8fa25fe
commit
6ff48eb015
|
@ -106,10 +106,9 @@ class GradeSummaryAssignmentPresenter
|
|||
|
||||
def grade_distribution
|
||||
@grade_distribution ||= begin
|
||||
stats = @summary.assignment_stats[assignment.id]
|
||||
[stats.max.to_f.round(1),
|
||||
stats.min.to_f.round(1),
|
||||
stats.avg.to_f.round(1)]
|
||||
if stats = @summary.assignment_stats[assignment.id]
|
||||
[stats.max, stats.min, stats.avg].map { |stat| stat.to_f.round(1) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
#
|
||||
# Copyright (C) 2015 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
||||
|
||||
describe GradeSummaryAssignmentPresenter do
|
||||
let(:summary) {
|
||||
GradeSummaryPresenter.new :first, :second, :third
|
||||
}
|
||||
|
||||
let(:assignment) {
|
||||
Assignment.new
|
||||
}
|
||||
|
||||
let(:presenter) {
|
||||
GradeSummaryAssignmentPresenter.new(summary,
|
||||
:current_user,
|
||||
assignment,
|
||||
:submission)
|
||||
}
|
||||
|
||||
context "#grade_distribution" do
|
||||
context "when a summary's assignment_stats is empty" do
|
||||
before { summary.stubs(:assignment_stats).returns({}) }
|
||||
|
||||
it "does not raise an error " do
|
||||
expect { presenter.grade_distribution }.to_not raise_error
|
||||
end
|
||||
|
||||
it "returns nil when a summary's assignment_stats is empty" do
|
||||
expect(presenter.grade_distribution).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue