From 1d0d6249e6151ff309ab0f2aad6b55915c4a232f Mon Sep 17 00:00:00 2001 From: Cameron Matheson Date: Tue, 17 Sep 2013 14:01:28 -0600 Subject: [PATCH] fix speedgrader regression when viewing quizzes fixes CNVS-8204 Test plan: * Make a quiz * give students a score for the quiz in gradebook (do not take the quiz) * open the quiz in speedgrader * the gradebook should load with no errors Change-Id: I6328fb786a2ba27d80e04ebeaecd85c579e7b4cd Reviewed-on: https://gerrit.instructure.com/24463 Tested-by: Jenkins Reviewed-by: Simon Williams QA-Review: Amber Taniuchi Product-Review: Simon Williams --- app/models/assignment.rb | 64 +++++++++++++++++----------------- spec/models/assignment_spec.rb | 16 +++++++++ 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/app/models/assignment.rb b/app/models/assignment.rb index f6a8d4a33cb..f5313f67a80 100644 --- a/app/models/assignment.rb +++ b/app/models/assignment.rb @@ -1148,38 +1148,38 @@ class Assignment < ActiveRecord::Base :methods => [:scribdable?, :scribd_doc, :submission_history, :late], :only => submission_fields ) - if json['submission_history'] && quiz.nil? - json['submission_history'].map! do |version| - version.as_json( - :include => { - :submission_comments => { :only => comment_fields } - }, - :only => submission_fields, - :methods => [:versioned_attachments, :late] - ).tap do |version_json| - if version_json['submission'] && version_json['submission']['versioned_attachments'] - version_json['submission']['versioned_attachments'].map! do |a| - a.as_json( - :only => attachment_fields, - :methods => [:view_inline_ping_url, :scribd_render_url] - ) - end - end - end - end - elsif quiz - quiz_submission_versions = sub.quiz_submission.versions.reverse - json['submission_history'] = quiz_submission_versions.map do |v| - qs = v.model - {submission: { - grade: qs.score, - show_grade_in_dropdown: true, - submitted_at: qs.finished_at, - late: qs.overdue?, - version: v.number, - }} - end - end + json['submission_history'] = if json['submission_history'] && quiz.nil? + json['submission_history'].map do |version| + version.as_json( + :include => { + :submission_comments => { :only => comment_fields } + }, + :only => submission_fields, + :methods => [:versioned_attachments, :late] + ).tap do |version_json| + if version_json['submission'] && version_json['submission']['versioned_attachments'] + version_json['submission']['versioned_attachments'].map! do |a| + a.as_json( + :only => attachment_fields, + :methods => [:view_inline_ping_url, :scribd_render_url] + ) + end + end + end + end + elsif quiz && sub.quiz_submission + quiz_submission_versions = sub.quiz_submission.versions.reverse + quiz_submission_versions.map do |v| + qs = v.model + {submission: { + grade: qs.score, + show_grade_in_dropdown: true, + submitted_at: qs.finished_at, + late: qs.overdue?, + version: v.number, + }} + end + end json } res[:GROUP_GRADING_MODE] = grade_as_group? diff --git a/spec/models/assignment_spec.rb b/spec/models/assignment_spec.rb index a6972f2204c..1c1be36eb23 100644 --- a/spec/models/assignment_spec.rb +++ b/spec/models/assignment_spec.rb @@ -2162,6 +2162,22 @@ describe Assignment do end json["GROUP_GRADING_MODE"].should be_true end + + it "works for quizzes without quiz_submissions" do + course_with_teacher(:active_all => true) + student_in_course + quiz = @course.quizzes.create! :title => "Final", + :quiz_type => "assignment" + quiz.did_edit + quiz.offer + + assignment = quiz.assignment + assignment.grade_student(@student, grade: 1) + json = assignment.speed_grader_json(@teacher) + json[:submissions].all? { |s| + s.has_key? 'submission_history' + }.should be_true + end end describe "update_student_submissions" do