allow students to see answers after final attempt

fixes CNVS-19091

test plan:
  - make a quiz where correct answers are visible
    after a final attempt and give them two attempts
    - include some questions that require manual
      grading and some that do not
  - as a student submit two attempts
  - note that you do NOT get an error saying
    'Answers will be shown after your last attempt'
    once you have submitted your second attempt

Change-Id: I4ed1c7c775ef730afb963ed1d15f844e2244602f
Reviewed-on: https://gerrit.instructure.com/55480
Tested-by: Jenkins
Reviewed-by: Brian Finney <bfinney@instructure.com>
QA-Review: Michael Hargiss <mhargiss@instructure.com>
Product-Review: Hilary Scharton <hilary@instructure.com>
This commit is contained in:
Michael Nomitch 2015-06-01 17:20:17 -05:00 committed by Mike Nomitch
parent 9786c83114
commit ea246c32d5
5 changed files with 24 additions and 12 deletions

View File

@ -122,8 +122,10 @@ module QuizzesHelper
end end
end end
def render_correct_answer_protection(quiz) def render_correct_answer_protection(quiz, submission)
return I18n.t('Answers will be shown after your last attempt') if quiz.show_correct_answers_last_attempt if quiz.show_correct_answers_last_attempt && !submission.last_attempt_completed?
return I18n.t('Answers will be shown after your last attempt')
end
show_at = quiz.show_correct_answers_at show_at = quiz.show_correct_answers_at
hide_at = quiz.hide_correct_answers_at hide_at = quiz.hide_correct_answers_at
now = Time.now now = Time.now

View File

@ -352,8 +352,9 @@ class Quizzes::Quiz < ActiveRecord::Base
return false unless self.show_correct_answers return false unless self.show_correct_answers
if user.present? && self.show_correct_answers_last_attempt && quiz_submission = user.quiz_submissions.where(quiz_id: self.id).first quiz_submission = user.present? && user.quiz_submissions.where(quiz_id: self.id).first
return quiz_submission.attempts_left == 0 && quiz_submission.complete? if self.show_correct_answers_last_attempt && quiz_submission
return quiz_submission.attempts_left == 0 && quiz_submission.completed?
end end
# If we're showing the results only one time, and are letting students # If we're showing the results only one time, and are letting students

View File

@ -229,12 +229,16 @@ class Quizzes::QuizSubmission < ActiveRecord::Base
# prevents the student from starting to take the quiz for the last # prevents the student from starting to take the quiz for the last
# time, then opening a new tab and looking at the results from # time, then opening a new tab and looking at the results from
# a prior attempt) # a prior attempt)
!quiz.allowed_attempts || quiz.allowed_attempts < 1 || attempt > quiz.allowed_attempts || (completed? && attempt == quiz.allowed_attempts) !quiz.allowed_attempts || quiz.allowed_attempts < 1 || attempt > quiz.allowed_attempts || last_attempt_completed?
else else
true true
end end
end end
def last_attempt_completed?
completed? && quiz.allowed_attempts && attempt >= quiz.allowed_attempts
end
def self.needs_grading def self.needs_grading
resp = where("( resp = where("(
quiz_submissions.workflow_state = 'untaken' quiz_submissions.workflow_state = 'untaken'

View File

@ -5,8 +5,8 @@
<% if correct_answers_protected? %> <% if correct_answers_protected? %>
<div class="alert"> <div class="alert">
<i class="icon-warning" aria-label="<%= render_correct_answer_protection(@quiz) %>"></i> <i class="icon-warning" aria-label="<%= render_correct_answer_protection(@quiz, (@current_submission || @submission)) %>"></i>
<span><%= render_correct_answer_protection(@quiz) %></span> <span><%= render_correct_answer_protection(@quiz, (@current_submission || @submission)) %></span>
</div> </div>
<% end %> <% end %>

View File

@ -398,8 +398,9 @@ describe QuizzesHelper do
quiz = stub({ quiz = stub({
show_correct_answers_last_attempt: true, show_correct_answers_last_attempt: true,
}) })
quiz_submission = stub(last_attempt_completed?: false)
message = render_correct_answer_protection(quiz) message = render_correct_answer_protection(quiz, quiz_submission)
expect(message).to match /last attempt/ expect(message).to match /last attempt/
end end
it 'should provide a useful message when "no"' do it 'should provide a useful message when "no"' do
@ -409,8 +410,9 @@ describe QuizzesHelper do
show_correct_answers_at: nil, show_correct_answers_at: nil,
hide_correct_answers_at: nil hide_correct_answers_at: nil
}) })
quiz_submission = stub(last_attempt_completed?: false)
message = render_correct_answer_protection(quiz) message = render_correct_answer_protection(quiz, quiz_submission)
expect(message).to match /are hidden/ expect(message).to match /are hidden/
end end
@ -421,8 +423,9 @@ describe QuizzesHelper do
show_correct_answers_at: nil, show_correct_answers_at: nil,
hide_correct_answers_at: nil hide_correct_answers_at: nil
}) })
quiz_submission = stub(last_attempt_completed?: false)
message = render_correct_answer_protection(quiz) message = render_correct_answer_protection(quiz, quiz_submission)
expect(message).to eq nil expect(message).to eq nil
end end
@ -433,8 +436,9 @@ describe QuizzesHelper do
show_correct_answers_at: 1.day.from_now, show_correct_answers_at: 1.day.from_now,
hide_correct_answers_at: nil hide_correct_answers_at: nil
}) })
quiz_submission = stub(last_attempt_completed?: false)
message = render_correct_answer_protection(quiz) message = render_correct_answer_protection(quiz, quiz_submission)
expect(message).to match /will be available/ expect(message).to match /will be available/
end end
@ -445,8 +449,9 @@ describe QuizzesHelper do
show_correct_answers_at: nil, show_correct_answers_at: nil,
hide_correct_answers_at: 1.day.from_now hide_correct_answers_at: 1.day.from_now
}) })
quiz_submission = stub(last_attempt_completed?: false)
message = render_correct_answer_protection(quiz) message = render_correct_answer_protection(quiz, quiz_submission)
expect(message).to match /are available until/ expect(message).to match /are available until/
end end
end end