From e0ff6459266a5ab9511b5b2ea82cc24c56901756 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Tue, 7 Mar 2017 16:35:59 -0600 Subject: [PATCH] review comment tweaks - completes #104 --- .../stylesheets/molecules/_admin_review.scss | 4 ++++ app/controllers/admin/vote_controller.rb | 21 +++++++++++++++---- app/views/admin/result/_comment_form.html.erb | 2 -- app/views/admin/result/_voting.html.erb | 10 ++++++++- app/views/admin/result/view.html.erb | 5 +++-- .../controllers/admin/vote_controller_test.rb | 11 ++++++++++ 6 files changed, 44 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/molecules/_admin_review.scss b/app/assets/stylesheets/molecules/_admin_review.scss index dc1f8fb..f6776a5 100644 --- a/app/assets/stylesheets/molecules/_admin_review.scss +++ b/app/assets/stylesheets/molecules/_admin_review.scss @@ -28,6 +28,10 @@ margin-bottom: 30px; } + form { + margin-bottom: 30px; + } + .comment-message { margin-right: 5px; } diff --git a/app/controllers/admin/vote_controller.rb b/app/controllers/admin/vote_controller.rb index 538bebf..862410a 100644 --- a/app/controllers/admin/vote_controller.rb +++ b/app/controllers/admin/vote_controller.rb @@ -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) - 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]}" } + 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 + def interview_params params.permit(:review_status, :review_comments) end diff --git a/app/views/admin/result/_comment_form.html.erb b/app/views/admin/result/_comment_form.html.erb index 701cb7a..f67fd03 100644 --- a/app/views/admin/result/_comment_form.html.erb +++ b/app/views/admin/result/_comment_form.html.erb @@ -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| %> diff --git a/app/views/admin/result/_voting.html.erb b/app/views/admin/result/_voting.html.erb index 689a7ae..4029c52 100644 --- a/app/views/admin/result/_voting.html.erb +++ b/app/views/admin/result/_voting.html.erb @@ -4,7 +4,7 @@
Votes: - <% 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 (<%= @candidate.votes.yea.count %>) <% end %> @@ -12,6 +12,10 @@ <%= link_to admin_down_vote_path(test_hash: @candidate.test_hash), remote: true do %> Nay (<%= @candidate.votes.nay.count %>) <% end %> + <% elsif @candidate.pending? %> +
You must comment before you can vote
+ Yea (<%= @candidate.votes.yea.count %>) + Nay (<%= @candidate.votes.nay.count %>) <% else %> Voting closed - Yea (<%= @candidate.votes.yea.count %>) - @@ -43,4 +47,8 @@ <% else %> Candidate Interview Status: <%= @candidate.review_status %> + <% unless @candidate.review_status.blank? %> +
Review Status Comments:
+
<%= @candidate.review_comments %>
+ <% end %> <% end %> diff --git a/app/views/admin/result/view.html.erb b/app/views/admin/result/view.html.erb index 45fdc79..ab89ea6 100644 --- a/app/views/admin/result/view.html.erb +++ b/app/views/admin/result/view.html.erb @@ -55,11 +55,12 @@
-

Comments

- <%= render partial: 'comment', collection: @comments, locals: { test_hash: @candidate.test_hash } %> +

Comments

<% 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 } %> + Back to top
diff --git a/test/controllers/admin/vote_controller_test.rb b/test/controllers/admin/vote_controller_test.rb index 79686c6..e7de4e4 100644 --- a/test/controllers/admin/vote_controller_test.rb +++ b/test/controllers/admin/vote_controller_test.rb @@ -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