diff --git a/Guardfile b/Guardfile
index 738d098..3a072a4 100644
--- a/Guardfile
+++ b/Guardfile
@@ -15,7 +15,7 @@
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
-guard :minitest, spring: true, all_after_pass: true do
+guard :minitest, spring: true do # , all_after_pass: true
watch(%r{^test/test_helper\.rb$}) { 'test' }
watch(%r{^test/(.*)\/?(.*)_test\.rb$})
watch(%r{^app/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 7bd799d..cb5e9bf 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,7 +1,21 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
- def current_candidate
- @current_candidate ||= Candidate.find_by(test_hash: session[:test_id])
+ def current_recruiter
+ @current_recruiter ||= User.find_by(id: session[:user]) if session[:user]
end
+
+ def current_candidate
+ @current_candidate ||= Candidate.find_by(test_hash: session[:test_id]) if session[:test_id]
+ end
+
+ private
+
+ def auth_params
+ params.require(:auth).permit(:email, :password)
+ end
+
+ def authorize_recruiter
+ redirect_to recruiter_login_path unless current_recruiter
+ end
end
diff --git a/app/controllers/recruiter_controller.rb b/app/controllers/recruiter_controller.rb
new file mode 100644
index 0000000..0b51426
--- /dev/null
+++ b/app/controllers/recruiter_controller.rb
@@ -0,0 +1,40 @@
+class RecruiterController < ApplicationController
+ before_action :authorize_recruiter, except: [:login, :auth]
+
+ def index
+ @candidates = current_recruiter.candidates
+ end
+
+ def new
+ @candidate = Candidate.new
+ end
+
+ def create
+ end
+
+ def login
+ redirect_to recruiter_path unless current_recruiter.nil?
+ end
+
+ def auth
+ recruiter = User.find_by(email: auth_params[:email])
+
+ if recruiter && recruiter.authenticate(auth_params[:password])
+ session[:user] = recruiter.to_i
+ redirect_to recruiter_path
+ else
+ redirect_to recruiter_login_path, flash: { error: "Sorry, incorrect email or password." }
+ end
+ end
+
+ def logout
+ reset_session
+ redirect_to recruiter_login_path
+ end
+
+ private
+
+ def candidate_params
+ params.require(:candidate).permit(:name, :email, :experience, :quiz_id)
+ end
+end
diff --git a/app/models/candidate.rb b/app/models/candidate.rb
index b6bce4a..482864a 100644
--- a/app/models/candidate.rb
+++ b/app/models/candidate.rb
@@ -26,6 +26,11 @@ class Candidate < ApplicationRecord
CandidateQuiz.new(id).build_my_quiz
end
+ def status
+ # TODO: quiz status: not started, started, completed
+ "--"
+ end
+
private
def generate_test_hash
diff --git a/app/views/recruiter/create.html.erb b/app/views/recruiter/create.html.erb
new file mode 100644
index 0000000..abf096a
--- /dev/null
+++ b/app/views/recruiter/create.html.erb
@@ -0,0 +1,2 @@
+
Recruiter#create
+Find me in app/views/recruiter/create.html.erb
diff --git a/app/views/recruiter/index.html.erb b/app/views/recruiter/index.html.erb
new file mode 100644
index 0000000..65c7b7d
--- /dev/null
+++ b/app/views/recruiter/index.html.erb
@@ -0,0 +1,23 @@
+
+ Candidates
+
+ <%= link_to "Create New Candidate", new_candidate_path, {class: 'button'} %>
+
+
+
+ Candidate |
+ Email |
+ Experience |
+ Status |
+
+
+ <% @candidates.each do |candidate| %>
+
+ <%= candidate.name %> |
+ <%= mail_to(candidate.email) %> |
+ <%= candidate.experience %> years |
+ <%= candidate.status %> |
+
+ <% end %>
+
+
diff --git a/app/views/recruiter/login.html.erb b/app/views/recruiter/login.html.erb
new file mode 100644
index 0000000..abfa894
--- /dev/null
+++ b/app/views/recruiter/login.html.erb
@@ -0,0 +1,21 @@
+
+ Recruiter Login
+
+ <% if flash[:error].present? %>
+ <%= flash[:error] %>
+ <% end %>
+
+ <%= form_for :auth, url: recruiter_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/recruiter/new.html.erb b/app/views/recruiter/new.html.erb
new file mode 100644
index 0000000..6afd6ab
--- /dev/null
+++ b/app/views/recruiter/new.html.erb
@@ -0,0 +1,2 @@
+Create new candidate
+
diff --git a/config/routes.rb b/config/routes.rb
index d52d09c..410be75 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -11,6 +11,15 @@ Rails.application.routes.draw do
post "/summary", to: "candidate#update_summary", as: :post_summary
get "/summary", to: "candidate#summary", as: :summary
+ get "/review", to: "review#index", as: :review
+
+ get "/recruiter", to: "recruiter#index", as: :recruiter
+ get "/recruiter/new-candidate", to: "recruiter#new", as: :new_candidate
+ post "/recruiter/new-candidate", to: "recruiter#create", as: :create_candidate
+ get "/recruiter/logout", to: "recruiter#logout", as: :recruiter_logout
+ get "/recruiter/login", to: "recruiter#login", as: :recruiter_login
+ post "/recruiter/login", to: "recruiter#auth", as: :recruiter_auth
+
root to: "candidate#welcome"
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
diff --git a/test/controllers/recruiter_controller_test.rb b/test/controllers/recruiter_controller_test.rb
new file mode 100644
index 0000000..e3bfe7f
--- /dev/null
+++ b/test/controllers/recruiter_controller_test.rb
@@ -0,0 +1,56 @@
+require 'test_helper'
+
+class RecruiterControllerTest < ActionDispatch::IntegrationTest
+ def setup_auth
+ post recruiter_auth_url, params: { auth:
+ { email: 'pdr.recruiter@mailinator.com', password: 'password' } }
+ end
+
+ test "should get login" do
+ get recruiter_login_url
+ assert_response :success
+ end
+
+ test "should require auth or redirect" do
+ get recruiter_url
+ assert_redirected_to recruiter_login_path
+
+ get new_candidate_url
+ assert_redirected_to recruiter_login_path
+
+ post create_candidate_url, params: { candidate: { name: 'foo', email: 'bar', experience: 'baz' } }
+ assert_redirected_to recruiter_login_path
+ end
+
+ test "should auth to index" do
+ setup_auth
+ assert_redirected_to recruiter_path
+ assert session[:user].present?
+ end
+
+ test "should fail auth with flash" do
+ post recruiter_auth_url, params: { auth:
+ { email: 'pdr.recruiter@mailinator.com', password: 'bad-password' } }
+
+ assert_redirected_to recruiter_login_path
+ assert flash[:error]
+ end
+
+ test "should get candidate list" do
+ setup_auth
+ get recruiter_url
+ assert_response :success
+ end
+
+ test "should get new" do
+ setup_auth
+ get new_candidate_url
+ assert_response :success
+ end
+
+ test "should get create" do
+ setup_auth
+ get create_candidate_url
+ assert_response :success
+ end
+end
diff --git a/test/fixtures/candidates.yml b/test/fixtures/candidates.yml
index c5c8342..7eeca9e 100644
--- a/test/fixtures/candidates.yml
+++ b/test/fixtures/candidates.yml
@@ -4,7 +4,7 @@ roy:
name: Roy Cruz
email: roy.cruz@mailinator.com
experience: 0-3
- recruiter: reviewer
+ recruiter: recruiter
quiz: fed
completed: false
reminded: false
@@ -14,7 +14,7 @@ martha:
name: Martha Watts
email: martha.watts@mailinator.com
experience: 4-6
- recruiter: reviewer
+ recruiter: recruiter
quiz: fed
completed: false
reminded: false
@@ -24,7 +24,7 @@ dawn:
name: Dawn Hopkins
email: dawn.hopkins@mailinator.com
experience: 0-2
- recruiter: reviewer
+ recruiter: recruiter
quiz: fed
completed: false
reminded: true
@@ -34,7 +34,7 @@ richard:
name: Richard Burns
email: richard.burns@mailinator.com
experience: 15+
- recruiter: reviewer
+ recruiter: recruiter
quiz: fed
completed: true
reminded: false