progress on #27: test coverage over 96%
This commit is contained in:
@@ -55,6 +55,14 @@ class CandidateControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to thankyou_path
|
||||
end
|
||||
|
||||
test 'should reset session' do
|
||||
setup_auth candidates(:dawn)
|
||||
get thankyou_path
|
||||
|
||||
assert :success
|
||||
assert session[:test_id].nil?
|
||||
end
|
||||
|
||||
test "should get summary if complete but not submitted" do
|
||||
setup_auth candidates(:dawn)
|
||||
|
||||
|
@@ -16,13 +16,75 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to login_path
|
||||
end
|
||||
|
||||
# TODO: test models/candidate.complete! == false
|
||||
# test 'should gracefully fail on summary submit' do
|
||||
# # if the mailers fail, should go to thank you still
|
||||
# end
|
||||
|
||||
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' } }
|
||||
|
||||
assert_redirected_to saved_path
|
||||
assert session[:test_id].present?
|
||||
end
|
||||
|
||||
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' } } }
|
||||
post post_answer_path, params: params
|
||||
|
||||
assert_redirected_to question_path
|
||||
assert session[:test_id].present?
|
||||
end
|
||||
|
||||
test "should get flash message on bad radio response" do
|
||||
setup_auth candidates(:martha)
|
||||
qid = questions(:fed1).id
|
||||
setup_auth candidates(:dawn)
|
||||
qid = questions(:fed5).id
|
||||
post post_answer_path, params: { answer: { question_id: qid, radio: nil } }
|
||||
|
||||
assert_response :success
|
||||
assert session[:test_id].present?
|
||||
assert_equal qid, flash[:error]
|
||||
end
|
||||
|
||||
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 } }
|
||||
|
||||
assert_response :success
|
||||
assert session[:test_id].present?
|
||||
assert_equal qid, flash[:error]
|
||||
end
|
||||
|
||||
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' } }
|
||||
|
||||
assert_response :success
|
||||
assert session[:test_id].present?
|
||||
end
|
||||
|
||||
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'] } }
|
||||
|
||||
assert_response :success
|
||||
assert_match(/updated successfully/, JSON.parse(@response.body)['message'])
|
||||
assert_equal 100, JSON.parse(@response.body)['progress']
|
||||
end
|
||||
|
||||
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 } }
|
||||
|
||||
assert_response 400
|
||||
assert_match(/select.*answer/i, JSON.parse(@response.body).join)
|
||||
end
|
||||
end
|
||||
|
@@ -11,6 +11,14 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test 'should logout and reset session' do
|
||||
setup_auth
|
||||
get recruiter_logout_path
|
||||
|
||||
assert :success
|
||||
assert session[:user].nil?
|
||||
end
|
||||
|
||||
test "should require auth or redirect" do
|
||||
get recruiter_url
|
||||
assert_redirected_to recruiter_login_path
|
||||
@@ -55,8 +63,8 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should create new candidate" do
|
||||
# recruiter = users(:recruiter)
|
||||
setup_auth
|
||||
|
||||
assert_difference("ActionMailer::Base.deliveries.size", 2) do
|
||||
assert_difference("Candidate.count") do
|
||||
post create_candidate_path, params: { candidate:
|
||||
@@ -66,4 +74,17 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to recruiter_path
|
||||
assert flash[:notice]
|
||||
end
|
||||
|
||||
test "should fail creation with message" do
|
||||
setup_auth
|
||||
|
||||
assert_difference("ActionMailer::Base.deliveries.size", 0) do
|
||||
assert_difference("Candidate.count", 0) do
|
||||
post create_candidate_path, params: { candidate:
|
||||
{ name: 'new name', email: 'test@mailinatorcom', experience: '0-3', quiz_id: quizzes(:fed).id } }
|
||||
end
|
||||
end
|
||||
assert :success
|
||||
assert_match(/failed.*save/i, flash[:error])
|
||||
end
|
||||
end
|
||||
|
@@ -52,4 +52,12 @@ class ReviewControllerTest < ActionDispatch::IntegrationTest
|
||||
get review_test_url(candidates(:richard).test_hash)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test 'should logout and reset session' do
|
||||
setup_auth
|
||||
get review_logout_path
|
||||
|
||||
assert :success
|
||||
assert session[:user].nil?
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user