correctly prepare quiz questions when copying course
some quiz questions weren't being processed for import correctly because they were pointing to an AQ and expected to get the AQ question data Test Plan: * Create some quizzes with images in the questions * Copy the course * The new course should have the images in the quiz questions closes #8476 Change-Id: Ieaaef88f9551afa79aa8daab8b784ce388857f48 Reviewed-on: https://gerrit.instructure.com/10591 Reviewed-by: Brian Palmer <brianp@instructure.com> Tested-by: Jenkins <jenkins@instructure.com>
This commit is contained in:
parent
873f374da4
commit
38ab6c39ce
|
@ -543,6 +543,8 @@ class AssessmentQuestion < ActiveRecord::Base
|
|||
answer[field] = ImportedHtmlConverter.convert(answer[field], context, true) if answer[field].present?
|
||||
end
|
||||
end if hash[:answers]
|
||||
hash[:prepped_for_import] = true
|
||||
hash
|
||||
end
|
||||
|
||||
named_scope :active, lambda {
|
||||
|
|
|
@ -1181,11 +1181,11 @@ class Quiz < ActiveRecord::Base
|
|||
if qq[:assessment_question_migration_id]
|
||||
if aq = question_data[:aq_data][qq[:assessment_question_migration_id]]
|
||||
qq['assessment_question_id'] = aq['assessment_question_id']
|
||||
AssessmentQuestion.prep_for_import(qq, context)
|
||||
QuizQuestion.import_from_migration(qq, context, item)
|
||||
aq_hash = AssessmentQuestion.prep_for_import(qq, context)
|
||||
QuizQuestion.import_from_migration(aq_hash, context, item)
|
||||
else
|
||||
AssessmentQuestion.import_from_migration(qq, context)
|
||||
QuizQuestion.import_from_migration(qq, context, item)
|
||||
aq_hash = AssessmentQuestion.import_from_migration(qq, context)
|
||||
QuizQuestion.import_from_migration(aq_hash, context, item)
|
||||
end
|
||||
end
|
||||
elsif aq = question_data[:aq_data][question[:migration_id]]
|
||||
|
|
|
@ -115,11 +115,11 @@ class QuizGroup < ActiveRecord::Base
|
|||
if qq[:assessment_question_migration_id]
|
||||
if aq = question_data[:aq_data][qq[:assessment_question_migration_id]]
|
||||
qq['assessment_question_id'] = aq['assessment_question_id']
|
||||
AssessmentQuestion.prep_for_import(qq, context)
|
||||
QuizQuestion.import_from_migration(qq, context, quiz, item)
|
||||
aq_hash = AssessmentQuestion.prep_for_import(qq, context)
|
||||
QuizQuestion.import_from_migration(aq_hash, context, quiz, item)
|
||||
else
|
||||
AssessmentQuestion.import_from_migration(qq, context)
|
||||
QuizQuestion.import_from_migration(qq, context, quiz, item)
|
||||
aq_hash = AssessmentQuestion.import_from_migration(qq, context)
|
||||
QuizQuestion.import_from_migration(aq_hash, context, quiz, item)
|
||||
end
|
||||
end
|
||||
elsif aq = question_data[:aq_data][question[:migration_id]]
|
||||
|
|
|
@ -137,6 +137,9 @@ class QuizQuestion < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.import_from_migration(hash, context, quiz=nil, quiz_group=nil)
|
||||
unless hash[:prepped_for_import]
|
||||
AssessmentQuestion.prep_for_import(hash, context)
|
||||
end
|
||||
question_data = self.connection.quote hash.to_yaml
|
||||
query = "INSERT INTO quiz_questions (quiz_id, quiz_group_id, assessment_question_id, question_data, created_at, updated_at, migration_id, position)"
|
||||
aq_id = hash['assessment_question_id'] ? hash['assessment_question_id'] : 'NULL'
|
||||
|
|
|
@ -665,6 +665,46 @@ describe ContentMigration do
|
|||
aq.question_data['question_text'].should == @question.question_data['question_text']
|
||||
end
|
||||
|
||||
it "should correctly copy quiz question html file references" do
|
||||
pending unless Qti.qti_enabled?
|
||||
att = Attachment.create!(:filename => 'first.jpg', :display_name => "first.jpg", :uploaded_data => StringIO.new('first'), :folder => Folder.root_folders(@copy_from).first, :context => @copy_from)
|
||||
att2 = Attachment.create!(:filename => 'test.jpg', :display_name => "test.jpg", :uploaded_data => StringIO.new('second'), :folder => Folder.root_folders(@copy_from).first, :context => @copy_from)
|
||||
att3 = Attachment.create!(:filename => 'testing.jpg', :display_name => "testing.jpg", :uploaded_data => StringIO.new('test this'), :folder => Folder.root_folders(@copy_from).first, :context => @copy_from)
|
||||
qtext = <<-HTML.strip
|
||||
File ref:<img src="/courses/%s/files/%s/download">
|
||||
different file ref: <img src="/courses/%s/%s">
|
||||
media object: <a id="media_comment_0_l4l5n0wt" class="instructure_inline_media_comment video_comment" href="/media_objects/0_l4l5n0wt">this is a media comment</a>
|
||||
equation: <img class="equation_image" title="Log_216" src="/equation_images/Log_216" alt="Log_216">
|
||||
HTML
|
||||
|
||||
data = {:correct_comments_html => "<strong>correct</strong>",
|
||||
:question_type => "multiple_choice_question",
|
||||
:question_name => "test fun",
|
||||
:name => "test fun",
|
||||
:points_possible => 10,
|
||||
:question_text => qtext % [@copy_from.id, att.id, @copy_from.id, "file_contents/course%20files/test.jpg"],
|
||||
:answers =>
|
||||
[{:migration_id => "QUE_1016_A1", :html => %{File ref:<img src="/courses/#{@copy_from.id}/files/#{att3.id}/download">}, :comments_html =>'<i>comment</i>', :text => "", :weight => 100, :id => 8080},
|
||||
{:migration_id => "QUE_1017_A2", :html => "<strong>html answer 2</strong>", :comments_html =>'<i>comment</i>', :text => "", :weight => 0, :id => 2279}]}.with_indifferent_access
|
||||
|
||||
q1 = @copy_from.quizzes.create!(:title => 'quiz1')
|
||||
qq = q1.quiz_questions.create!
|
||||
qq.write_attribute(:question_data, data)
|
||||
qq.save!
|
||||
|
||||
run_course_copy
|
||||
|
||||
@copy_to.attachments.count.should == 3
|
||||
att_2 = @copy_to.attachments.find_by_migration_id(mig_id(att))
|
||||
att2_2 = @copy_to.attachments.find_by_migration_id(mig_id(att2))
|
||||
att3_2 = @copy_to.attachments.find_by_migration_id(mig_id(att3))
|
||||
|
||||
q_to = @copy_to.quizzes.first
|
||||
qq_to = q_to.quiz_questions.first
|
||||
qq_to.question_data[:question_text].should == qtext % [@copy_to.id, att_2.id, @copy_to.id, "files/#{att2_2.id}/preview"]
|
||||
qq_to.question_data[:answers][0][:html].should == %{File ref:<img src="/courses/#{@copy_to.id}/files/#{att3_2.id}/download">}
|
||||
end
|
||||
|
||||
it "should copy all html fields in assessment questions" do
|
||||
pending unless Qti.qti_enabled?
|
||||
@bank = @copy_from.assessment_question_banks.create!(:title => 'Test Bank')
|
||||
|
|
|
@ -120,7 +120,7 @@ describe Qti::Converter do
|
|||
quiz = @course.quizzes.last
|
||||
quiz.should be_present
|
||||
quiz.quiz_questions.size.should == 9
|
||||
match_ignoring(quiz.quiz_questions.map(&:question_data), RESPONDUS_QUESTIONS, %w[id assessment_question_id match_id])
|
||||
match_ignoring(quiz.quiz_questions.map(&:question_data), RESPONDUS_QUESTIONS, %w[id assessment_question_id match_id prepped_for_import])
|
||||
end
|
||||
|
||||
def match_ignoring(a, b, ignoring = [])
|
||||
|
|
Loading…
Reference in New Issue