review
This commit is contained in:
parent
abb3dee9f5
commit
ace9b864d3
@ -2,7 +2,13 @@ class ApplicationController < ActionController::Base
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
def current_recruiter
|
||||
@current_recruiter ||= User.find_by(id: session[:user]) if session[:user]
|
||||
user_parms = { id: session[:user], role: %w(admin recruiter) }
|
||||
@current_recruiter ||= User.find_by(user_parms) if session[:user]
|
||||
end
|
||||
|
||||
def current_reviewer
|
||||
user_parms = { id: session[:user], role: %w(admin reviewer) }
|
||||
@current_reviewer ||= User.find_by(user_parms) if session[:user]
|
||||
end
|
||||
|
||||
def current_candidate
|
||||
@ -18,4 +24,8 @@ class ApplicationController < ActionController::Base
|
||||
def authorize_recruiter
|
||||
redirect_to recruiter_login_path unless current_recruiter
|
||||
end
|
||||
|
||||
def authorize_reviewer
|
||||
redirect_to review_login_path unless current_reviewer
|
||||
end
|
||||
end
|
||||
|
@ -26,7 +26,7 @@ class RecruiterController < ApplicationController
|
||||
end
|
||||
|
||||
def auth
|
||||
recruiter = User.find_by(email: auth_params[:email])
|
||||
recruiter = User.find_by(email: auth_params[:email], role: %w(admin recruiter))
|
||||
|
||||
if recruiter && recruiter.authenticate(auth_params[:password])
|
||||
session[:user] = recruiter.to_i
|
||||
|
33
app/controllers/review_controller.rb
Normal file
33
app/controllers/review_controller.rb
Normal file
@ -0,0 +1,33 @@
|
||||
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." }
|
||||
end
|
||||
end
|
||||
|
||||
def logout
|
||||
reset_session
|
||||
redirect_to review_login_path
|
||||
end
|
||||
end
|
@ -1,7 +1,9 @@
|
||||
<main class="summary_tpl">
|
||||
<h1>Candidates</h1>
|
||||
|
||||
<%= link_to "Create New Candidate", new_candidate_path, {class: 'button'} %>
|
||||
<%= link_to(new_candidate_path, { class: 'secondary-btn' }) do %>
|
||||
<button>Create New Candidate</button>
|
||||
<% end %>
|
||||
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
|
19
app/views/review/index.html.erb
Normal file
19
app/views/review/index.html.erb
Normal file
@ -0,0 +1,19 @@
|
||||
<main class="summary_tpl">
|
||||
<h1>Completed Tests</h1>
|
||||
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<th>Test ID</th>
|
||||
<th>Experience</th>
|
||||
<th>Recruiter</th>
|
||||
</tr>
|
||||
|
||||
<% @candidates.each do |candidate| %>
|
||||
<tr>
|
||||
<td><%= link_to candidate.test_hash, review_test_path(candidate.test_hash) %></td>
|
||||
<td><%= candidate.experience %> years</td>
|
||||
<td><%= mail_to(candidate.recruiter.email) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
</main>
|
21
app/views/review/login.html.erb
Normal file
21
app/views/review/login.html.erb
Normal file
@ -0,0 +1,21 @@
|
||||
<main class="intro_tpl">
|
||||
<h1>Reviewer Login</h1>
|
||||
|
||||
<% if flash[:error].present? %>
|
||||
<div class="error"><%= flash[:error] %></div>
|
||||
<% end %>
|
||||
|
||||
<%= form_for :auth, url: review_login_path do |form| %>
|
||||
<div class="form-group">
|
||||
<%= form.label :email %>
|
||||
<%= form.email_field :email %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :password %>
|
||||
<%= form.password_field :password %>
|
||||
</div>
|
||||
|
||||
<%= submit_tag "Login" %>
|
||||
<% end %>
|
||||
</main>
|
31
app/views/review/view.html.erb
Normal file
31
app/views/review/view.html.erb
Normal file
@ -0,0 +1,31 @@
|
||||
<main class="summary_tpl">
|
||||
<h2 class="prft-heading">Quiz Review</h2>
|
||||
<p>
|
||||
<strong>Test ID:</strong> <%= @candidate.test_hash %><br />
|
||||
<strong>Years of Experience:</strong> <%= @candidate.experience %><br />
|
||||
<strong>Recruiter Email:</strong> <%= mail_to @candidate.recruiter.name, @candidate.recruiter.email %><br />
|
||||
</p>
|
||||
|
||||
<% @quiz.each do |question| %>
|
||||
<%= form_for(:answer, url: post_summary_path, html:{id: 'summary-form'}) do |form| %>
|
||||
<article class="answer-sec <%= question.input_type %>-type" data-qid="<%= question.question_id %>">
|
||||
<div class="question-heading">
|
||||
<div class="question-title">
|
||||
<h3><%= question.question %></h3>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="answer-container">
|
||||
<fieldset disabled class="answer-block">
|
||||
<%= hidden_field_tag 'answer[question_id]', question.question_id %>
|
||||
<%= render partial: "candidate/#{question.input_type}", locals: {question: question, form: form} %>
|
||||
</fieldset>
|
||||
</div>
|
||||
</article>
|
||||
<% end #form_tag %>
|
||||
<% end #questions loop %>
|
||||
|
||||
<%= link_to(review_path, { class: 'secondary-btn' }) do %>
|
||||
<button>Back to list</button>
|
||||
<% end %>
|
||||
</main>
|
@ -11,7 +11,11 @@ Rails.application.routes.draw do
|
||||
post "/summary", to: "candidate#update_summary", as: :post_summary
|
||||
get "/summary", to: "candidate#summary", as: :summary
|
||||
|
||||
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 "/recruiter", to: "recruiter#index", as: :recruiter
|
||||
get "/recruiter/new-candidate", to: "recruiter#new", as: :new_candidate
|
||||
|
55
test/controllers/review_controller_test.rb
Normal file
55
test/controllers/review_controller_test.rb
Normal file
@ -0,0 +1,55 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ReviewControllerTest < ActionDispatch::IntegrationTest
|
||||
def setup_auth
|
||||
post review_auth_url, params: { auth:
|
||||
{ email: 'fed.reviewer@mailinator.com', password: 'password' } }
|
||||
end
|
||||
|
||||
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
|
||||
setup_auth
|
||||
assert_redirected_to review_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
|
||||
setup_auth
|
||||
get review_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
setup_auth
|
||||
|
||||
get review_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get view" do
|
||||
setup_auth
|
||||
|
||||
get review_test_url(candidates(:richard).test_hash)
|
||||
assert_response :success
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user