diff --git a/app/assets/stylesheets/molecules/_admin_review.scss b/app/assets/stylesheets/molecules/_admin_review.scss
index 9077423..ab119d1 100644
--- a/app/assets/stylesheets/molecules/_admin_review.scss
+++ b/app/assets/stylesheets/molecules/_admin_review.scss
@@ -24,6 +24,10 @@
padding-left: 30px;
width: 33%;
+ > div {
+ margin-bottom: 30px;
+ }
+
.comment-message {
margin-right: 5px;
}
diff --git a/app/models/user.rb b/app/models/user.rb
index 6179a94..02b88bf 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -19,6 +19,10 @@ class User < ApplicationRecord
save
end
+ def commented_on? test_hash
+ quiz_comments.where(test_hash: test_hash).count.positive?
+ end
+
# Voting
# TODO: Refactor this out of User, belongs on ReviewerVote
# ie: cast_yea(candidate, user)
diff --git a/app/policies/quiz_comment_policy.rb b/app/policies/quiz_comment_policy.rb
index f4128f9..cb95c15 100644
--- a/app/policies/quiz_comment_policy.rb
+++ b/app/policies/quiz_comment_policy.rb
@@ -10,7 +10,10 @@ class QuizCommentPolicy < ApplicationPolicy
end
def create?
- user.acts_as_reviewer? && record.candidate.reviewers.where(id: user.id).count.positive?
+ return true if user.acts_as_admin?
+
+ user.acts_as_reviewer? &&
+ record.candidate.reviewers.where(id: user.id).count.positive?
end
def update?
diff --git a/app/policies/reviewer_vote_policy.rb b/app/policies/reviewer_vote_policy.rb
index 7e9f1da..00f28a7 100644
--- a/app/policies/reviewer_vote_policy.rb
+++ b/app/policies/reviewer_vote_policy.rb
@@ -2,20 +2,22 @@
class ReviewerVotePolicy < ApplicationPolicy
# Voting Policy
#
- # Only Reviewers, Managers, and Admins, can cast a vote on a quiz result
+ # Only Reviewers and Managers can cast a vote on a quiz result
#
# Reviewers can vote any quiz they are linked to
# Only Managers, and Admins, can veto a quiz result
def up?
- return true if user.acts_as_admin?
+ return false unless user.commented_on?(record.candidate.test_hash)
return false unless record.candidate.reviewers.include? user
+ return false if user.admin?
user.acts_as_reviewer?
end
def down?
- return true if user.acts_as_admin?
+ return false unless user.commented_on?(record.candidate.test_hash)
return false unless record.candidate.reviewers.include? user
+ return false if user.admin?
user.acts_as_reviewer?
end
diff --git a/app/views/admin/result/view.html.erb b/app/views/admin/result/view.html.erb
index 0372f3d..6c60953 100644
--- a/app/views/admin/result/view.html.erb
+++ b/app/views/admin/result/view.html.erb
@@ -13,8 +13,6 @@
Client/Project: <%= @candidate.project %>
Recruiter Email: <%= mail_to @candidate.recruiter.name, @candidate.recruiter.email %>
-
-
<%= render partial: 'voting' %>
<% @quiz.each do |question| %>
@@ -44,10 +42,19 @@
diff --git a/test/controllers/admin/comment_controller_test.rb b/test/controllers/admin/comment_controller_test.rb
index 9b9a8fb..8fd3f31 100644
--- a/test/controllers/admin/comment_controller_test.rb
+++ b/test/controllers/admin/comment_controller_test.rb
@@ -40,6 +40,19 @@ module Admin
assert flash[:success]
end
+ test "admin can post comment" do
+ auth_admin
+ candidate = candidates(:stacy)
+
+ assert_difference("QuizComment.count") do
+ post admin_create_comment_url(test_hash: candidate.test_hash),
+ params: { quiz_comment: { message: 'this is an admin comment' } }
+ end
+
+ assert_redirected_to admin_result_url(test_hash: candidate.test_hash)
+ assert flash[:success]
+ end
+
test "should queue emails on create" do
auth_reviewer
candidate = candidates(:stacy)
diff --git a/test/controllers/admin/vote_controller_test.rb b/test/controllers/admin/vote_controller_test.rb
index 303f7d4..23e202e 100644
--- a/test/controllers/admin/vote_controller_test.rb
+++ b/test/controllers/admin/vote_controller_test.rb
@@ -6,7 +6,7 @@ module Admin
include ActiveJob::TestHelper
test "reviewer can up vote henry" do
- auth_user users(:reviewer)
+ auth_user users(:reviewer2)
henry = candidates(:henry)
assert_difference("Candidate.find(#{henry.id}).votes.yea.count", 1) do
@@ -16,7 +16,7 @@ module Admin
end
test "reviewer can down vote henry" do
- auth_user users(:reviewer)
+ auth_user users(:reviewer2)
henry = candidates(:henry)
assert_difference("Candidate.find(#{henry.id}).votes.nay.count", 1) do
@@ -26,7 +26,7 @@ module Admin
end
test "reviewer can change vote on henry" do
- auth_user users(:reviewer)
+ auth_user users(:reviewer2)
henry = candidates(:henry)
get admin_up_vote_url(henry.test_hash)
@@ -72,5 +72,23 @@ module Admin
data = JSON.parse(response.body)
assert_match 'requested', data["message"]
end
+
+ test "reviewer can only vote after commenting" do
+ auth_user users(:reviewer)
+ henry = candidates(:henry)
+
+ assert_difference("Candidate.find(#{henry.id}).votes.yea.count", 0) do
+ get admin_up_vote_url(henry.test_hash)
+ end
+
+ post admin_create_comment_url(test_hash: henry.test_hash),
+ params: { quiz_comment: { message: 'this is a comment to vote' } }
+
+ assert_difference("Candidate.find(#{henry.id}).votes.yea.count", 1) do
+ get admin_up_vote_url(henry.test_hash)
+ end
+
+ assert_response :success
+ end
end
end
diff --git a/test/fixtures/quiz_comments.yml b/test/fixtures/quiz_comments.yml
index 68a7938..3ac5c7a 100644
--- a/test/fixtures/quiz_comments.yml
+++ b/test/fixtures/quiz_comments.yml
@@ -70,3 +70,18 @@ com14:
user: reviewer2
message: Ultricies Vulputate Bibendum Parturient
+com15:
+ test_hash: 6NjnourLE6Y #richard
+ user: manager
+ message: gibberish
+
+com16:
+ test_hash: egPomAuVDeCEp #henry
+ user: admin
+ message: word.
+
+com17:
+ test_hash: 6NjnourLE6Y #richard
+ user: reviewer
+ message: more gibberish
+
diff --git a/test/models/quiz_comment_test.rb b/test/models/quiz_comment_test.rb
index 90e3ec8..9f81ccd 100644
--- a/test/models/quiz_comment_test.rb
+++ b/test/models/quiz_comment_test.rb
@@ -9,7 +9,7 @@ class QuizCommentTest < ActiveSupport::TestCase
test "user to comments association" do
manager = users(:manager)
- assert_equal 4, manager.quiz_comments.size
+ assert_equal 5, manager.quiz_comments.size
end
test "candidate to comments association" do
diff --git a/test/policies/quiz_comment_policy_test.rb b/test/policies/quiz_comment_policy_test.rb
index 6298093..08b2543 100644
--- a/test/policies/quiz_comment_policy_test.rb
+++ b/test/policies/quiz_comment_policy_test.rb
@@ -14,8 +14,8 @@ class QuizCommentPolicyTest < PolicyAssertions::Test
assert_permit users(:manager), comment
assert_permit users(:reviewer), comment
+ assert_permit users(:admin), comment
- refute_permit users(:admin), comment
refute_permit users(:recruiter), comment
end
diff --git a/test/policies/reviewer_vote_policy_test.rb b/test/policies/reviewer_vote_policy_test.rb
index 1824293..95c8e82 100644
--- a/test/policies/reviewer_vote_policy_test.rb
+++ b/test/policies/reviewer_vote_policy_test.rb
@@ -31,8 +31,8 @@ class ReviewerVotePolicyTest < PolicyAssertions::Test
def test_up
assert_permit users(:manager), reviewer_votes(:manager_richard)
assert_permit users(:reviewer), reviewer_votes(:reviewer_richard)
- assert_permit users(:admin), reviewer_votes(:manager_henry)
+ refute_permit users(:admin), reviewer_votes(:manager_henry)
refute_permit users(:recruiter), reviewer_votes(:manager_henry)
refute_permit users(:reviewer), reviewer_votes(:gustov)
refute_permit users(:manager), reviewer_votes(:gustov)
@@ -41,8 +41,8 @@ class ReviewerVotePolicyTest < PolicyAssertions::Test
def test_down
assert_permit users(:manager), reviewer_votes(:manager_richard)
assert_permit users(:reviewer), reviewer_votes(:reviewer_richard)
- assert_permit users(:admin), reviewer_votes(:manager_henry)
+ refute_permit users(:admin), reviewer_votes(:manager_henry)
refute_permit users(:recruiter), reviewer_votes(:manager_henry)
refute_permit users(:reviewer), reviewer_votes(:gustov)
refute_permit users(:manager), reviewer_votes(:gustov)
Comments
- <%= render partial: 'comment', collection: @comments, locals: { test_hash: @candidate.test_hash } %> - <% if policy(QuizComment).new? %> - <%= render partial: 'comment_form', locals: {comment: @comment, test_hash: @candidate.test_hash } %> - <% end %> +Voting
+Comments
+ <%= render partial: 'comment', collection: @comments, locals: { test_hash: @candidate.test_hash } %> + <% if policy(QuizComment).new? %> + <%= render partial: 'comment_form', locals: {comment: @comment, test_hash: @candidate.test_hash } %> + <% end %> +