split login/welcome and added direct link welcome

This commit is contained in:
Mark Moser 2016-08-02 18:02:20 -05:00
parent 7bdb86f89f
commit 737fd10636
9 changed files with 125 additions and 85 deletions

View File

@ -30,6 +30,6 @@ class ApplicationController < ActionController::Base
end
def authorize_candidate
redirect_to welcome_path unless current_candidate
redirect_to login_path unless current_candidate
end
end

View File

@ -1,5 +1,14 @@
class CandidateController < ApplicationController
before_action :authorize_candidate, except: [:welcome, :validate, :live_coder]
before_action :authorize_candidate, except: [:login, :validate, :live_coder]
before_action :send_to_oops, only: [:login]
def login
login_candidate
redirect_to :thankyou and return if current_candidate && current_candidate.completed?
redirect_to :welcome if current_candidate
flash[:error] = "Sorry, incorrect test id" if params[:test_hash].present?
end
def welcome
end
@ -7,6 +16,9 @@ class CandidateController < ApplicationController
def saved
end
def oops
end
def thankyou
redirect_to root_path if session[:test_id].nil?
reset_session
@ -52,11 +64,22 @@ class CandidateController < ApplicationController
session[:test_id] = candidate.test_hash
redirect_to :thankyou and return if candidate.completed?
redirect_to :question
redirect_to :welcome
end
private
def login_candidate
candidate = Candidate.find_by(test_hash: params['test_id'])
return false if candidate.nil?
session[:test_id] = candidate.test_hash
end
def send_to_oops
redirect_to oops_path if current_candidate
end
def prep_question qid
@question = current_candidate.fetch_question(qid)
end

View File

@ -0,0 +1,20 @@
<% content_for :title, "Skills Assessment" %>
<main class="intro_tpl">
<h1 class="prft-heading">Let's Get Started</h1>
<p>
Hey there! Give us your test id, and we'll get you started.
</p>
<%= form_tag(validate_candidate_path) do %>
<div class="form-group">
<label for="userid">What's your Test ID?</label>
<input type="text" id="test_id" name="test_id" required/>
<% if flash[:error].present? %>
<div class="error"><%= flash[:error] %></div>
<% end %>
</div>
<button type="submit">Login</button>
<% end %>
</main>

View File

@ -0,0 +1,9 @@
<main class="intro_tpl">
<h1 class="prft-heading">Oops!</h1>
<p>
Looks like you hit the browser's Back button. You can't go backwards in the test,
but you'll have a chance at the end to review your answers and make changes.
</p>
<a href="<%= question_path %>"><button>Continue Test</button></a>
</main>

View File

@ -1,21 +1,7 @@
<% content_for :title, "Skills Assessment" %>
<% if session[:test_id].present? %>
<main class="intro_tpl">
<h1 class="prft-heading">Oops!</h1>
<p>
Looks like you hit the browser's Back button. You can't go backwards in the test,
but you'll have a chance at the end to review your answers and make changes.
</p>
<a href="<%= question_path %>"><button>Continue Test</button></a>
</main>
<% else %>
<main class="intro_tpl">
<h1 class="prft-heading">Let's Get Started</h1>
<h1 class="prft-heading">Welcome!</h1>
<p>
This is a skills assessment test. It's the first step in the process of interviewing
for a Front-End Development position with Perficient Digital.
@ -34,17 +20,7 @@
answers, we will review your assessment and your recruiter will be in touch.
</p>
<%= form_tag(validate_candidate_path) do %>
<div class="form-group">
<label for="userid">What's your User ID?</label>
<input type="text" id="test_id" name="test_id" required/>
<% if flash[:error].present? %>
<div class="error"><%= flash[:error] %></div>
<% end %>
</div>
<%= link_to question_path do %>
<button type="submit">Begin</button>
<% end %>
</main>
<% end %>

View File

@ -17,9 +17,10 @@
<td style="padding:15px 20px; background-color:#cdcdcd; text-align:center;">
<h4>
Please visit <%= link_to nil, root_url %>
and enter the above Candidate ID to being your test.
Please visit <%= link_to nil, login_url(@candidate.test_hash) %> to get started.
</h4>
<p>If you would rather, visit <%= link_to nil, root_url %>
and enter the above Candidate ID to being your test.</p>
<h5>We will reach back to you once we have evaluated your answers. Good luck!</h5>
</td>

View File

@ -1,10 +1,9 @@
PERFICIENT DIGITAL - Skills Assessment Test
Your Candidate ID is <%= @candidate.test_hash %>
Please visit <%= login_url(@candidate.test_hash) %> to get started.
Please visit <%= root_url %>
and enter the above Candidate ID to being your test.
Or, visit <%= root_url %> and enter your Candidate ID to being your test.
Your Candidate ID is: <%= @candidate.test_hash %>
We will reach back to you once we have evaluated your answers.
Good luck!

View File

@ -1,8 +1,10 @@
Rails.application.routes.draw do
post "/validate", to: "candidate#validate", as: :validate_candidate
get "/login(/:test_id)", to: "candidate#login", as: :login
get "/welcome", to: "candidate#welcome", as: :welcome
get "/thankyou", to: "candidate#thankyou", as: :thankyou
get "/saved", to: "candidate#saved", as: :saved
get "/thankyou", to: "candidate#thankyou", as: :thankyou
get "/oops", to: "candidate#oops", as: :oops
post "/question(/:answer_id)", to: "candidate#update_answer", as: :post_answer
get "/question(/:question_id)", to: "candidate#question", as: :question
@ -24,7 +26,7 @@ Rails.application.routes.draw do
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#login"
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

View File

@ -6,32 +6,42 @@ class CandidateControllerTest < ActionDispatch::IntegrationTest
end
test "should get login" do
get welcome_path
get login_path
assert_response :success
refute flash[:error].present?, "Should not be displaying an error message"
end
test "should require auth and redirect" do
get saved_path
assert_redirected_to welcome_path
assert_redirected_to login_path
get thankyou_path
assert_redirected_to welcome_path
assert_redirected_to login_path
get summary_path
assert_redirected_to welcome_path
assert_redirected_to login_path
get question_path
assert_redirected_to welcome_path
assert_redirected_to login_path
get question_path(questions(:fed1).id)
assert_redirected_to welcome_path
assert_redirected_to login_path
end
test "should auth to question" do
test "should auth to welcome" do
setup_auth candidates(:martha)
assert_redirected_to question_path
assert_redirected_to welcome_path
assert session[:test_id].present?
refute flash[:error].present?, "Should not be displaying an error message"
end
test "should auth directly to welcome" do
get login_path(candidates(:martha).test_hash)
assert_redirected_to welcome_path
assert session[:test_id].present?
refute flash[:error].present?, "Should not be displaying an error message"
end
test "should redirect to thankyou when completed" do