Skip to content

Commit

Permalink
Don't blow up if a user's answer is not an option
Browse files Browse the repository at this point in the history
Fixes CNVS-19274

Test plan
 - The following should no longer error
  https://ucdenver.instructure.com/courses/16213/gradebook/speed_grader?assignment_id=128057#%7B%22student_id%22%3A%2212288%22%7D

Change-Id: I4b477254398b4bc025d6d692fcbcf986f3b5c28b
Reviewed-on: https://gerrit.instructure.com/50357
Reviewed-by: Cameron Sutter <[email protected]>
Product-Review: Cameron Sutter <[email protected]>
QA-Review: Derek Hansen <[email protected]>
Tested-by: Matt Fairbourn <[email protected]>
  • Loading branch information
yenif authored and mfairbourn committed Mar 14, 2015
1 parent 2f41f13 commit ae0a791
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/helpers/quizzes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,11 @@ def multiple_dropdowns_question(options)
question_id = s["name"]
a = hash_get(answers, question_id)
end
opt_tag = s.children.css("option[value='#{a}']").first
opt_tag["selected"] = "selected"

# If existing answer is one of the options, select it
if opt_tag = s.children.css("option[value='#{a}']").first
opt_tag["selected"] = "selected"
end
end
doc.to_s.html_safe
end
Expand Down
7 changes: 7 additions & 0 deletions spec/helpers/quizzes_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ def user_content(stuff); stuff; end # mock #user_content
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

it "should not blow up if the user's answer isn't there" do
html = multiple_dropdowns_question(question: { question_text: 'some <select class="question_input" name="question_4"><option value="other_val">val</option></select>'},
answer_list: ['val'])
expect(html).to eq 'some <select class="question_input" name="question_4"><option value="other_val">val</option></select>'
expect(html).to be_html_safe
end
end

describe "#quiz_edit_text" do
Expand Down

0 comments on commit ae0a791

Please sign in to comment.