test suite refactor
This commit is contained in:
parent
9db007489f
commit
27ef8565f3
@ -56,7 +56,7 @@ guard 'livereload' do
|
||||
end
|
||||
|
||||
guard :minitest, spring: "bin/rails test", all_after_pass: true do
|
||||
watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
||||
watch(%r{^app/(.+)\.rb$}) { |m| ["test/#{m[1]}", "test/#{m[1]}_test.rb"] }
|
||||
watch(%r{^app/controllers/(admin|application)_controller\.rb$}) { 'test/controllers' }
|
||||
watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
|
||||
watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
|
||||
|
@ -40,7 +40,6 @@ class QuizController < ApplicationController
|
||||
ReviewerMailer.candidate_submission(current_candidate).deliver_later
|
||||
return true
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
def prep_question qid
|
||||
|
@ -2,12 +2,6 @@
|
||||
require 'test_helper'
|
||||
|
||||
class CandidateControllerTest < ActionDispatch::IntegrationTest
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
def setup_auth candidate
|
||||
post validate_candidate_url, params: { test_id: candidate.test_hash }
|
||||
end
|
||||
|
||||
test "should get login" do
|
||||
get login_path
|
||||
assert_response :success
|
||||
@ -23,7 +17,7 @@ class CandidateControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should auth to welcome" do
|
||||
setup_auth candidates(:martha)
|
||||
auth_candidate candidates(:martha)
|
||||
|
||||
assert_redirected_to welcome_path
|
||||
assert session[:test_id].present?
|
||||
@ -39,56 +33,30 @@ class CandidateControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should display welcome view" do
|
||||
setup_auth candidates(:martha)
|
||||
auth_candidate candidates(:martha)
|
||||
get welcome_path
|
||||
|
||||
assert_select '.prft-heading', "Welcome!"
|
||||
end
|
||||
|
||||
test "should display welcome back view" do
|
||||
setup_auth candidates(:roy)
|
||||
auth_candidate candidates(:roy)
|
||||
get welcome_path
|
||||
|
||||
assert_select '.prft-heading', "Welcome Back"
|
||||
end
|
||||
|
||||
test "should redirect to thankyou when completed" do
|
||||
setup_auth candidates(:richard)
|
||||
auth_candidate candidates(:richard)
|
||||
|
||||
assert_redirected_to thankyou_path
|
||||
end
|
||||
|
||||
test 'should reset session' do
|
||||
setup_auth candidates(:dawn)
|
||||
auth_candidate 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)
|
||||
|
||||
get summary_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should NOT send mailers on submission" do
|
||||
setup_auth candidates(:dawn)
|
||||
|
||||
assert_enqueued_jobs 0 do
|
||||
post post_summary_path
|
||||
end
|
||||
assert_redirected_to summary_path
|
||||
assert_match 'must complete', flash[:error]
|
||||
end
|
||||
|
||||
test "should send mailers on submission" do
|
||||
setup_auth candidates(:peggy)
|
||||
|
||||
assert_enqueued_jobs 3 do
|
||||
post post_summary_path
|
||||
end
|
||||
assert_redirected_to thankyou_path
|
||||
end
|
||||
end
|
||||
|
25
test/controllers/quiz_controller/get_question_test.rb
Normal file
25
test/controllers/quiz_controller/get_question_test.rb
Normal file
@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
require 'test_helper'
|
||||
|
||||
class QuizControllerTest < ActionDispatch::IntegrationTest
|
||||
test "should require auth and redirect" do
|
||||
get question_path
|
||||
assert_redirected_to login_path
|
||||
|
||||
get question_path(questions(:fed1).id)
|
||||
assert_redirected_to login_path
|
||||
end
|
||||
|
||||
test "should redirect to next question on next" do
|
||||
auth_candidate candidates(:roy)
|
||||
qid = questions(:fed3).id
|
||||
params = { submit: 'Next', answer: { question_id: qid, answer_hash: { text: 'stuff' } } }
|
||||
post post_answer_path, params: params
|
||||
|
||||
assert_redirected_to question_path
|
||||
assert session[:test_id].present?
|
||||
assert assigns(:question), '@question not present'
|
||||
assert assigns(:answer), '@answer not present'
|
||||
assert assigns(:status), '@status not present'
|
||||
end
|
||||
end
|
@ -2,23 +2,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class QuizControllerTest < ActionDispatch::IntegrationTest
|
||||
def setup_auth candidate
|
||||
post validate_candidate_url, params: { test_id: candidate.test_hash }
|
||||
end
|
||||
|
||||
test "should require auth and redirect" do
|
||||
get summary_path
|
||||
assert_redirected_to login_path
|
||||
|
||||
get question_path
|
||||
assert_redirected_to login_path
|
||||
|
||||
get question_path(questions(:fed1).id)
|
||||
assert_redirected_to login_path
|
||||
end
|
||||
|
||||
test "should redirect to saved on save" do
|
||||
setup_auth candidates(:dawn)
|
||||
auth_candidate candidates(:dawn)
|
||||
qid = questions(:fed5).id
|
||||
post post_answer_path, params: { save: 'Save', answer: { question_id: qid, answer: 'an option' } }
|
||||
|
||||
@ -26,36 +11,8 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
|
||||
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, answer_hash: { text: 'stuff' } } }
|
||||
post post_answer_path, params: params
|
||||
|
||||
assert_redirected_to question_path
|
||||
assert session[:test_id].present?
|
||||
assert assigns(:question), '@question not present'
|
||||
assert assigns(:answer), '@answer not present'
|
||||
assert assigns(:status), '@status not present'
|
||||
end
|
||||
|
||||
test "should get summary" do
|
||||
setup_auth candidates :dawn
|
||||
get summary_path
|
||||
|
||||
assert_response :success
|
||||
assert assigns(:quiz), '@quiz not present'
|
||||
end
|
||||
|
||||
test "should redirect from summary" do
|
||||
setup_auth candidates :roy
|
||||
get summary_path
|
||||
|
||||
assert_redirected_to question_path
|
||||
end
|
||||
|
||||
test "should get flash message on bad radio response" do
|
||||
setup_auth candidates(:dawn)
|
||||
auth_candidate candidates(:dawn)
|
||||
qid = questions(:fed5).id
|
||||
post post_answer_path, params: { answer: { question_id: qid, answer: nil } }
|
||||
|
||||
@ -67,7 +24,7 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should get flash message on bad text response" do
|
||||
setup_auth candidates(:dawn)
|
||||
auth_candidate candidates(:dawn)
|
||||
qid = questions(:fed4).id
|
||||
post post_answer_path, params: { answer: { question_id: qid, answer: nil } }
|
||||
|
||||
@ -79,7 +36,7 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should process checkbox" do
|
||||
setup_auth candidates(:dawn)
|
||||
auth_candidate candidates(:dawn)
|
||||
qid = questions(:fed10).id
|
||||
post post_answer_path, params: { answer: { question_id: qid, answer_array: 'an-option' } }
|
||||
|
||||
@ -90,7 +47,7 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'should handle XHR update and complete progress' do
|
||||
setup_auth candidates(:peggy)
|
||||
auth_candidate candidates(:peggy)
|
||||
qid = questions(:fed10).id
|
||||
post post_answer_path, xhr: true, params: { answer: { question_id: qid, answer_array: ['an-option'] } }
|
||||
|
||||
@ -102,7 +59,7 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'should handle XHR fail' do
|
||||
setup_auth candidates(:peggy)
|
||||
auth_candidate candidates(:peggy)
|
||||
qid = questions(:fed10).id
|
||||
post post_answer_path, xhr: true, params: { answer: { question_id: qid, answer_array: [nil] } }
|
||||
|
52
test/controllers/quiz_controller/summary_test.rb
Normal file
52
test/controllers/quiz_controller/summary_test.rb
Normal file
@ -0,0 +1,52 @@
|
||||
# frozen_string_literal: true
|
||||
require 'test_helper'
|
||||
|
||||
class QuizControllerTest < ActionDispatch::IntegrationTest
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
test 'summary should require auth and redirect' do
|
||||
get summary_path
|
||||
assert_redirected_to login_path
|
||||
end
|
||||
|
||||
test "should get summary" do
|
||||
auth_candidate candidates :dawn
|
||||
get summary_path
|
||||
|
||||
assert_response :success
|
||||
assert assigns(:quiz), '@quiz not present'
|
||||
end
|
||||
|
||||
test "should get summary if complete but not submitted" do
|
||||
auth_candidate candidates(:dawn)
|
||||
|
||||
get summary_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should redirect from summary" do
|
||||
auth_candidate candidates :roy
|
||||
get summary_path
|
||||
|
||||
assert_redirected_to question_path
|
||||
end
|
||||
|
||||
test "should NOT send mailers on submission" do
|
||||
auth_candidate candidates(:dawn)
|
||||
|
||||
assert_enqueued_jobs 0 do
|
||||
post post_summary_path
|
||||
end
|
||||
assert_redirected_to summary_path
|
||||
assert_match 'must complete', flash[:error]
|
||||
end
|
||||
|
||||
test "should send mailers on submission" do
|
||||
auth_candidate candidates(:peggy)
|
||||
|
||||
assert_enqueued_jobs 3 do
|
||||
post post_summary_path
|
||||
end
|
||||
assert_redirected_to thankyou_path
|
||||
end
|
||||
end
|
@ -4,18 +4,13 @@ require 'test_helper'
|
||||
class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
def setup_auth
|
||||
post recruiter_auth_url, params: { auth:
|
||||
{ email: 'pdr.recruiter@mailinator.com', password: 'password' } }
|
||||
end
|
||||
|
||||
test "should get login" do
|
||||
get recruiter_login_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test 'should logout and reset session' do
|
||||
setup_auth
|
||||
auth_recruiter
|
||||
get recruiter_logout_path
|
||||
|
||||
assert :success
|
||||
@ -34,7 +29,7 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should auth to index" do
|
||||
setup_auth
|
||||
auth_recruiter
|
||||
assert_redirected_to recruiter_path
|
||||
assert session[:user].present?
|
||||
end
|
||||
@ -48,27 +43,27 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should get candidate list" do
|
||||
setup_auth
|
||||
auth_recruiter
|
||||
get recruiter_url
|
||||
assert_response :success
|
||||
assert assigns(:candidates), "@candidates not present"
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
setup_auth
|
||||
auth_recruiter
|
||||
get new_candidate_url
|
||||
assert_response :success
|
||||
assert assigns(:candidate), "@candidate not present"
|
||||
end
|
||||
|
||||
test "should get create" do
|
||||
setup_auth
|
||||
auth_recruiter
|
||||
get create_candidate_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create new candidate" do
|
||||
setup_auth
|
||||
auth_recruiter
|
||||
|
||||
assert_enqueued_jobs 2 do
|
||||
assert_difference("Candidate.count") do
|
||||
@ -81,7 +76,7 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should fail creation with improper email format" do
|
||||
setup_auth
|
||||
auth_recruiter
|
||||
|
||||
assert_enqueued_jobs 0 do
|
||||
assert_difference("Candidate.count", 0) do
|
||||
@ -95,7 +90,7 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should fail creation gracefully with empty email" do
|
||||
setup_auth
|
||||
auth_recruiter
|
||||
|
||||
assert_enqueued_jobs 0 do
|
||||
assert_difference("Candidate.count", 0) do
|
||||
|
@ -2,11 +2,6 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ReviewControllerTest < ActionDispatch::IntegrationTest
|
||||
def setup_auth
|
||||
post review_auth_url, params: { auth:
|
||||
{ email: 'fed.reviewer@mailinator.com', password: 'password' } }
|
||||
end
|
||||
|
||||
test "should get login" do
|
||||
get review_login_url
|
||||
assert_response :success
|
||||
@ -21,7 +16,7 @@ class ReviewControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should auth to index" do
|
||||
setup_auth
|
||||
auth_reviewer
|
||||
assert_redirected_to review_path
|
||||
assert session[:user].present?
|
||||
end
|
||||
@ -35,21 +30,21 @@ class ReviewControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should get review list" do
|
||||
setup_auth
|
||||
auth_reviewer
|
||||
get review_url
|
||||
assert_response :success
|
||||
assert assigns(:candidates), '@candidates not present'
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
setup_auth
|
||||
auth_reviewer
|
||||
|
||||
get review_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get view" do
|
||||
setup_auth
|
||||
auth_reviewer
|
||||
|
||||
get review_test_url(candidates(:richard).test_hash)
|
||||
assert_response :success
|
||||
@ -59,7 +54,7 @@ class ReviewControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'should logout and reset session' do
|
||||
setup_auth
|
||||
auth_reviewer
|
||||
get review_logout_path
|
||||
|
||||
assert :success
|
||||
|
@ -2,12 +2,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class QuestionAttachmentsTest < ActionDispatch::IntegrationTest
|
||||
def setup_auth candidate
|
||||
post validate_candidate_url, params: { test_id: candidate.test_hash }
|
||||
end
|
||||
|
||||
test "should show attachments on question" do
|
||||
setup_auth candidates(:dawn)
|
||||
auth_candidate candidates(:dawn)
|
||||
|
||||
get question_path questions(:fed6)
|
||||
assert_response :success
|
||||
@ -16,7 +12,7 @@ class QuestionAttachmentsTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should show attachments on summary" do
|
||||
setup_auth candidates(:dawn)
|
||||
auth_candidate candidates(:dawn)
|
||||
|
||||
get summary_path
|
||||
assert_response :success
|
||||
|
@ -2,12 +2,8 @@
|
||||
require 'test_helper'
|
||||
|
||||
class QuestionFlowTest < ActionDispatch::IntegrationTest
|
||||
def setup_auth candidate
|
||||
post validate_candidate_url, params: { test_id: candidate.test_hash }
|
||||
end
|
||||
|
||||
test "should load the first question" do
|
||||
setup_auth candidates(:martha)
|
||||
auth_candidate candidates(:martha)
|
||||
|
||||
get question_path
|
||||
assert_response :success
|
||||
@ -15,7 +11,7 @@ class QuestionFlowTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should load the summary" do
|
||||
setup_auth candidates(:dawn)
|
||||
auth_candidate candidates(:dawn)
|
||||
|
||||
get summary_path
|
||||
assert_response :success
|
||||
@ -23,18 +19,16 @@ class QuestionFlowTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "can load specific question from summary" do
|
||||
setup_auth candidates(:dawn)
|
||||
auth_candidate candidates(:dawn)
|
||||
question = questions(:fed4)
|
||||
|
||||
get question_path(question.id)
|
||||
assert_response :success
|
||||
assert_select '.question-text', question.question
|
||||
# TODO: add in capybara and test form post
|
||||
# assert_redirected summary_path
|
||||
end
|
||||
|
||||
test 'juan should be on summary with 80% complete' do
|
||||
setup_auth candidates(:juan)
|
||||
auth_candidate candidates(:juan)
|
||||
|
||||
get summary_path
|
||||
assert_response :success
|
||||
|
@ -2,23 +2,17 @@
|
||||
require 'test_helper'
|
||||
|
||||
class QuestionLiveCoderTest < ActionDispatch::IntegrationTest
|
||||
def setup_auth candidate
|
||||
post validate_candidate_url, params: { test_id: candidate.test_hash }
|
||||
end
|
||||
|
||||
test "can load a live coder question" do
|
||||
setup_auth candidates(:dawn)
|
||||
auth_candidate candidates(:dawn)
|
||||
question = questions(:fed7)
|
||||
|
||||
get question_path(question.id)
|
||||
assert_response :success
|
||||
assert_select '.question-text', question.question
|
||||
# TODO: add in capybara and test form post
|
||||
# assert_redirected summary_path
|
||||
end
|
||||
|
||||
test "should load seed data into live coder" do
|
||||
setup_auth candidates(:juan)
|
||||
auth_candidate candidates(:juan)
|
||||
question = questions(:fed7)
|
||||
|
||||
get question_path(question.id)
|
||||
|
@ -24,4 +24,5 @@ class ActiveSupport::TestCase
|
||||
fixtures :all
|
||||
|
||||
# Add more helper methods to be used by all tests here...
|
||||
include AuthTestHelper
|
||||
end
|
||||
|
16
test/test_helpers/auth_test_helper.rb
Normal file
16
test/test_helpers/auth_test_helper.rb
Normal file
@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
module AuthTestHelper
|
||||
def auth_candidate candidate
|
||||
post validate_candidate_url, params: { test_id: candidate.test_hash }
|
||||
end
|
||||
|
||||
def auth_recruiter
|
||||
post recruiter_auth_url, params: { auth:
|
||||
{ email: 'pdr.recruiter@mailinator.com', password: 'password' } }
|
||||
end
|
||||
|
||||
def auth_reviewer
|
||||
post review_auth_url, params: { auth:
|
||||
{ email: 'fed.reviewer@mailinator.com', password: 'password' } }
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user