From 0a9bf96e243cb516199f9a61be2ed8ccd4927822 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Thu, 22 Sep 2016 14:19:44 -0500 Subject: [PATCH] move /review to /admin/results --- app/controllers/admin/result_controller.rb | 21 +++++++ app/controllers/review_controller.rb | 34 ---------- .../{review => admin/result}/index.html.erb | 2 +- .../{review => admin/result}/view.html.erb | 2 +- app/views/review/login.html.erb | 21 ------- .../candidate_submission.html.inky | 4 +- .../candidate_submission.text.erb | 2 +- config/routes.rb | 7 +-- .../admin/result_controller_test.rb | 23 +++++++ test/controllers/review_controller_test.rb | 63 ------------------- test/integration/question_attachments_test.rb | 5 +- 11 files changed, 53 insertions(+), 131 deletions(-) create mode 100644 app/controllers/admin/result_controller.rb delete mode 100644 app/controllers/review_controller.rb rename app/views/{review => admin/result}/index.html.erb (81%) rename app/views/{review => admin/result}/view.html.erb (94%) delete mode 100644 app/views/review/login.html.erb create mode 100644 test/controllers/admin/result_controller_test.rb delete mode 100644 test/controllers/review_controller_test.rb diff --git a/app/controllers/admin/result_controller.rb b/app/controllers/admin/result_controller.rb new file mode 100644 index 0000000..9d14ded --- /dev/null +++ b/app/controllers/admin/result_controller.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true +module Admin + class ResultController < AdminController + # + # TODO: change context from Candidate to Quiz + # bypass pundit lockdowns until completed + after_action :skip_policy_scope + after_action :skip_authorization + # + + def index + @candidates = Candidate.where(completed: true).includes(:recruiter) + end + + def view + @candidate = Candidate.find_by(test_hash: params[:test_hash]) + @quiz = @candidate.my_quiz + @status = QuizStatus.new(@candidate) + end + end +end diff --git a/app/controllers/review_controller.rb b/app/controllers/review_controller.rb deleted file mode 100644 index d810bad..0000000 --- a/app/controllers/review_controller.rb +++ /dev/null @@ -1,34 +0,0 @@ -# frozen_string_literal: true -class ReviewController < ApplicationController - before_action :authorize_reviewer, except: [:login, :auth] - - def index - @candidates = Candidate.where(completed: true).includes(:recruiter) - end - - def view - @candidate = Candidate.find_by(test_hash: params[:test_hash]) - @quiz = @candidate.my_quiz - @status = QuizStatus.new(@candidate) - end - - def login - redirect_to review_path unless current_reviewer.nil? - end - - def auth - reviewer = User.find_by(email: auth_params[:email], role: %w(admin reviewer)) - - if reviewer && reviewer.authenticate(auth_params[:password]) - session[:user] = reviewer.to_i - redirect_to review_path - else - redirect_to review_login_path, flash: { error: "Sorry, incorrect email or password. Please try again." } - end - end - - def logout - reset_session - redirect_to review_login_path - end -end diff --git a/app/views/review/index.html.erb b/app/views/admin/result/index.html.erb similarity index 81% rename from app/views/review/index.html.erb rename to app/views/admin/result/index.html.erb index 3601598..158605e 100644 --- a/app/views/review/index.html.erb +++ b/app/views/admin/result/index.html.erb @@ -10,7 +10,7 @@ <% @candidates.each do |candidate| %> - <%= link_to candidate.test_hash, review_test_path(candidate.test_hash) %> + <%= link_to candidate.test_hash, admin_result_path(candidate.test_hash) %> <%= candidate.experience %> years <%= mail_to(candidate.recruiter.email) %> diff --git a/app/views/review/view.html.erb b/app/views/admin/result/view.html.erb similarity index 94% rename from app/views/review/view.html.erb rename to app/views/admin/result/view.html.erb index 497199a..73a0f72 100644 --- a/app/views/review/view.html.erb +++ b/app/views/admin/result/view.html.erb @@ -27,7 +27,7 @@ <% end #form_tag %> <% end #questions loop %> - <%= link_to(review_path, { class: 'secondary-btn' }) do %> + <%= link_to(admin_results_path, { class: 'secondary-btn' }) do %> <% end %> diff --git a/app/views/review/login.html.erb b/app/views/review/login.html.erb deleted file mode 100644 index 6d84f0f..0000000 --- a/app/views/review/login.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -
-

Reviewer Login

- - <% if flash[:error].present? %> -
<%= flash[:error] %>
- <% end %> - - <%= form_for :auth, url: review_login_path do |form| %> -
- <%= form.label :email %> - <%= form.email_field :email %> -
- -
- <%= form.label :password %> - <%= form.password_field :password %> -
- - <%= submit_tag "Login" %> - <% end %> -
diff --git a/app/views/reviewer_mailer/candidate_submission.html.inky b/app/views/reviewer_mailer/candidate_submission.html.inky index 4f61e26..1c5a20f 100644 --- a/app/views/reviewer_mailer/candidate_submission.html.inky +++ b/app/views/reviewer_mailer/candidate_submission.html.inky @@ -1,6 +1,6 @@ - \ No newline at end of file + diff --git a/app/views/reviewer_mailer/candidate_submission.text.erb b/app/views/reviewer_mailer/candidate_submission.text.erb index 7ca4a38..e81acc2 100644 --- a/app/views/reviewer_mailer/candidate_submission.text.erb +++ b/app/views/reviewer_mailer/candidate_submission.text.erb @@ -2,4 +2,4 @@ PERFICIENT/digital SKILLS ASSESSMENT RESULTS Candidate <%= @candidate.test_hash %> has completed the Skills Assessment Test. -You can view the results here: <%= review_test_url(@candidate.test_hash) %>. +You can view the results here: <%= admin_result_url(@candidate.test_hash) %>. diff --git a/config/routes.rb b/config/routes.rb index 1fd272b..2691c85 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -47,11 +47,8 @@ Rails.application.routes.draw do post "/admin/candidate/:id", to: "admin/candidate#update", as: :admin_update_candidate get "/admin/candidate/:id/resend", to: "admin/candidate#resend_welcome", as: :admin_resend_welcome - get "/review/logout", to: "review#logout", as: :review_logout - post "/review/login", to: "review#auth", as: :review_auth - get "/review/login", to: "review#login", as: :review_login - get "/review", to: "review#index", as: :review - get "/review/:test_hash", to: "review#view", as: :review_test + get "/admin/results", to: "admin/result#index", as: :admin_results + get "/admin/result/:test_hash", to: "admin/result#view", as: :admin_result get "/admin", to: "admin/dashboard#show", as: :admin diff --git a/test/controllers/admin/result_controller_test.rb b/test/controllers/admin/result_controller_test.rb new file mode 100644 index 0000000..699517d --- /dev/null +++ b/test/controllers/admin/result_controller_test.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true +require 'test_helper' + +module Admin + class ResultControllerTest < ActionDispatch::IntegrationTest + test "should get results list" do + auth_reviewer + get admin_results_url + assert_response :success + assert assigns(:candidates), '@candidates not present' + end + + test "should get view" do + auth_reviewer + + get admin_result_url(candidates(:richard).test_hash) + assert_response :success + assert assigns(:candidate), "@candidate not present" + assert assigns(:quiz), "@quiz not present" + assert assigns(:status), "@status not present" + end + end +end diff --git a/test/controllers/review_controller_test.rb b/test/controllers/review_controller_test.rb deleted file mode 100644 index 453a629..0000000 --- a/test/controllers/review_controller_test.rb +++ /dev/null @@ -1,63 +0,0 @@ -# frozen_string_literal: true -require 'test_helper' - -class ReviewControllerTest < ActionDispatch::IntegrationTest - test "should get login" do - get review_login_url - assert_response :success - end - - test "should require auth or redirect" do - get review_url - assert_redirected_to review_login_path - - get review_test_url(candidates(:richard).test_hash) - assert_redirected_to review_login_path - end - - test "should auth to index" do - auth_reviewer - assert_redirected_to admin_path - assert session[:user].present? - end - - test "should fail auth with flash" do - post review_auth_url, params: { auth: - { email: 'fed.review@mailinator.com', password: 'bad-password' } } - - assert_redirected_to review_login_path - assert flash[:error] - end - - test "should get review list" do - auth_reviewer - get review_url - assert_response :success - assert assigns(:candidates), '@candidates not present' - end - - test "should get index" do - auth_reviewer - - get review_url - assert_response :success - end - - test "should get view" do - auth_reviewer - - get review_test_url(candidates(:richard).test_hash) - assert_response :success - assert assigns(:candidate), "@candidate not present" - assert assigns(:quiz), "@quiz not present" - assert assigns(:status), "@status not present" - end - - test 'should logout and reset session' do - auth_reviewer - get review_logout_path - - assert :success - assert session[:user].nil? - end -end diff --git a/test/integration/question_attachments_test.rb b/test/integration/question_attachments_test.rb index e10f3e8..84b4215 100644 --- a/test/integration/question_attachments_test.rb +++ b/test/integration/question_attachments_test.rb @@ -20,10 +20,9 @@ class QuestionAttachmentsTest < ActionDispatch::IntegrationTest end test "should show attachments on review" do - user = users :reviewer - post review_auth_url, params: { auth: { email: user.email, password: 'password' } } + auth_reviewer - get review_test_path(candidates(:richard).test_hash) + get admin_result_path(candidates(:richard).test_hash) assert_response :success assert_select "img[src=\"#{questions(:fed6).attachment}\"]" end