parent
f17ed8e8b1
commit
a51a751524
@ -63,8 +63,9 @@ guard :minitest, spring: "bin/rails test", all_after_pass: true do
|
||||
watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
|
||||
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
||||
watch(%r{^test/.+_test\.rb$})
|
||||
# run controller/integration test when touching erb files
|
||||
# run controller/integration test when touching the router or erb files
|
||||
watch(%r{^app/views/((?!_mailer).)*([^/]+)\.erb$}) { ["test/controllers", "test/integration"] }
|
||||
watch(%r{^config/routes.rb}) { ["test/controllers", "test/integration"] }
|
||||
# run mailers/integration test when touching mailer erb files
|
||||
watch(%r{^app/views/(.*_mailer/)?([^/]+)\.erb$}) { ["test/mailers", "test/integration"] }
|
||||
end
|
||||
|
@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
class RecruiterController < ApplicationController
|
||||
before_action :authorize_recruiter, except: [:login, :auth]
|
||||
before_action :collect_quizzes, except: [:login, :auth]
|
||||
|
||||
def index
|
||||
@candidates = current_recruiter.candidates
|
||||
@ -8,12 +9,10 @@ class RecruiterController < ApplicationController
|
||||
|
||||
def new
|
||||
@candidate = Candidate.new
|
||||
@quizzes = Quiz.order(:name)
|
||||
render :form
|
||||
render :new
|
||||
end
|
||||
|
||||
def create
|
||||
@quizzes = Quiz.order(:name)
|
||||
@candidate = Candidate.create(candidate_params.merge(recruiter_id: current_recruiter.id))
|
||||
|
||||
if @candidate.persisted?
|
||||
@ -22,7 +21,23 @@ class RecruiterController < ApplicationController
|
||||
redirect_to recruiter_path, flash: { success: "Sucessfully created candidate #{@candidate.name}" }
|
||||
else
|
||||
flash[:error] = "Failed to save candidate."
|
||||
render :form
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@candidate = Candidate.find_by(id: params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@candidate = Candidate.find_by(id: params[:id])
|
||||
@candidate.update(candidate_params)
|
||||
|
||||
if @candidate.save
|
||||
redirect_to recruiter_path, flash: { success: "#{@candidate.name} updated!" }
|
||||
else
|
||||
flash[:error] = "Failed to save candidate."
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
@ -58,4 +73,8 @@ class RecruiterController < ApplicationController
|
||||
def candidate_params
|
||||
params.require(:candidate).permit(:name, :email, :experience, :quiz_id)
|
||||
end
|
||||
|
||||
def collect_quizzes
|
||||
@quizzes ||= Quiz.order(:name)
|
||||
end
|
||||
end
|
||||
|
@ -11,6 +11,10 @@ module ApplicationHelper
|
||||
], disabled: "-", selected: (val.blank? ? '' : val))
|
||||
end
|
||||
|
||||
def quiz_options quizzes, selected_val
|
||||
options_from_collection_for_select(quizzes, 'id', 'name', selected_val)
|
||||
end
|
||||
|
||||
def admin_role_options val
|
||||
options_for_select([
|
||||
%w(Reviewer reviewer),
|
||||
|
25
app/views/recruiter/_form.html.erb
Normal file
25
app/views/recruiter/_form.html.erb
Normal file
@ -0,0 +1,25 @@
|
||||
<%= render partial: 'shared/form_model_errors', locals: { obj: candidate } %>
|
||||
|
||||
<%= form_for candidate, url: create_candidate_path do |form| %>
|
||||
<div class="form-group">
|
||||
<%= form.label :name, "Candidate name" %>
|
||||
<%= form.text_field :name %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :email, "Candidate email" %>
|
||||
<%= form.email_field :email %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :experience, "Years of experience" %>
|
||||
<%= form.select :experience, experience_options(candidate.experience), include_blank: false %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :quiz_id, "Quiz" %>
|
||||
<%= form.select :quiz_id, quiz_options(quizzes, candidate.quiz_id), include_blank: (quizzes.size > 1) %>
|
||||
</div>
|
||||
|
||||
<%= submit_tag %>
|
||||
<% end %>
|
6
app/views/recruiter/edit.html.erb
Normal file
6
app/views/recruiter/edit.html.erb
Normal file
@ -0,0 +1,6 @@
|
||||
<main class="intro_tpl">
|
||||
<h1>Edit: <%= @candidate.name %></h1>
|
||||
<p><strong>Test ID: </strong><%= @candidate.test_hash %></p>
|
||||
|
||||
<%= render partial: 'form', locals: { candidate: @candidate, quizzes: @quizzes } %>
|
||||
</main>
|
@ -1,28 +0,0 @@
|
||||
<main class="intro_tpl">
|
||||
<h1>New Candidate</h1>
|
||||
|
||||
<%= render partial: 'shared/form_model_errors', locals: { obj: @candidate } %>
|
||||
<%= form_for @candidate, url: create_candidate_path do |form| %>
|
||||
<div class="form-group">
|
||||
<%= form.label :name, "Candidate name" %>
|
||||
<%= form.text_field :name %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :email, "Candidate email" %>
|
||||
<%= form.email_field :email %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :experience, "Years of experience" %>
|
||||
<%= form.select :experience, experience_options(@candidate.experience), include_blank: false %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :quiz_id, "Quiz" %>
|
||||
<%= form.select :quiz_id, options_from_collection_for_select(@quizzes, 'id', 'name'), include_blank: (@quizzes.size > 1) %>
|
||||
</div>
|
||||
|
||||
<%= submit_tag "Create" %>
|
||||
<% end %>
|
||||
</main>
|
@ -18,7 +18,7 @@
|
||||
|
||||
<% @candidates.each do |candidate| %>
|
||||
<tr>
|
||||
<td><%= candidate.name %></td>
|
||||
<td><%= link_to candidate.name, edit_candidate_path(candidate.id) %></td>
|
||||
<td><%= candidate.test_hash %></td>
|
||||
<td>
|
||||
<%= mail_to(candidate.email) %>
|
||||
|
5
app/views/recruiter/new.html.erb
Normal file
5
app/views/recruiter/new.html.erb
Normal file
@ -0,0 +1,5 @@
|
||||
<main class="intro_tpl">
|
||||
<h1>New Candidate</h1>
|
||||
|
||||
<%= render partial: 'form', locals: { candidate: @candidate, quizzes: @quizzes } %>
|
||||
</main>
|
@ -63,8 +63,10 @@ Rails.application.routes.draw do
|
||||
get "/resend/welcome/:id", to: "recruiter#resend_welcome", as: :resend_welcome
|
||||
|
||||
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/candidate", to: "recruiter#new", as: :new_candidate
|
||||
post "/recruiter/candidate", to: "recruiter#create", as: :create_candidate
|
||||
get "/recruiter/candidate/:id", to: "recruiter#edit", as: :edit_candidate
|
||||
post "/recruiter/candidate/:id", to: "recruiter#update", as: :update_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
|
||||
|
56
test/controllers/recruiter_controller/index_test.rb
Normal file
56
test/controllers/recruiter_controller/index_test.rb
Normal file
@ -0,0 +1,56 @@
|
||||
# frozen_string_literal: true
|
||||
require 'test_helper'
|
||||
|
||||
class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
test "should get login" do
|
||||
get recruiter_login_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test 'should logout and reset session' do
|
||||
auth_recruiter
|
||||
get recruiter_logout_path
|
||||
|
||||
assert :success
|
||||
assert session[:user].nil?
|
||||
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
|
||||
auth_recruiter
|
||||
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
|
||||
auth_recruiter
|
||||
get recruiter_url
|
||||
assert_response :success
|
||||
assert assigns(:candidates), "@candidates not present"
|
||||
end
|
||||
|
||||
test 'should have edit links' do
|
||||
auth_recruiter
|
||||
get recruiter_url
|
||||
assert_response :success
|
||||
assert_select "a[href='#{edit_candidate_path(candidates(:martha))}']"
|
||||
end
|
||||
end
|
@ -4,51 +4,6 @@ require 'test_helper'
|
||||
class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
test "should get login" do
|
||||
get recruiter_login_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test 'should logout and reset session' do
|
||||
auth_recruiter
|
||||
get recruiter_logout_path
|
||||
|
||||
assert :success
|
||||
assert session[:user].nil?
|
||||
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
|
||||
auth_recruiter
|
||||
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
|
||||
auth_recruiter
|
||||
get recruiter_url
|
||||
assert_response :success
|
||||
assert assigns(:candidates), "@candidates not present"
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
auth_recruiter
|
||||
get new_candidate_url
|
@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
require 'test_helper'
|
||||
|
||||
class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
test 'should edit candidate' do
|
||||
auth_recruiter
|
||||
candidate = candidates(:martha)
|
||||
|
||||
get edit_candidate_path(candidate.id)
|
||||
assert_response :success
|
||||
assert_select 'form'
|
||||
end
|
||||
|
||||
test 'should update candidate, but NOT test_hash' do
|
||||
auth_recruiter
|
||||
candidate = candidates(:martha)
|
||||
post update_candidate_url(id: candidate.id), params:
|
||||
{ candidate: { name: 'new name', email: "mail@martha.me", test_hash: 'SOMENEWSTRING' } }
|
||||
|
||||
refute_equal candidate.name, Candidate.find_by(id: candidate.id).name
|
||||
assert_equal candidate.test_hash, Candidate.find_by(id: candidate.id).test_hash
|
||||
assert_redirected_to recruiter_url
|
||||
end
|
||||
|
||||
test 'should redirect to form on fail' do
|
||||
auth_recruiter
|
||||
candidate = candidates(:martha)
|
||||
post update_candidate_url(id: candidate.id), params:
|
||||
{ candidate: { name: 'new name', email: "mail@martha" } }
|
||||
|
||||
assert :success
|
||||
assert_match(/failed.*save/i, flash[:error])
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user