admin test complete
This commit is contained in:
parent
33f0358fa5
commit
4a745e0aba
@ -8,6 +8,7 @@ module Admin
|
||||
after_action :skip_authorization
|
||||
#
|
||||
|
||||
# TODO: Limit results to the quizzes current_user has access to
|
||||
def index
|
||||
@candidates = Candidate.where(completed: true).includes(:recruiter)
|
||||
end
|
||||
|
@ -26,6 +26,13 @@ module Admin
|
||||
assert_redirected_to admin_url
|
||||
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
|
||||
post admin_auth_url, params: { auth:
|
||||
{ email: 'pdr.recruiter@mailinator.com', password: 'password' } }
|
||||
|
@ -14,5 +14,33 @@ module Admin
|
||||
get admin_users_url
|
||||
assert_response :success
|
||||
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
|
||||
|
@ -5,24 +5,22 @@ module Admin
|
||||
class UserControllerTest < ActionDispatch::IntegrationTest
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
def setup
|
||||
post admin_auth_url, params: { auth:
|
||||
{ email: 'alan.admin@mailinator.com', password: 'password' } }
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
auth_admin
|
||||
get admin_users_url
|
||||
assert_response :success
|
||||
assert assigns :users
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
auth_admin
|
||||
get admin_new_user_url
|
||||
assert_response :success
|
||||
assert assigns :user
|
||||
end
|
||||
|
||||
test "should fail create" do
|
||||
auth_admin
|
||||
assert_difference("User.count", 0) do
|
||||
post admin_create_user_url, params: { user: { name: 'New User' } }
|
||||
end
|
||||
@ -31,6 +29,7 @@ module Admin
|
||||
end
|
||||
|
||||
test "should post create" do
|
||||
auth_admin
|
||||
assert_enqueued_jobs 1 do
|
||||
assert_difference("User.count", 1) do
|
||||
post admin_create_user_url, params: { user:
|
||||
@ -41,6 +40,7 @@ module Admin
|
||||
end
|
||||
|
||||
test "should get view" do
|
||||
auth_admin
|
||||
user = users(:recruiter)
|
||||
get admin_user_url user.to_i
|
||||
assert_response :success
|
||||
@ -48,6 +48,7 @@ module Admin
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
auth_admin
|
||||
user = users(:recruiter)
|
||||
get admin_edit_user_url user.to_i
|
||||
assert_response :success
|
||||
@ -55,6 +56,7 @@ module Admin
|
||||
end
|
||||
|
||||
test "should post update user" do
|
||||
auth_admin
|
||||
user = users(:recruiter)
|
||||
post admin_update_user_url(user.to_i), params: { user: { name: 'new name' } }
|
||||
assert_redirected_to admin_user_path(user.to_i)
|
||||
@ -64,10 +66,19 @@ module Admin
|
||||
end
|
||||
|
||||
test "should fail to update user" do
|
||||
auth_admin
|
||||
user = users(:recruiter)
|
||||
post admin_update_user_url(user.to_i), params: { user: { name: nil } }
|
||||
assert :success
|
||||
assert_match(/failed/i, session[:flash].values.join)
|
||||
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
|
||||
|
@ -2,4 +2,11 @@
|
||||
require 'test_helper'
|
||||
|
||||
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
|
||||
|
@ -2,7 +2,81 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UserTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
test 'admin should act as any role' do
|
||||
user = users(:admin)
|
||||
|
||||
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
|
||||
|
@ -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