display late message on DA in speedgrader

The model logic of QuizSubmission#late? now accounts for
differentiated assignments. This bubbles up to a fix for
the view.

fixes CNVS-24099

Test plan:
 1. As a teacher in a course with 2 or more students,
    Create a quiz.
 2. Assign the quiz to a student with a due date in the
    past.
 3. As that student, take the quiz.
 4. Go to speedgrader and verify the quiz is late.

Change-Id: If95846dfdccda2684e33334c20a27da4172d0d20
Reviewed-on: https://gerrit.instructure.com/67263
Tested-by: Jenkins
Reviewed-by: Derek Bender <djbender@instructure.com>
Reviewed-by: Spencer Olson <solson@instructure.com>
QA-Review: Jason Carter <jcarter@instructure.com>
Product-Review: Christi Wruck
This commit is contained in:
Strand McCutchen 2015-11-17 15:28:29 +08:00
parent f4dd6019fc
commit 39ef76a0f2
2 changed files with 71 additions and 26 deletions

View File

@ -850,11 +850,17 @@ class Quizzes::QuizSubmission < ActiveRecord::Base
fixer.run!(self)
end
def due_at
return quiz.due_at if submission.blank?
quiz.overridden_for(submission.user).due_at
end
# TODO: Extract? conceptually similar to Submission::Tardiness#late?
def late?
return false if finished_at.blank?
return false if quiz.due_at.blank?
return false if due_at.blank?
finished_at > quiz.due_at
finished_at > due_at
end
end

View File

@ -643,7 +643,7 @@ describe Quizzes::QuizSubmission do
})
expect(@quiz_submission.submission.workflow_state).to eql 'graded'
end
it "should mark a submission complete if all essay questions have been graded, even if a text_only_question is present" do
quiz_with_graded_submission([{:question_data => {:name => 'question 1', :points_possible => 1, 'question_type' => 'essay_question'}},
{:question_data => {:name => 'question 2', :points_possible => 1, 'question_type' => 'text_only_question'}}]) do
@ -1559,48 +1559,87 @@ describe Quizzes::QuizSubmission do
end
end
describe "Tardiness" do
let(:course) { Course.create! }
let(:now) { Time.zone.now }
let(:quiz) { course.quizzes.create! due_at: 3.days.ago(now) }
let(:submission) { quiz.quiz_submissions.create! }
describe "#late?" do
let(:course) { Course.create! }
let(:now) { Time.zone.now }
let(:quiz) { course.quizzes.create! due_at: 3.days.ago(now) }
context "for quizzes with a due date" do
let(:quiz_submission) { quiz.quiz_submissions.create! }
describe "#late?" do
it "is not late when on turned in before the due date" do
submission.finished_at = 4.days.ago(now)
submission.save
quiz_submission.finished_at = 4.days.ago(now)
quiz_submission.save
expect(submission.late?).to eq false
expect(quiz_submission.late?).to eq false
end
it "is not late when on turned in exactly at the due date" do
submission.finished_at = 3.days.ago(now)
submission.save
quiz_submission.finished_at = 3.days.ago(now)
quiz_submission.save
expect(submission.late?).to eq false
expect(quiz_submission.late?).to eq false
end
it "is late when turned in after the due date" do
quiz_submission.finished_at = 2.days.ago(now)
quiz_submission.save
expect(quiz_submission.late?).to eq true
end
it "is not late when unfinished" do
expect(submission.late?).to eq false
expect(quiz_submission.late?).to eq false
end
end
context "for quizzes without a due date" do
let(:quiz) { course.quizzes.create! }
let(:quiz_submission) do
quiz.quiz_submissions.create! do |qs|
qs.finished_at = 3.days.ago(now)
end
end
it "is not late when the quiz has no due date" do
quiz_two = course.quizzes.create!
submission_two = quiz_two.quiz_submissions.create!
submission_two.finished_at = 3.days.ago(now)
submission_two.save
expect(submission_two.late?).to eq false
expect(quiz_submission.late?).to eq false
end
end
context "for quizzes with overridden due dates for some students" do
let(:quiz_submission) do
quiz.quiz_submissions.create! do |qs|
qs.user = student
qs.finished_at = 1.week.ago(now)
end
end
it "is late when on turned in after the due date" do
submission.finished_at = 2.days.ago(now)
submission.save
let(:student) { User.create! }
expect(submission.late?).to eq true
let!(:enroll_student) do
course.enroll_user student, 'StudentEnrollment'
end
let!(:override_students_quiz) do
assignment_override = quiz.assignment_overrides.create! do |override|
override.due_at = 3.weeks.ago(now)
override.due_at_overridden = true
end
assignment_override.assignment_override_students.create! do |aos|
aos.quiz = quiz
aos.user = student
end
end
it "is late when it's overridden due date is before the submission" do
submission = stub("blank?" => false, "user" => student)
quiz_submission.stubs(:submission).returns(submission)
expect(quiz_submission.late?).to eq true
end
end
end
describe '#excused?' do
let(:submission) do
s=Submission.new