review comment tweaks - completes #104

This commit is contained in:
Mark Moser 2017-03-07 16:35:59 -06:00
parent 2c0020a280
commit e0ff645926
6 changed files with 44 additions and 9 deletions

View File

@ -28,6 +28,10 @@
margin-bottom: 30px;
}
form {
margin-bottom: 30px;
}
.comment-message {
margin-right: 5px;
}

View File

@ -17,14 +17,27 @@ module Admin
@candidate = Candidate.find_by(test_hash: params[:test_hash])
authorize ReviewerVote.find_by(user_id: current_user.id, candidate_id: @candidate.id)
if interview_params[:review_comments].blank?
refuse_interview_request
else
send_interview_request
end
end
private
def refuse_interview_request
redirect_to admin_result_path(@candidate.test_hash),
flash: { error: "Must provide a comment" }
end
def send_interview_request
current_user.review_candidate(@candidate, interview_params)
RecruiterMailer.candidate_reviewed(@candidate).deliver_later
redirect_to admin_result_path(@candidate.test_hash),
flash: { notice: "Quiz #{interview_params[:review_status]}" }
end
private
def interview_params
params.permit(:review_status, :review_comments)
end

View File

@ -1,5 +1,3 @@
<%= render partial: 'shared/form_model_errors', locals: { obj: comment } %>
<% if comment.id.nil? %>
<%= form_for comment, url: admin_create_comment_path(test_hash: test_hash), method: :post do |form| %>

View File

@ -4,7 +4,7 @@
<div class="review_meta__votes" data-id="vote-count">
<strong>Votes: </strong>
<% if @candidate.pending? %>
<% if @candidate.pending? && current_user.commented_on?(@candidate.test_hash) %>
<%= link_to admin_up_vote_path(test_hash: @candidate.test_hash), remote: true do %>
Yea (<span data-id="up-votes"><%= @candidate.votes.yea.count %></span>)
<% end %>
@ -12,6 +12,10 @@
<%= link_to admin_down_vote_path(test_hash: @candidate.test_hash), remote: true do %>
Nay (<span data-id="down-votes"><%= @candidate.votes.nay.count %></span>)
<% end %>
<% elsif @candidate.pending? %>
<div>You must comment before you can vote</div>
<span>Yea (<span data-id="up-votes"><%= @candidate.votes.yea.count %></span>)</span>
<span>Nay (<span data-id="down-votes"><%= @candidate.votes.nay.count %></span>)</span>
<% else %>
Voting closed -
Yea (<%= @candidate.votes.yea.count %>) -
@ -43,4 +47,8 @@
<% else %>
<strong>Candidate Interview Status: </strong><%= @candidate.review_status %>
<% unless @candidate.review_status.blank? %>
<div>Review Status Comments:</div>
<div><%= @candidate.review_comments %></div>
<% end %>
<% end %>

View File

@ -55,11 +55,12 @@
</div>
<div>
<h2 class="prft-heading">Comments</h2>
<%= render partial: 'comment', collection: @comments, locals: { test_hash: @candidate.test_hash } %>
<h2 id="comment-header" class="prft-heading">Comments</h2>
<% if policy(QuizComment).new? %>
<%= render partial: 'comment_form', locals: {comment: @comment, test_hash: @candidate.test_hash } %>
<% end %>
<%= render partial: 'comment', collection: @comments, locals: { test_hash: @candidate.test_hash } %>
<a href="#comment-header">Back to top</a>
</div>
</div>
</div>

View File

@ -70,5 +70,16 @@ module Admin
assert_equal 'ipsum', Candidate.find(henry.to_i).review_comments
assert_redirected_to admin_result_url(henry.test_hash)
end
test "approve fails without comment" do
auth_user users(:manager)
henry = candidates(:henry)
assert_enqueued_jobs 0 do
post admin_interview_url(henry.test_hash), params: { review_status: 'approved' }
end
assert_match 'comment', flash[:error]
assert_redirected_to admin_result_url(henry.test_hash)
end
end
end