multiple drop down questions show answers

fixes CNVS-18429

the regex looking for the select tags was busted.
I tried to fix it, but i think this is a better approach

test plan:
 * as a teacher
 - create a quiz with questions of type: multiple drop downs
 * as a student
 - start the quiz and answer some questions, but do not submit
 - navigate away from the page
 - come back to the page
 > the answers you chose should be chosen in the drop downs

Change-Id: I9b0d5e31bc87b2dc00cf73e9f7bc0d23c961cda7
Reviewed-on: https://gerrit.instructure.com/49853
Reviewed-by: Ryan Taylor <rtaylor@instructure.com>
Tested-by: Jenkins
QA-Review: Amber Taniuchi <amber@instructure.com>
Product-Review: Hilary Scharton <hilary@instructure.com>
This commit is contained in:
Cameron Sutter 2015-03-04 11:01:25 -07:00
parent 8447e36bd0
commit 853eb61c38
2 changed files with 12 additions and 7 deletions

View File

@ -446,15 +446,20 @@ module QuizzesHelper
answer_list = hash_get(options, :answer_list)
res = user_content hash_get(question, :question_text)
index = 0
res.to_str.gsub %r{<select.*?name=['"](question_.*?)['"].*?>.*?</select>} do |match|
doc = Nokogiri::HTML.fragment(res)
selects = doc.css(".question_input")
selects.each do |s|
if answer_list && !answer_list.empty?
a = answer_list[index]
index += 1
else
a = hash_get(answers, $1)
question_id = s["name"]
a = hash_get(answers, question_id)
end
match.sub(%r{(<option.*?value=['"]#{ERB::Util.h(a)}['"])}, '\\1 selected')
end.html_safe
opt_tag = s.children.css("option[value='#{a}']").first
opt_tag["selected"] = "selected"
end
doc.to_s.html_safe
end
def duration_in_minutes(duration_seconds)
@ -551,7 +556,7 @@ module QuizzesHelper
def score_to_keep_message(quiz=@quiz)
case quiz.scoring_policy
when "keep_highest"
I18n.t("Will keep the highest of all your scores")
I18n.t("Will keep the highest of all your scores")
when "keep_latest"
I18n.t("Will keep the latest of all your scores")
when "keep_average"

View File

@ -253,9 +253,9 @@ describe QuizzesHelper do
end
it "should select the user's answer" do
html = multiple_dropdowns_question(question: { question_text: "some <select name='question_4'><option value='val'>val</option></select>"},
html = multiple_dropdowns_question(question: { question_text: 'some <select class="question_input" name="question_4"><option value="val">val</option></select>'},
answer_list: ['val'])
expect(html).to eq "some <select name='question_4'><option value='val' selected>val</option></select>"
expect(html).to eq 'some <select class="question_input" name="question_4"><option value="val" selected>val</option></select>'
expect(html).to be_html_safe
end
end