quiz question types works with groups
fixes CNVS-20948 test plan: - make a quiz with multiple questions and a quiz group with questions of different types in it - ping the API endpoint for this quiz "api/v1/courses/:id/quizzes/:id" - the question_types array contains the types from the quiz group and the types of the non-nested questions Change-Id: I647499707fa024a19fac564688653db3c9f9e4c7 Reviewed-on: https://gerrit.instructure.com/55993 Reviewed-by: Ryan Taylor <rtaylor@instructure.com> Tested-by: Jenkins QA-Review: Michael Hargiss <mhargiss@instructure.com> Product-Review: Ryan Taylor <rtaylor@instructure.com>
This commit is contained in:
parent
f43cf628a5
commit
cc4a9fb949
|
@ -552,9 +552,16 @@ class Quizzes::Quiz < ActiveRecord::Base
|
||||||
# Lists all the question types available in this quiz
|
# Lists all the question types available in this quiz
|
||||||
def question_types
|
def question_types
|
||||||
return [] unless quiz_data
|
return [] unless quiz_data
|
||||||
quiz_data.map do |question|
|
|
||||||
question["question_type"]
|
all_question_types = quiz_data.flat_map do |datum|
|
||||||
end.uniq
|
if datum["entry_type"] == "quiz_group"
|
||||||
|
datum["questions"].map{|q| q["question_type"]}
|
||||||
|
else
|
||||||
|
datum["question_type"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
all_question_types.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_access_code
|
def has_access_code
|
||||||
|
|
|
@ -1066,6 +1066,25 @@ describe Quizzes::Quiz do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#question_types" do
|
||||||
|
before :once do
|
||||||
|
@quiz = @course.quizzes.build :title => "test quiz", :hide_results => 'invalid'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns an empty array when no quiz data" do
|
||||||
|
@quiz.stubs(:quiz_data).returns nil
|
||||||
|
expect(@quiz.question_types).to eq([])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns quiz types of question in quiz groups" do
|
||||||
|
@quiz.stubs(:quiz_data).returns([
|
||||||
|
{"question_type" => "foo"},
|
||||||
|
{"entry_type" => "quiz_group", "questions" => [{"question_type" => "bar"},{"question_type" => "baz"}]}
|
||||||
|
])
|
||||||
|
expect(@quiz.question_types).to eq(["foo", "bar", "baz"])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#has_file_upload_question?" do
|
describe "#has_file_upload_question?" do
|
||||||
|
|
||||||
let(:quiz) { @course.quizzes.build title: 'File Upload Quiz' }
|
let(:quiz) { @course.quizzes.build title: 'File Upload Quiz' }
|
||||||
|
|
Loading…
Reference in New Issue