remove question id from data on clone, fixes #4684

Change-Id: I1ba23dfe1e20b33503b40711098ea7d329a5aba6
Reviewed-on: https://gerrit.instructure.com/3880
Tested-by: Hudson <hudson@instructure.com>
Reviewed-by: Bracken Mosbacker <bracken@instructure.com>
This commit is contained in:
Brian Palmer 2011-05-26 09:46:54 -06:00
parent fffd493232
commit d3d6a266cf
3 changed files with 22 additions and 0 deletions

View File

@ -93,6 +93,7 @@ class QuizQuestion < ActiveRecord::Base
dup.send("#{key}=", val)
end
data = self.question_data || {}
data.delete(:id)
if options[:old_context] && options[:new_context]
data = QuizQuestion.migrate_question_hash(data, options)
end

View File

@ -0,0 +1,19 @@
# some cloned quiz questions mistakenly have the old question id saved to the data hash, causing issues when trying to edit.
class RemoveQuizDataIds < ActiveRecord::Migration
class QuizQuestion < ActiveRecord::Base;
serialize :question_data
end
def self.up
QuizQuestion.find_each do |qq|
data = qq.question_data
if data.is_a?(Hash) && data[:id].present? && data[:id] != qq.id
data[:id] = qq.id
qq.save
end
end
end
def self.down
end
end

View File

@ -389,6 +389,8 @@ describe Quiz do
new_q.title.should eql(q.title)
new_q.quiz_groups.length.should eql(q.quiz_groups.length)
new_q.quiz_questions.length.should eql(q.quiz_questions.length)
new_q.quiz_questions.first.question_data[:id].should be_nil
new_q.quiz_questions.first.data[:id].should == new_q.quiz_questions.first.id
end
it "should set the related assignment's group correctly" do