Allow outcome result details for Quiz alignments

Fixes CNVS-25911

Test plan:

Align an outcome to a question bank
Create a quiz
Import question bank into quiz
Have student take quiz
Go to outcome show page
Click on the quiz result within "Artifacts"
Should redirect to quiz submission, not show error

Change-Id: Ibb25d4fae21ccce29d49325bd593de3eafd866e3
Reviewed-on: https://gerrit.instructure.com/70093
Reviewed-by: John Corrigan <jcorrigan@instructure.com>
QA-Review: Deepeeca Soundarrajan <dsoundarrajan@instructure.com>
Tested-by: Jenkins
Product-Review: McCall Smith <mcsmith@instructure.com>
This commit is contained in:
Michael Brewer-Davis 2016-01-12 09:19:41 -06:00
parent 1de51751a3
commit 154d34fa26
5 changed files with 114 additions and 27 deletions

View File

@ -199,15 +199,31 @@ class OutcomesController < ApplicationController
redirect_to named_context_url(@result.context, :context_assignment_submission_url, @submission.assignment_id, @submission.user_id) redirect_to named_context_url(@result.context, :context_assignment_submission_url, @submission.assignment_id, @submission.user_id)
elsif @result.artifact.is_a?(Quizzes::QuizSubmission) && @result.associated_asset elsif @result.artifact.is_a?(Quizzes::QuizSubmission) && @result.associated_asset
@submission = @result.artifact @submission = @result.artifact
@question = @result.associated_asset @asset = @result.associated_asset
if @submission.attempt <= @result.attempt if @submission.attempt <= @result.attempt
@submission_version = @submission @submission_version = @submission
else else
@submission_version = @submission.submitted_attempts.detect{|s| s.attempt >= @result.attempt } @submission_version = @submission.submitted_attempts.detect{|s| s.attempt >= @result.attempt }
end end
question = @submission.quiz_data.detect{|q| q['assessment_question_id'] == @question.data[:id] } if @asset.is_a?(Quizzes::Quiz) && @result.alignment && @result.alignment.content_type == 'AssessmentQuestionBank'
question_id = (question && question['id']) || @question.data[:id] # anchor to first question in aligned bank
redirect_to named_context_url(@result.context, :context_quiz_history_url, @submission.quiz_id, :quiz_submission_id => @submission.id, :version => @submission_version.version_number, :anchor => "question_#{question_id}") question_bank_id = @result.alignment.content_id
first_aligned_question = Quizzes::QuizQuestion.where(quiz_id: @asset.id)
.joins(:assessment_question)
.where(assessment_questions: { assessment_question_bank_id: question_bank_id })
.order(:position)
.first
anchor = first_aligned_question ? "question_#{first_aligned_question.id}" : nil
elsif @asset.is_a? AssessmentQuestion
question = @submission.quiz_data.detect{|q| q['assessment_question_id'] == @asset.data[:id] }
question_id = (question && question['id']) || @asset.data[:id]
anchor = "question_#{question_id}"
end
redirect_to named_context_url(
@result.context, :context_quiz_history_url, @submission.quiz_id,
:quiz_submission_id => @submission.id,
:version => @submission_version.version_number,
:anchor => anchor)
else else
flash[:error] = "Unrecognized artifact type: #{@result.try(:artifact_type) || 'nil'}" flash[:error] = "Unrecognized artifact type: #{@result.try(:artifact_type) || 'nil'}"
redirect_to named_context_url(@context, :context_outcome_url, @outcome.id) redirect_to named_context_url(@context, :context_outcome_url, @outcome.id)

View File

@ -105,7 +105,6 @@ describe OutcomesController do
it "should include tags from courses when viewed in the account" do it "should include tags from courses when viewed in the account" do
account_outcome account_outcome
@outcome
quiz = @course.quizzes.create! quiz = @course.quizzes.create!
alignment = @outcome.align(quiz, @course) alignment = @outcome.align(quiz, @course)
@ -296,4 +295,43 @@ describe OutcomesController do
expect(@outcome).to be_deleted expect(@outcome).to be_deleted
end end
end end
describe "GET 'outcome_result" do
before :each do
course_outcome
end
context "with a quiz result" do
before :each do
assessment_question_bank_with_questions
@outcome.align(@bank, @bank.context, :mastery_score => 0.7)
@quiz = @course.quizzes.create!(:title => "a quiz")
@quiz.add_assessment_questions [ @q1, @q2 ]
@submission = @quiz.generate_submission @student
@submission.quiz_data = @quiz.generate_quiz_data
@submission.mark_completed
Quizzes::SubmissionGrader.new(@submission).grade_submission
end
it "should require teacher authorization" do
user_session(@student)
get 'outcome_result',
:course_id => @course.id,
:outcome_id => @outcome.id,
:id => @outcome.learning_outcome_results.last
assert_unauthorized
end
it "should redirect to show quiz when result is a quiz" do
user_session(@teacher)
get 'outcome_result',
:course_id => @course.id,
:outcome_id => @outcome.id,
:id => @outcome.learning_outcome_results.last
expect(response).to redirect_to(/#{Regexp.quote(course_quiz_history_url(quiz_id: @submission.quiz_id))}/)
end
end
end
end end

View File

@ -0,0 +1,42 @@
# coding: utf-8
#
# Copyright (C) 2011 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/>.
#
def assessment_question_bank_model
@course ||= course_model(:reusable => true)
@bank = @course.assessment_question_banks.create!(:title=>'Test Bank')
end
def assessment_question_bank_with_questions
@bank ||= assessment_question_bank_model
# create a bunch of questions to make it more likely that they'll shuffle randomly
# define @q1..@q10
(1..10).each do |i|
q = @bank.assessment_questions.create!(
:question_data => {
'name' => "test question #{i}",
'points_possible' => 10,
'answers' => [{'id' => 1}, {'id' => 2}]
}
)
instance_variable_set("@q#{i}", q)
end
@bank
end

View File

@ -40,9 +40,9 @@ def quiz_with_submission(complete_quiz = true)
@course.enroll_student(@student).accept @course.enroll_student(@student).accept
@quiz = @course.quizzes.create @quiz = @course.quizzes.create
@quiz.workflow_state = "available" @quiz.workflow_state = "available"
@quiz.quiz_data = test_data @quiz.quiz_questions.create!({ question_data: test_data.first })
@quiz.save! @quiz.save!
@quiz
@qsub = Quizzes::SubmissionManager.new(@quiz).find_or_create_submission(@student) @qsub = Quizzes::SubmissionManager.new(@quiz).find_or_create_submission(@student)
@qsub.quiz_data = test_data @qsub.quiz_data = test_data
@qsub.submission_data = complete_quiz ? [{:points=>0, :text=>"7051", :question_id=>128, :correct=>false, :answer_id=>7051}] : test_data.first @qsub.submission_data = complete_quiz ? [{:points=>0, :text=>"7051", :question_id=>128, :correct=>false, :answer_id=>7051}] : test_data.first

View File

@ -21,22 +21,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe AssessmentQuestionBank do describe AssessmentQuestionBank do
before :once do before :once do
course course
assessment_question_bank_model
@bank = @course.assessment_question_banks.create!(:title=>'Test Bank') @bank = @course.assessment_question_banks.create!(:title=>'Test Bank')
end end
describe "#select_for_submission" do describe "#select_for_submission" do
before :once do before :once do
# create a bunch of questions to make it more likely that they'll shuffle randomly assessment_question_bank_with_questions
@q1 = @bank.assessment_questions.create!(:question_data => {'name' => 'test question 1', 'answers' => [{'id' => 1}, {'id' => 2}]})
@q2 = @bank.assessment_questions.create!(:question_data => {'name' => 'test question 2', 'answers' => [{'id' => 3}, {'id' => 4}]})
@q3 = @bank.assessment_questions.create!(:question_data => {'name' => 'test question 3', 'answers' => [{'id' => 3}, {'id' => 4}]})
@q4 = @bank.assessment_questions.create!(:question_data => {'name' => 'test question 4', 'answers' => [{'id' => 3}, {'id' => 4}]})
@q5 = @bank.assessment_questions.create!(:question_data => {'name' => 'test question 5', 'answers' => [{'id' => 3}, {'id' => 4}]})
@q6 = @bank.assessment_questions.create!(:question_data => {'name' => 'test question 6', 'answers' => [{'id' => 3}, {'id' => 4}]})
@q7 = @bank.assessment_questions.create!(:question_data => {'name' => 'test question 7', 'answers' => [{'id' => 3}, {'id' => 4}]})
@q8 = @bank.assessment_questions.create!(:question_data => {'name' => 'test question 8', 'answers' => [{'id' => 3}, {'id' => 4}]})
@q9 = @bank.assessment_questions.create!(:question_data => {'name' => 'test question 9', 'answers' => [{'id' => 3}, {'id' => 4}]})
@q10 = @bank.assessment_questions.create!(:question_data => {'name' => 'test question 10', 'answers' => [{'id' => 3}, {'id' => 4}]})
@quiz = @course.quizzes.create!(:title => "some quiz") @quiz = @course.quizzes.create!(:title => "some quiz")
@group = @quiz.quiz_groups.create!(:name => "question group", :pick_count => 3, :question_points => 5.0) @group = @quiz.quiz_groups.create!(:name => "question group", :pick_count => 3, :question_points => 5.0)
@group.assessment_question_bank = @bank @group.assessment_question_bank = @bank