vote/veto processing

This commit is contained in:
Mark Moser
2016-11-19 16:34:48 -06:00
parent 5845f76e1d
commit e0f5e482be
10 changed files with 240 additions and 1 deletions

View File

@ -1,4 +1,4 @@
# frozen_string_literal: true
# frozen_string_literal: true()
require 'test_helper'
module Admin

View 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

View File

@ -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

View 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