recruiter login + index
This commit is contained in:
		@@ -15,7 +15,7 @@
 | 
				
			|||||||
#
 | 
					#
 | 
				
			||||||
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
 | 
					# 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_helper\.rb$}) { 'test' }
 | 
				
			||||||
  watch(%r{^test/(.*)\/?(.*)_test\.rb$})
 | 
					  watch(%r{^test/(.*)\/?(.*)_test\.rb$})
 | 
				
			||||||
  watch(%r{^app/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
 | 
					  watch(%r{^app/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,21 @@
 | 
				
			|||||||
class ApplicationController < ActionController::Base
 | 
					class ApplicationController < ActionController::Base
 | 
				
			||||||
  protect_from_forgery with: :exception
 | 
					  protect_from_forgery with: :exception
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def current_candidate
 | 
					  def current_recruiter
 | 
				
			||||||
    @current_candidate ||= Candidate.find_by(test_hash: session[:test_id])
 | 
					    @current_recruiter ||= User.find_by(id: session[:user]) if session[:user]
 | 
				
			||||||
  end
 | 
					  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
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										40
									
								
								app/controllers/recruiter_controller.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								app/controllers/recruiter_controller.rb
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
				
			||||||
@@ -26,6 +26,11 @@ class Candidate < ApplicationRecord
 | 
				
			|||||||
    CandidateQuiz.new(id).build_my_quiz
 | 
					    CandidateQuiz.new(id).build_my_quiz
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def status
 | 
				
			||||||
 | 
					    # TODO: quiz status: not started, started, completed
 | 
				
			||||||
 | 
					    "--"
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private
 | 
					  private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def generate_test_hash
 | 
					    def generate_test_hash
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								app/views/recruiter/create.html.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								app/views/recruiter/create.html.erb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					<h1>Recruiter#create</h1>
 | 
				
			||||||
 | 
					<p>Find me in app/views/recruiter/create.html.erb</p>
 | 
				
			||||||
							
								
								
									
										23
									
								
								app/views/recruiter/index.html.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								app/views/recruiter/index.html.erb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					<main class="summary_tpl">
 | 
				
			||||||
 | 
					  <h1>Candidates</h1>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <%= link_to "Create New Candidate", new_candidate_path, {class: 'button'} %>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <table cellspacing="0" cellpadding="0">
 | 
				
			||||||
 | 
					    <tr>
 | 
				
			||||||
 | 
					      <th>Candidate</th>
 | 
				
			||||||
 | 
					      <th>Email</th>
 | 
				
			||||||
 | 
					      <th>Experience</th>
 | 
				
			||||||
 | 
					      <th>Status</th>
 | 
				
			||||||
 | 
					    </tr>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <% @candidates.each do |candidate| %>
 | 
				
			||||||
 | 
					      <tr>
 | 
				
			||||||
 | 
					        <td><%= candidate.name %></td>
 | 
				
			||||||
 | 
					        <td><%= mail_to(candidate.email) %></td>
 | 
				
			||||||
 | 
					        <td><%= candidate.experience %> years</td>
 | 
				
			||||||
 | 
					        <td><%= candidate.status %></td>
 | 
				
			||||||
 | 
					      </tr>
 | 
				
			||||||
 | 
					    <% end %>
 | 
				
			||||||
 | 
					  </table>
 | 
				
			||||||
 | 
					</main>
 | 
				
			||||||
							
								
								
									
										21
									
								
								app/views/recruiter/login.html.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								app/views/recruiter/login.html.erb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					<main class="intro_tpl">
 | 
				
			||||||
 | 
					  <h1>Recruiter Login</h1>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <% if flash[:error].present? %>
 | 
				
			||||||
 | 
					    <div class="error"><%= flash[:error] %></div>
 | 
				
			||||||
 | 
					  <% end %>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <%= form_for :auth, url: recruiter_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>
 | 
				
			||||||
							
								
								
									
										2
									
								
								app/views/recruiter/new.html.erb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								app/views/recruiter/new.html.erb
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					<h1>Create new candidate</h1>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -11,6 +11,15 @@ Rails.application.routes.draw do
 | 
				
			|||||||
  post "/summary",                       to: "candidate#update_summary", as: :post_summary
 | 
					  post "/summary",                       to: "candidate#update_summary", as: :post_summary
 | 
				
			||||||
   get "/summary",                       to: "candidate#summary",        as: :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"
 | 
					  root to: "candidate#welcome"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
 | 
					  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										56
									
								
								test/controllers/recruiter_controller_test.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								test/controllers/recruiter_controller_test.rb
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
				
			||||||
							
								
								
									
										8
									
								
								test/fixtures/candidates.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								test/fixtures/candidates.yml
									
									
									
									
										vendored
									
									
								
							@@ -4,7 +4,7 @@ roy:
 | 
				
			|||||||
  name: Roy Cruz
 | 
					  name: Roy Cruz
 | 
				
			||||||
  email: roy.cruz@mailinator.com
 | 
					  email: roy.cruz@mailinator.com
 | 
				
			||||||
  experience: 0-3
 | 
					  experience: 0-3
 | 
				
			||||||
  recruiter: reviewer
 | 
					  recruiter: recruiter
 | 
				
			||||||
  quiz: fed
 | 
					  quiz: fed
 | 
				
			||||||
  completed: false
 | 
					  completed: false
 | 
				
			||||||
  reminded: false
 | 
					  reminded: false
 | 
				
			||||||
@@ -14,7 +14,7 @@ martha:
 | 
				
			|||||||
  name: Martha Watts
 | 
					  name: Martha Watts
 | 
				
			||||||
  email: martha.watts@mailinator.com
 | 
					  email: martha.watts@mailinator.com
 | 
				
			||||||
  experience: 4-6
 | 
					  experience: 4-6
 | 
				
			||||||
  recruiter: reviewer
 | 
					  recruiter: recruiter
 | 
				
			||||||
  quiz: fed
 | 
					  quiz: fed
 | 
				
			||||||
  completed: false
 | 
					  completed: false
 | 
				
			||||||
  reminded: false
 | 
					  reminded: false
 | 
				
			||||||
@@ -24,7 +24,7 @@ dawn:
 | 
				
			|||||||
  name: Dawn Hopkins
 | 
					  name: Dawn Hopkins
 | 
				
			||||||
  email: dawn.hopkins@mailinator.com
 | 
					  email: dawn.hopkins@mailinator.com
 | 
				
			||||||
  experience: 0-2
 | 
					  experience: 0-2
 | 
				
			||||||
  recruiter: reviewer
 | 
					  recruiter: recruiter
 | 
				
			||||||
  quiz: fed
 | 
					  quiz: fed
 | 
				
			||||||
  completed: false
 | 
					  completed: false
 | 
				
			||||||
  reminded: true
 | 
					  reminded: true
 | 
				
			||||||
@@ -34,7 +34,7 @@ richard:
 | 
				
			|||||||
  name: Richard Burns
 | 
					  name: Richard Burns
 | 
				
			||||||
  email: richard.burns@mailinator.com
 | 
					  email: richard.burns@mailinator.com
 | 
				
			||||||
  experience: 15+
 | 
					  experience: 15+
 | 
				
			||||||
  recruiter: reviewer
 | 
					  recruiter: recruiter
 | 
				
			||||||
  quiz: fed
 | 
					  quiz: fed
 | 
				
			||||||
  completed: true
 | 
					  completed: true
 | 
				
			||||||
  reminded: false
 | 
					  reminded: false
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user