# 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