vote/veto processing
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
# frozen_string_literal: true()
|
||||
require 'test_helper'
|
||||
|
||||
module Admin
|
||||
|
57
test/controllers/admin/vote_controller_test.rb
Normal file
57
test/controllers/admin/vote_controller_test.rb
Normal file
@ -0,0 +1,57 @@
|
||||
# frozen_string_literal: true
|
||||
require 'test_helper'
|
||||
|
||||
module Admin
|
||||
class VoteControllerTest < ActionDispatch::IntegrationTest
|
||||
test "reviewer can up vote henry" do
|
||||
auth_user users(:reviewer)
|
||||
henry = candidates(:henry)
|
||||
|
||||
assert_difference("Candidate.find(#{henry.id}).votes.yea.count", 1) do
|
||||
get admin_up_vote_url(henry.test_hash)
|
||||
end
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "reviewer can down vote henry" do
|
||||
auth_user users(:reviewer)
|
||||
henry = candidates(:henry)
|
||||
|
||||
assert_difference("Candidate.find(#{henry.id}).votes.nay.count", 1) do
|
||||
get admin_down_vote_url(henry.test_hash)
|
||||
end
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "reviewer can change vote on henry" do
|
||||
auth_user users(:reviewer)
|
||||
henry = candidates(:henry)
|
||||
get admin_up_vote_url(henry.test_hash)
|
||||
|
||||
assert_difference("Candidate.find(#{henry.id}).votes.nay.count", 1) do
|
||||
get admin_down_vote_url(henry.test_hash)
|
||||
end
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "manager can approve henry" do
|
||||
auth_user users(:manager)
|
||||
henry = candidates(:henry)
|
||||
get admin_approve_vote_url(henry.test_hash)
|
||||
|
||||
assert_equal 1, henry.votes.approved.count
|
||||
assert_equal 'approved', Candidate.find(henry.to_i).review_status
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "manager can decline henry" do
|
||||
auth_user users(:manager)
|
||||
henry = candidates(:henry)
|
||||
get admin_decline_vote_url(henry.test_hash)
|
||||
|
||||
assert_equal 1, henry.votes.rejected.count
|
||||
assert_equal 'declined', Candidate.find(henry.to_i).review_status
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
10
test/fixtures/candidates.yml
vendored
10
test/fixtures/candidates.yml
vendored
@ -102,3 +102,13 @@ wade: # Wade has completed AND submitted the test
|
||||
reminded: false
|
||||
test_hash: BkSkpapJnkz2N
|
||||
|
||||
gustov: # Gustov is NOT for FED
|
||||
name: Gustov
|
||||
email: <%= CryptSerializer.dump 'gustov@mailinator.com' %>
|
||||
experience: 0-3
|
||||
recruiter: recruiter
|
||||
quiz: admin
|
||||
completed: false
|
||||
reminded: false
|
||||
test_hash: kp6tfghjyapJnkz2N
|
||||
|
||||
|
49
test/policies/reviewer_vote_policy_test.rb
Normal file
49
test/policies/reviewer_vote_policy_test.rb
Normal file
@ -0,0 +1,49 @@
|
||||
# frozen_string_literal: true
|
||||
require 'test_helper'
|
||||
|
||||
class ReviewerVotePolicyTest < PolicyAssertions::Test
|
||||
test 'should require current_user' do
|
||||
assert_raise Pundit::NotAuthorizedError do
|
||||
ReviewerVotePolicy.new(nil, ReviewerVote.first).view?
|
||||
end
|
||||
end
|
||||
|
||||
test 'should allow admin to scope' do
|
||||
scope = ReviewerVotePolicy::Scope.new(users(:admin), ReviewerVote).resolve
|
||||
assert_equal ReviewerVote.count, scope.count
|
||||
end
|
||||
|
||||
test 'should allow manager to scope' do
|
||||
scope = ReviewerVotePolicy::Scope.new(users(:manager), ReviewerVote).resolve
|
||||
assert_equal ReviewerVote.count, scope.count
|
||||
end
|
||||
|
||||
test 'should allow reviewer to scope' do
|
||||
scope = ReviewerVotePolicy::Scope.new(users(:reviewer), ReviewerVote).resolve
|
||||
assert_equal users(:reviewer).votes.count, scope.count
|
||||
end
|
||||
|
||||
test 'should NOT allow recruiter to scope' do
|
||||
scope = ReviewerVotePolicy::Scope.new(users(:recruiter), ReviewerVote).resolve
|
||||
assert_equal 0, scope.count
|
||||
end
|
||||
|
||||
def test_up
|
||||
skip
|
||||
# assert_permit users(:admin), candidates(:richard)
|
||||
# assert_permit users(:admin), candidates(:gustov)
|
||||
# assert_permit users(:manager), candidates(:richard)
|
||||
# assert_permit users(:reviewer), candidates(:richard)
|
||||
#
|
||||
# refute_permit users(:reviewer), candidates(:gustov)
|
||||
# refute_permit users(:recruiter), candidates(:richard)
|
||||
end
|
||||
|
||||
# def test_create_and_update
|
||||
# assert_permit users(:admin), Vote
|
||||
# assert_permit users(:manager), Vote
|
||||
#
|
||||
# refute_permit users(:recruiter), Vote
|
||||
# refute_permit users(:reviewer), Vote
|
||||
# end
|
||||
end
|
Reference in New Issue
Block a user