2016-07-31 09:56:02 -05:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
|
|
|
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
|
|
|
|
|
2016-08-16 17:09:40 -05:00
|
|
|
test 'should logout and reset session' do
|
|
|
|
setup_auth
|
|
|
|
get recruiter_logout_path
|
|
|
|
|
|
|
|
assert :success
|
|
|
|
assert session[:user].nil?
|
|
|
|
end
|
|
|
|
|
2016-07-31 09:56:02 -05:00
|
|
|
test "should require auth or redirect" do
|
|
|
|
get recruiter_url
|
|
|
|
assert_redirected_to recruiter_login_path
|
|
|
|
|
|
|
|
get new_candidate_url
|
|
|
|
assert_redirected_to recruiter_login_path
|
|
|
|
|
|
|
|
post create_candidate_url, params: { candidate: { name: 'foo', email: 'bar', experience: 'baz' } }
|
|
|
|
assert_redirected_to recruiter_login_path
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should auth to index" do
|
|
|
|
setup_auth
|
|
|
|
assert_redirected_to recruiter_path
|
|
|
|
assert session[:user].present?
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should fail auth with flash" do
|
|
|
|
post recruiter_auth_url, params: { auth:
|
|
|
|
{ email: 'pdr.recruiter@mailinator.com', password: 'bad-password' } }
|
|
|
|
|
|
|
|
assert_redirected_to recruiter_login_path
|
|
|
|
assert flash[:error]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should get candidate list" do
|
|
|
|
setup_auth
|
|
|
|
get recruiter_url
|
|
|
|
assert_response :success
|
2016-08-17 13:58:25 -05:00
|
|
|
assert assigns(:candidates), "@candidates not present"
|
2016-07-31 09:56:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "should get new" do
|
|
|
|
setup_auth
|
|
|
|
get new_candidate_url
|
|
|
|
assert_response :success
|
2016-08-17 13:58:25 -05:00
|
|
|
assert assigns(:candidate), "@candidate not present"
|
2016-07-31 09:56:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "should get create" do
|
|
|
|
setup_auth
|
|
|
|
get create_candidate_url
|
|
|
|
assert_response :success
|
|
|
|
end
|
2016-07-31 14:47:15 -05:00
|
|
|
|
|
|
|
test "should create new candidate" do
|
|
|
|
setup_auth
|
2016-08-16 17:09:40 -05:00
|
|
|
|
2016-08-02 11:48:18 -05:00
|
|
|
assert_difference("ActionMailer::Base.deliveries.size", 2) do
|
|
|
|
assert_difference("Candidate.count") do
|
|
|
|
post create_candidate_path, params: { candidate:
|
|
|
|
{ name: 'new name', email: 'test@mailinator.com', experience: '0-3', quiz_id: quizzes(:fed).id } }
|
|
|
|
end
|
2016-07-31 14:47:15 -05:00
|
|
|
end
|
|
|
|
assert_redirected_to recruiter_path
|
|
|
|
assert flash[:notice]
|
|
|
|
end
|
2016-08-16 17:09:40 -05:00
|
|
|
|
|
|
|
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
|
2016-08-17 13:58:25 -05:00
|
|
|
assert assigns(:candidate), "@candidate not present"
|
2016-08-16 17:09:40 -05:00
|
|
|
assert_match(/failed.*save/i, flash[:error])
|
|
|
|
end
|
2016-07-31 09:56:02 -05:00
|
|
|
end
|