admin test complete
This commit is contained in:
parent
33f0358fa5
commit
4a745e0aba
@ -8,6 +8,7 @@ module Admin
|
|||||||
after_action :skip_authorization
|
after_action :skip_authorization
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# TODO: Limit results to the quizzes current_user has access to
|
||||||
def index
|
def index
|
||||||
@candidates = Candidate.where(completed: true).includes(:recruiter)
|
@candidates = Candidate.where(completed: true).includes(:recruiter)
|
||||||
end
|
end
|
||||||
|
@ -26,6 +26,13 @@ module Admin
|
|||||||
assert_redirected_to admin_url
|
assert_redirected_to admin_url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should FAIL auth" do
|
||||||
|
post admin_auth_url, params: { auth:
|
||||||
|
{ email: 'alan.admin@mailinator.com', password: 'b@d9a$$werD' } }
|
||||||
|
assert_redirected_to admin_login_url
|
||||||
|
assert_match(/incorrect.*password/i, flash[:error])
|
||||||
|
end
|
||||||
|
|
||||||
test "recruiter should auth to dashboard" do
|
test "recruiter should auth to dashboard" do
|
||||||
post admin_auth_url, params: { auth:
|
post admin_auth_url, params: { auth:
|
||||||
{ email: 'pdr.recruiter@mailinator.com', password: 'password' } }
|
{ email: 'pdr.recruiter@mailinator.com', password: 'password' } }
|
||||||
|
@ -14,5 +14,33 @@ module Admin
|
|||||||
get admin_users_url
|
get admin_users_url
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "admin should redirect to users" do
|
||||||
|
auth_admin
|
||||||
|
get admin_url
|
||||||
|
|
||||||
|
assert_redirected_to admin_users_path
|
||||||
|
end
|
||||||
|
|
||||||
|
test "manager should redirect to quizzes" do
|
||||||
|
auth_manager
|
||||||
|
get admin_url
|
||||||
|
|
||||||
|
assert_redirected_to admin_quizzes_path
|
||||||
|
end
|
||||||
|
|
||||||
|
test "reviewer should redirect to results" do
|
||||||
|
auth_reviewer
|
||||||
|
get admin_url
|
||||||
|
|
||||||
|
assert_redirected_to admin_results_path
|
||||||
|
end
|
||||||
|
|
||||||
|
test "recruiter should redirect to candidates" do
|
||||||
|
auth_recruiter
|
||||||
|
get admin_url
|
||||||
|
|
||||||
|
assert_redirected_to admin_candidates_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,24 +5,22 @@ module Admin
|
|||||||
class UserControllerTest < ActionDispatch::IntegrationTest
|
class UserControllerTest < ActionDispatch::IntegrationTest
|
||||||
include ActiveJob::TestHelper
|
include ActiveJob::TestHelper
|
||||||
|
|
||||||
def setup
|
|
||||||
post admin_auth_url, params: { auth:
|
|
||||||
{ email: 'alan.admin@mailinator.com', password: 'password' } }
|
|
||||||
end
|
|
||||||
|
|
||||||
test "should get index" do
|
test "should get index" do
|
||||||
|
auth_admin
|
||||||
get admin_users_url
|
get admin_users_url
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert assigns :users
|
assert assigns :users
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get new" do
|
test "should get new" do
|
||||||
|
auth_admin
|
||||||
get admin_new_user_url
|
get admin_new_user_url
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert assigns :user
|
assert assigns :user
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should fail create" do
|
test "should fail create" do
|
||||||
|
auth_admin
|
||||||
assert_difference("User.count", 0) do
|
assert_difference("User.count", 0) do
|
||||||
post admin_create_user_url, params: { user: { name: 'New User' } }
|
post admin_create_user_url, params: { user: { name: 'New User' } }
|
||||||
end
|
end
|
||||||
@ -31,6 +29,7 @@ module Admin
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "should post create" do
|
test "should post create" do
|
||||||
|
auth_admin
|
||||||
assert_enqueued_jobs 1 do
|
assert_enqueued_jobs 1 do
|
||||||
assert_difference("User.count", 1) do
|
assert_difference("User.count", 1) do
|
||||||
post admin_create_user_url, params: { user:
|
post admin_create_user_url, params: { user:
|
||||||
@ -41,6 +40,7 @@ module Admin
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "should get view" do
|
test "should get view" do
|
||||||
|
auth_admin
|
||||||
user = users(:recruiter)
|
user = users(:recruiter)
|
||||||
get admin_user_url user.to_i
|
get admin_user_url user.to_i
|
||||||
assert_response :success
|
assert_response :success
|
||||||
@ -48,6 +48,7 @@ module Admin
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "should get edit" do
|
test "should get edit" do
|
||||||
|
auth_admin
|
||||||
user = users(:recruiter)
|
user = users(:recruiter)
|
||||||
get admin_edit_user_url user.to_i
|
get admin_edit_user_url user.to_i
|
||||||
assert_response :success
|
assert_response :success
|
||||||
@ -55,6 +56,7 @@ module Admin
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "should post update user" do
|
test "should post update user" do
|
||||||
|
auth_admin
|
||||||
user = users(:recruiter)
|
user = users(:recruiter)
|
||||||
post admin_update_user_url(user.to_i), params: { user: { name: 'new name' } }
|
post admin_update_user_url(user.to_i), params: { user: { name: 'new name' } }
|
||||||
assert_redirected_to admin_user_path(user.to_i)
|
assert_redirected_to admin_user_path(user.to_i)
|
||||||
@ -64,10 +66,19 @@ module Admin
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "should fail to update user" do
|
test "should fail to update user" do
|
||||||
|
auth_admin
|
||||||
user = users(:recruiter)
|
user = users(:recruiter)
|
||||||
post admin_update_user_url(user.to_i), params: { user: { name: nil } }
|
post admin_update_user_url(user.to_i), params: { user: { name: nil } }
|
||||||
assert :success
|
assert :success
|
||||||
assert_match(/failed/i, session[:flash].values.join)
|
assert_match(/failed/i, session[:flash].values.join)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'non admin can not change own role' do
|
||||||
|
auth_recruiter
|
||||||
|
user = users(:recruiter)
|
||||||
|
post admin_update_user_url(user.to_i), params: { user: { name: 'new name', role: 'foobar' } }
|
||||||
|
|
||||||
|
assert_equal user.role, User.find_by(id: user.id).role
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,4 +2,11 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class AdminControllerTest < ActionDispatch::IntegrationTest
|
class AdminControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
test 'should provide flash mesage when access is denied' do
|
||||||
|
auth_reviewer
|
||||||
|
get admin_candidates_path
|
||||||
|
|
||||||
|
assert_redirected_to admin_login_path
|
||||||
|
assert_match 'not authorized', flash[:error]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,81 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class UserTest < ActiveSupport::TestCase
|
class UserTest < ActiveSupport::TestCase
|
||||||
# test "the truth" do
|
test 'admin should act as any role' do
|
||||||
# assert true
|
user = users(:admin)
|
||||||
# end
|
|
||||||
|
assert user.acts_as_admin?
|
||||||
|
assert user.acts_as_manager?
|
||||||
|
assert user.acts_as_recruiter?
|
||||||
|
assert user.acts_as_reviewer?
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'admin should only be admin' do
|
||||||
|
user = users(:admin)
|
||||||
|
|
||||||
|
assert user.admin?
|
||||||
|
refute user.manager?
|
||||||
|
refute user.recruiter?
|
||||||
|
refute user.reviewer?
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'manager should act as manager' do
|
||||||
|
user = users(:manager)
|
||||||
|
|
||||||
|
assert user.acts_as_manager?
|
||||||
|
|
||||||
|
refute user.acts_as_admin?
|
||||||
|
refute user.acts_as_recruiter?
|
||||||
|
refute user.acts_as_reviewer?
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'manager should only be manager' do
|
||||||
|
user = users(:manager)
|
||||||
|
|
||||||
|
assert user.manager?
|
||||||
|
|
||||||
|
refute user.admin?
|
||||||
|
refute user.recruiter?
|
||||||
|
refute user.reviewer?
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'recruiter should act as recruiter' do
|
||||||
|
user = users(:recruiter)
|
||||||
|
|
||||||
|
assert user.acts_as_recruiter?
|
||||||
|
|
||||||
|
refute user.acts_as_manager?
|
||||||
|
refute user.acts_as_admin?
|
||||||
|
refute user.acts_as_reviewer?
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'recruiter should only be recruiter' do
|
||||||
|
user = users(:recruiter)
|
||||||
|
|
||||||
|
assert user.recruiter?
|
||||||
|
|
||||||
|
refute user.admin?
|
||||||
|
refute user.manager?
|
||||||
|
refute user.reviewer?
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'reviewer should act as reviewer' do
|
||||||
|
user = users(:reviewer)
|
||||||
|
|
||||||
|
assert user.acts_as_reviewer?
|
||||||
|
|
||||||
|
refute user.acts_as_manager?
|
||||||
|
refute user.acts_as_admin?
|
||||||
|
refute user.acts_as_recruiter?
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'reviewer should only be reviewer' do
|
||||||
|
user = users(:reviewer)
|
||||||
|
|
||||||
|
assert user.reviewer?
|
||||||
|
|
||||||
|
refute user.admin?
|
||||||
|
refute user.manager?
|
||||||
|
refute user.recruiter?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
require 'test_helper'
|
|
||||||
|
|
||||||
# TODO: How the heck to you test a headless policy?...
|
|
||||||
#
|
|
||||||
# class AdminPolicyTest < PolicyAssertions::Test
|
|
||||||
# def test_dashboard
|
|
||||||
# assert_permit users(:recruiter), Admin
|
|
||||||
# end
|
|
||||||
# end
|
|
8
test/policies/dashboard_policy_test.rb
Normal file
8
test/policies/dashboard_policy_test.rb
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class DashboardPolicyTest < PolicyAssertions::Test
|
||||||
|
def test_show
|
||||||
|
assert_permit users(:recruiter), :dashboard
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user