- <%= link_to candidate.name, edit_candidate_path(candidate.id) %> |
+ <%= link_to candidate.name, admin_edit_candidate_path(candidate.id) %> |
<%= candidate.test_hash %> |
<%= mail_to(candidate.email) %>
- <%= link_to "resend welcome email", resend_welcome_path(candidate.id), remote: true, class: '', data: { id: 'ajax-action' } %>
+ <%= link_to "resend welcome email", admin_resend_welcome_path(candidate.id), remote: true, class: '', data: { id: 'ajax-action' } %>
|
<%= candidate.experience %> years |
<%= candidate.status %> |
diff --git a/app/views/admin/candidate/new.html.erb b/app/views/admin/candidate/new.html.erb
new file mode 100644
index 0000000..c529467
--- /dev/null
+++ b/app/views/admin/candidate/new.html.erb
@@ -0,0 +1,6 @@
+
+ New Candidate
+
+ <%= render partial: 'form', locals:
+ { action: admin_create_candidate_path, candidate: @candidate, quizzes: @quizzes } %>
+
diff --git a/app/views/recruiter/edit.html.erb b/app/views/recruiter/edit.html.erb
deleted file mode 100644
index dc6aff7..0000000
--- a/app/views/recruiter/edit.html.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-
- Edit: <%= @candidate.name %>
- Test ID: <%= @candidate.test_hash %>
-
- <%= render partial: 'form', locals: { action: update_candidate_path(@candidate.id), candidate: @candidate, quizzes: @quizzes } %>
-
diff --git a/app/views/recruiter/login.html.erb b/app/views/recruiter/login.html.erb
deleted file mode 100644
index 9d4098d..0000000
--- a/app/views/recruiter/login.html.erb
+++ /dev/null
@@ -1,21 +0,0 @@
-
- Recruiter Login
-
- <% if flash[:error].present? %>
- <%= flash[:error] %>
- <% end %>
-
- <%= form_for :auth, url: recruiter_login_path do |form| %>
-
- <%= form.label :email %>
- <%= form.email_field :email %>
-
-
-
- <%= form.label :password %>
- <%= form.password_field :password %>
-
-
- <%= submit_tag "Log in" %>
- <% end %>
-
diff --git a/app/views/recruiter/new.html.erb b/app/views/recruiter/new.html.erb
deleted file mode 100644
index 7892256..0000000
--- a/app/views/recruiter/new.html.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-
- New Candidate
-
- <%= render partial: 'form', locals:
- { action: create_candidate_path, candidate: @candidate, quizzes: @quizzes } %>
-
diff --git a/config/routes.rb b/config/routes.rb
index 41c8002..1fd272b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,5 +1,8 @@
# frozen_string_literal: true
Rails.application.routes.draw do
+ get "/styleguide", to: "application#styleguide", as: :styleguide
+ get "/admin/styleguide", to: "application#styleguide"
+
post "/admin/login", to: "admin/auth#auth", as: :admin_auth
get "/admin/login", to: "admin/auth#login", as: :admin_login
get "/admin/logout", to: "admin/auth#logout", as: :admin_logout
@@ -33,26 +36,16 @@ Rails.application.routes.draw do
post "/admin/question/:question_id/edit", to: "admin/question#update", as: :admin_update_question
patch "/admin/question/:question_id/edit", to: "admin/question#update"
- get "/admin/profile", to: "admin/profile#view", as: :admin_profile
- post "/admin/profile", to: "admin/profile#update", as: :admin_update_profile
- get "/admin/profile/edit", to: "admin/profile#edit", as: :admin_edit_profile
+ get "/admin/profile", to: "admin/profile#view", as: :admin_profile
+ post "/admin/profile", to: "admin/profile#update", as: :admin_update_profile
+ get "/admin/profile/edit", to: "admin/profile#edit", as: :admin_edit_profile
- get "/admin", to: "admin/dashboard#show", as: :admin
-
- #########################################################################################
-
- post "/validate", to: "candidate#validate", as: :validate_candidate
- get "/login(/:test_id)", to: "candidate#login", as: :login
- get "/welcome", to: "candidate#welcome", as: :welcome
- get "/saved", to: "candidate#saved", as: :saved
- get "/thankyou", to: "candidate#thankyou", as: :thankyou
-
- get "/oops", to: "candidate#oops", as: :oops
-
- post "/question(/:answer_id)", to: "quiz#update_answer", as: :post_answer
- get "/question(/:question_id)", to: "quiz#question", as: :question
- post "/summary", to: "quiz#submit_summary", as: :post_summary
- get "/summary", to: "quiz#summary", as: :summary
+ get "/admin/candidate", to: "admin/candidate#index", as: :admin_candidate
+ get "/admin/candidate/new", to: "admin/candidate#new", as: :admin_new_candidate
+ post "/admin/candidate/new", to: "admin/candidate#create", as: :admin_create_candidate
+ get "/admin/candidate/:id", to: "admin/candidate#edit", as: :admin_edit_candidate
+ post "/admin/candidate/:id", to: "admin/candidate#update", as: :admin_update_candidate
+ get "/admin/candidate/:id/resend", to: "admin/candidate#resend_welcome", as: :admin_resend_welcome
get "/review/logout", to: "review#logout", as: :review_logout
post "/review/login", to: "review#auth", as: :review_auth
@@ -60,18 +53,21 @@ Rails.application.routes.draw do
get "/review", to: "review#index", as: :review
get "/review/:test_hash", to: "review#view", as: :review_test
- get "/resend/welcome/:id", to: "recruiter#resend_welcome", as: :resend_welcome
+ get "/admin", to: "admin/dashboard#show", as: :admin
- get "/recruiter", to: "recruiter#index", as: :recruiter
- get "/recruiter/candidate", to: "recruiter#new", as: :new_candidate
- post "/recruiter/candidate", to: "recruiter#create", as: :create_candidate
- get "/recruiter/candidate/:id", to: "recruiter#edit", as: :edit_candidate
- post "/recruiter/candidate/:id", to: "recruiter#update", as: :update_candidate
- get "/recruiter/logout", to: "recruiter#logout", as: :recruiter_logout
- get "/recruiter/login", to: "recruiter#login", as: :recruiter_login
- post "/recruiter/login", to: "recruiter#auth", as: :recruiter_auth
+ #########################################################################################
- get "/styleguide", to: "application#styleguide", as: :styleguide
+ post "/validate", to: "candidate#validate", as: :validate_candidate
+ get "/login(/:test_id)", to: "candidate#login", as: :login
+ get "/welcome", to: "candidate#welcome", as: :welcome
+ get "/saved", to: "candidate#saved", as: :saved
+ get "/thankyou", to: "candidate#thankyou", as: :thankyou
+ get "/oops", to: "candidate#oops", as: :oops
+
+ post "/question(/:answer_id)", to: "quiz#update_answer", as: :post_answer
+ get "/question(/:question_id)", to: "quiz#question", as: :question
+ post "/summary", to: "quiz#submit_summary", as: :post_summary
+ get "/summary", to: "quiz#summary", as: :summary
root to: "candidate#login"
diff --git a/test/controllers/admin/candidate_controller/index_test.rb b/test/controllers/admin/candidate_controller/index_test.rb
new file mode 100644
index 0000000..d9c2b11
--- /dev/null
+++ b/test/controllers/admin/candidate_controller/index_test.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+require 'test_helper'
+
+module Admin
+ class CandidateControllerTest < ActionDispatch::IntegrationTest
+ test "should require auth or redirect" do
+ get admin_candidate_url
+ assert_redirected_to admin_login_url
+
+ get admin_new_candidate_url
+ assert_redirected_to admin_login_url
+
+ post admin_create_candidate_url, params: { candidate: { name: 'foo', email: 'bar', experience: 'baz' } }
+ assert_redirected_to admin_login_url
+ end
+
+ test "should get candidate list" do
+ auth_recruiter
+ get admin_candidate_url
+ assert_response :success
+ assert assigns(:candidates), "@candidates not present"
+ end
+
+ test 'should have edit links' do
+ auth_recruiter
+ get admin_candidate_url
+ assert_response :success
+ assert_select "a[href='#{admin_edit_candidate_path(candidates(:martha))}']"
+ end
+ end
+end
diff --git a/test/controllers/admin/candidate_controller/new_candidate_test.rb b/test/controllers/admin/candidate_controller/new_candidate_test.rb
new file mode 100644
index 0000000..50fb582
--- /dev/null
+++ b/test/controllers/admin/candidate_controller/new_candidate_test.rb
@@ -0,0 +1,73 @@
+# frozen_string_literal: true
+require 'test_helper'
+
+module Admin
+ class CandidateControllerTest < ActionDispatch::IntegrationTest
+ include ActiveJob::TestHelper
+
+ test "should get new" do
+ auth_recruiter
+ get admin_new_candidate_url
+ assert_response :success
+ assert assigns(:candidate), "@candidate not present"
+ end
+
+ test "should get create" do
+ auth_recruiter
+ get admin_create_candidate_url
+ assert_response :success
+ end
+
+ test "should create new candidate" do
+ auth_recruiter
+
+ assert_enqueued_jobs 2 do
+ assert_difference("Candidate.count") do
+ post admin_create_candidate_path, params: { candidate:
+ { name: 'new name', email: 'test@mailinator.com', experience: '0-3', quiz_id: quizzes(:fed).id } }
+ end
+ end
+ assert_redirected_to admin_candidate_path
+ assert flash[:success]
+ end
+
+ test "should fail creation with improper email format" do
+ auth_recruiter
+
+ assert_enqueued_jobs 0 do
+ assert_difference("Candidate.count", 0) do
+ post admin_create_candidate_path, params: { candidate:
+ { name: 'new name', email: 'test@mailinatorcom', experience: '0-3', quiz_id: quizzes(:fed).id } }
+ end
+ end
+ assert :success
+ assert assigns(:candidate), "@candidate not present"
+ assert_match(/failed.*save/i, flash[:error])
+ end
+
+ test "should fail creation gracefully with empty email" do
+ auth_recruiter
+
+ assert_enqueued_jobs 0 do
+ assert_difference("Candidate.count", 0) do
+ post admin_create_candidate_path, params: { candidate:
+ { name: 'new name', email: "", experience: '0-3', quiz_id: quizzes(:fed).id } }
+ end
+ end
+ assert :success
+ assert assigns(:candidate), "@candidate not present"
+ assert_match(/failed.*save/i, flash[:error])
+ end
+
+ test 'should queue up a welcome email [resend]' do
+ auth_recruiter
+
+ assert_enqueued_jobs 1 do
+ get admin_resend_welcome_path(id: candidates(:peggy)), xhr: true
+ end
+ assert_response :success
+ data = JSON.parse(response.body)
+ assert_match 'queued', data["message"]
+ end
+ end
+end
diff --git a/test/controllers/admin/candidate_controller/update_candidate_test.rb b/test/controllers/admin/candidate_controller/update_candidate_test.rb
new file mode 100644
index 0000000..25a6efc
--- /dev/null
+++ b/test/controllers/admin/candidate_controller/update_candidate_test.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+require 'test_helper'
+
+module Admin
+ class CandidateControllerTest < ActionDispatch::IntegrationTest
+ test 'should edit candidate' do
+ auth_recruiter
+ candidate = candidates(:martha)
+
+ get admin_edit_candidate_path(candidate.id)
+ assert_response :success
+ assert_select 'form'
+ end
+
+ test 'should update candidate, but NOT test_hash' do
+ auth_recruiter
+ candidate = candidates(:martha)
+ post admin_update_candidate_url(id: candidate.id), params:
+ { candidate: { name: 'new name', email: "mail@martha.me", test_hash: 'SOMENEWSTRING' } }
+
+ refute_equal candidate.name, Candidate.find_by(id: candidate.id).name
+ assert_equal candidate.test_hash, Candidate.find_by(id: candidate.id).test_hash
+ assert_redirected_to admin_candidate_url
+ end
+
+ test 'should redirect to form on fail' do
+ auth_recruiter
+ candidate = candidates(:martha)
+ post admin_update_candidate_url(id: candidate.id), params:
+ { candidate: { name: 'new name', email: "mail@martha" } }
+
+ assert :success
+ assert_match(/failed.*save/i, flash[:error])
+ end
+ end
+end
diff --git a/test/controllers/recruiter_controller/index_test.rb b/test/controllers/recruiter_controller/index_test.rb
deleted file mode 100644
index b6b4a7c..0000000
--- a/test/controllers/recruiter_controller/index_test.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-# frozen_string_literal: true
-require 'test_helper'
-
-class RecruiterControllerTest < ActionDispatch::IntegrationTest
- test "should get login" do
- get recruiter_login_url
- assert_response :success
- end
-
- test 'should logout and reset session' do
- auth_recruiter
- 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
-
- 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
- auth_recruiter
- 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
- auth_recruiter
- get recruiter_url
- assert_response :success
- assert assigns(:candidates), "@candidates not present"
- end
-
- test 'should have edit links' do
- auth_recruiter
- get recruiter_url
- assert_response :success
- assert_select "a[href='#{edit_candidate_path(candidates(:martha))}']"
- end
-end
diff --git a/test/controllers/recruiter_controller/new_candidate_test.rb b/test/controllers/recruiter_controller/new_candidate_test.rb
deleted file mode 100644
index 458237b..0000000
--- a/test/controllers/recruiter_controller/new_candidate_test.rb
+++ /dev/null
@@ -1,71 +0,0 @@
-# frozen_string_literal: true
-require 'test_helper'
-
-class RecruiterControllerTest < ActionDispatch::IntegrationTest
- include ActiveJob::TestHelper
-
- test "should get new" do
- auth_recruiter
- get new_candidate_url
- assert_response :success
- assert assigns(:candidate), "@candidate not present"
- end
-
- test "should get create" do
- auth_recruiter
- get create_candidate_url
- assert_response :success
- end
-
- test "should create new candidate" do
- auth_recruiter
-
- assert_enqueued_jobs 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
- end
- assert_redirected_to recruiter_path
- assert flash[:success]
- end
-
- test "should fail creation with improper email format" do
- auth_recruiter
-
- assert_enqueued_jobs 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 assigns(:candidate), "@candidate not present"
- assert_match(/failed.*save/i, flash[:error])
- end
-
- test "should fail creation gracefully with empty email" do
- auth_recruiter
-
- assert_enqueued_jobs 0 do
- assert_difference("Candidate.count", 0) do
- post create_candidate_path, params: { candidate:
- { name: 'new name', email: "", experience: '0-3', quiz_id: quizzes(:fed).id } }
- end
- end
- assert :success
- assert assigns(:candidate), "@candidate not present"
- assert_match(/failed.*save/i, flash[:error])
- end
-
- test 'should queue up a welcome email [resend]' do
- auth_recruiter
-
- assert_enqueued_jobs 1 do
- get resend_welcome_path(id: candidates(:peggy)), xhr: true
- end
- assert_response :success
- data = JSON.parse(response.body)
- assert_match 'queued', data["message"]
- end
-end
diff --git a/test/controllers/recruiter_controller/update_candidate_test.rb b/test/controllers/recruiter_controller/update_candidate_test.rb
deleted file mode 100644
index 02a1dbe..0000000
--- a/test/controllers/recruiter_controller/update_candidate_test.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: true
-require 'test_helper'
-
-class RecruiterControllerTest < ActionDispatch::IntegrationTest
- test 'should edit candidate' do
- auth_recruiter
- candidate = candidates(:martha)
-
- get edit_candidate_path(candidate.id)
- assert_response :success
- assert_select 'form'
- end
-
- test 'should update candidate, but NOT test_hash' do
- auth_recruiter
- candidate = candidates(:martha)
- post update_candidate_url(id: candidate.id), params:
- { candidate: { name: 'new name', email: "mail@martha.me", test_hash: 'SOMENEWSTRING' } }
-
- refute_equal candidate.name, Candidate.find_by(id: candidate.id).name
- assert_equal candidate.test_hash, Candidate.find_by(id: candidate.id).test_hash
- assert_redirected_to recruiter_url
- end
-
- test 'should redirect to form on fail' do
- auth_recruiter
- candidate = candidates(:martha)
- post update_candidate_url(id: candidate.id), params:
- { candidate: { name: 'new name', email: "mail@martha" } }
-
- assert :success
- assert_match(/failed.*save/i, flash[:error])
- end
-end
diff --git a/test/controllers/review_controller_test.rb b/test/controllers/review_controller_test.rb
index 5851678..453a629 100644
--- a/test/controllers/review_controller_test.rb
+++ b/test/controllers/review_controller_test.rb
@@ -17,7 +17,7 @@ class ReviewControllerTest < ActionDispatch::IntegrationTest
test "should auth to index" do
auth_reviewer
- assert_redirected_to review_path
+ assert_redirected_to admin_path
assert session[:user].present?
end
diff --git a/test/policies/candidate_policy_test.rb b/test/policies/candidate_policy_test.rb
new file mode 100644
index 0000000..5124ec8
--- /dev/null
+++ b/test/policies/candidate_policy_test.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+require 'test_helper'
+
+class CandidatePolicyTest < PolicyAssertions::Test
+ test 'should require current_user' do
+ assert_raise Pundit::NotAuthorizedError do
+ CandidatePolicy.new(nil, Candidate.first).view?
+ end
+ end
+
+ test 'should allow admin to scope' do
+ scope = CandidatePolicy::Scope.new(users(:admin), Candidate).resolve
+ assert_equal Candidate.count, scope.count
+ end
+
+ test 'should allow recruiter to scope' do
+ scope = CandidatePolicy::Scope.new(users(:recruiter), Candidate).resolve
+ assert_equal Candidate.count, scope.count
+ end
+
+ test 'reviewer CAN NOT scope candidates' do
+ assert_raise Pundit::NotAuthorizedError do
+ CandidatePolicy::Scope.new(users(:reviewer), Candidate).resolve
+ end
+ end
+
+ test 'manager CAN NOT scope candidates' do
+ assert_raise Pundit::NotAuthorizedError do
+ CandidatePolicy::Scope.new(users(:manager), Candidate).resolve
+ end
+ end
+
+ def test_view_and_update
+ assert_permit users(:admin), candidates(:roy)
+ assert_permit users(:recruiter), candidates(:roy)
+
+ refute_permit users(:manager), candidates(:roy)
+ refute_permit users(:reviewer), candidates(:roy)
+ end
+
+ def test_create
+ assert_permit users(:admin), Candidate
+ assert_permit users(:recruiter), Candidate
+
+ refute_permit users(:manager), Candidate
+ refute_permit users(:reviewer), Candidate
+ end
+end
diff --git a/test/policies/question_policy_test.rb b/test/policies/question_policy_test.rb
index 28d63c8..f8173db 100644
--- a/test/policies/question_policy_test.rb
+++ b/test/policies/question_policy_test.rb
@@ -31,7 +31,7 @@ class QuestionPolicyTest < PolicyAssertions::Test
end
end
- def test_view
+ def test_view_and_options
assert_permit users(:admin), questions(:fed1)
assert_permit users(:manager), questions(:fed1)
assert_permit users(:reviewer), questions(:fed1)
diff --git a/test/test_helpers/auth_test_helper.rb b/test/test_helpers/auth_test_helper.rb
index 7bddabe..152a7b6 100644
--- a/test/test_helpers/auth_test_helper.rb
+++ b/test/test_helpers/auth_test_helper.rb
@@ -4,13 +4,28 @@ module AuthTestHelper
post validate_candidate_url, params: { test_id: candidate.test_hash }
end
+ def auth_user user
+ post admin_auth_url, params: { auth:
+ { email: user.email, password: 'password' } }
+ end
+
+ def auth_admin
+ post admin_auth_url, params: { auth:
+ { email: 'alan.admin@mailinator.com', password: 'password' } }
+ end
+
+ def auth_manager
+ post admin_auth_url, params: { auth:
+ { email: 'mary.manager@mailinator.com', password: 'password' } }
+ end
+
def auth_recruiter
- post recruiter_auth_url, params: { auth:
+ post admin_auth_url, params: { auth:
{ email: 'pdr.recruiter@mailinator.com', password: 'password' } }
end
def auth_reviewer
- post review_auth_url, params: { auth:
+ post admin_auth_url, params: { auth:
{ email: 'fed.reviewer@mailinator.com', password: 'password' } }
end
end