refactor quiz processing

completes #60
This commit is contained in:
Mark Moser
2016-09-02 17:51:35 -05:00
parent 3f8d089701
commit a977c0ceb3
10 changed files with 62 additions and 87 deletions

View File

@ -24,7 +24,7 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
test "should redirect to saved on save" do
setup_auth candidates(:dawn)
qid = questions(:fed5).id
post post_answer_path, params: { save: 'Save', answer: { question_id: qid, radio: 'an option' } }
post post_answer_path, params: { save: 'Save', answer: { question_id: qid, answer: 'an option' } }
assert_redirected_to saved_path
assert session[:test_id].present?
@ -33,7 +33,7 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
test "should redirect to next question on next" do
setup_auth candidates(:roy)
qid = questions(:fed3).id
params = { submit: 'Next', answer: { question_id: qid, live_code: { text: 'stuff' } } }
params = { submit: 'Next', answer: { question_id: qid, answer_hash: { text: 'stuff' } } }
post post_answer_path, params: params
assert_redirected_to question_path
@ -61,7 +61,7 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
test "should get flash message on bad radio response" do
setup_auth candidates(:dawn)
qid = questions(:fed5).id
post post_answer_path, params: { answer: { question_id: qid, radio: nil } }
post post_answer_path, params: { answer: { question_id: qid, answer: nil } }
assert_response :success
assert session[:test_id].present?
@ -73,7 +73,7 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
test "should get flash message on bad text response" do
setup_auth candidates(:dawn)
qid = questions(:fed4).id
post post_answer_path, params: { answer: { question_id: qid, text: nil } }
post post_answer_path, params: { answer: { question_id: qid, answer: nil } }
assert_response :success
assert session[:test_id].present?
@ -85,7 +85,7 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
test "should process checkbox" do
setup_auth candidates(:dawn)
qid = questions(:fed10).id
post post_answer_path, params: { answer: { question_id: qid, checkbox: 'an-option' } }
post post_answer_path, params: { answer: { question_id: qid, answer_array: 'an-option' } }
assert_response :success
assert session[:test_id].present?
@ -96,7 +96,7 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
test 'should handle XHR update and complete progress' do
setup_auth candidates(:peggy)
qid = questions(:fed10).id
post post_answer_path, xhr: true, params: { answer: { question_id: qid, checkbox: ['an-option'] } }
post post_answer_path, xhr: true, params: { answer: { question_id: qid, answer_array: ['an-option'] } }
assert_response :success
assert_match(/updated successfully/, JSON.parse(@response.body)['message'])
@ -108,7 +108,7 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
test 'should handle XHR fail' do
setup_auth candidates(:peggy)
qid = questions(:fed10).id
post post_answer_path, xhr: true, params: { answer: { question_id: qid, checkbox: nil } }
post post_answer_path, xhr: true, params: { answer: { question_id: qid, answer_array: [nil] } }
assert_response 400
assert_match(/select.*answer/i, JSON.parse(@response.body).join)