diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index c2965a3..ed68e9d 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -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
diff --git a/app/controllers/candidate_controller.rb b/app/controllers/candidate_controller.rb
index 8b537bc..6031fc4 100644
--- a/app/controllers/candidate_controller.rb
+++ b/app/controllers/candidate_controller.rb
@@ -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
diff --git a/app/views/candidate/login.html.erb b/app/views/candidate/login.html.erb
new file mode 100644
index 0000000..35ee06d
--- /dev/null
+++ b/app/views/candidate/login.html.erb
@@ -0,0 +1,20 @@
+<% content_for :title, "Skills Assessment" %>
+
+
+
Let's Get Started
+
+ Hey there! Give us your test id, and we'll get you started.
+
+
+ <%= form_tag(validate_candidate_path) do %>
+
+
+
+
+ <% if flash[:error].present? %>
+
<%= flash[:error] %>
+ <% end %>
+
+
+ <% end %>
+
diff --git a/app/views/candidate/oops.html.erb b/app/views/candidate/oops.html.erb
new file mode 100644
index 0000000..81eda59
--- /dev/null
+++ b/app/views/candidate/oops.html.erb
@@ -0,0 +1,9 @@
+
+
Oops!
+
+ 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.
+
+ 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.
+
+
+ The questions will test your knowledge in the areas of HTML, CSS, and JavaScript.
+ Please note that you can only move forward through the test, not back,
+ and you must attempt to answer the question before moving to the
+ next one. You'll have an opportunity at the end of the test to review and update your
+ answers if need be. At any time, you may save your progress and log back in to continue
+ taking the test from where you left off.
+
+
+ Please answer to the best of your ability—it's totally okay to say
+ "I don't know"!—and above all, relax and have fun! Once you submit your
+ answers, we will review your assessment and your recruiter will be in touch.
+
-
-
Oops!
-
- 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.
-
-
-
-
-
-<% else %>
-
-
-
Let's Get Started
-
- 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.
-
-
- The questions will test your knowledge in the areas of HTML, CSS, and JavaScript.
- Please note that you can only move forward through the test, not back,
- and you must attempt to answer the question before moving to the
- next one. You'll have an opportunity at the end of the test to review and update your
- answers if need be. At any time, you may save your progress and log back in to continue
- taking the test from where you left off.
-
-
- Please answer to the best of your ability—it's totally okay to say
- "I don't know"!—and above all, relax and have fun! Once you submit your
- answers, we will review your assessment and your recruiter will be in touch.
-
-
- <%= form_tag(validate_candidate_path) do %>
-
-
-
-
- <% if flash[:error].present? %>
-
<%= flash[:error] %>
- <% end %>
-
-
- <% end %>
-
-
-<% end %>
+ <%= link_to question_path do %>
+
+ <% end %>
+
diff --git a/app/views/candidate_mailer/welcome.html.erb b/app/views/candidate_mailer/welcome.html.erb
index 3336217..e458d56 100644
--- a/app/views/candidate_mailer/welcome.html.erb
+++ b/app/views/candidate_mailer/welcome.html.erb
@@ -17,9 +17,10 @@
- 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.
+
If you would rather, visit <%= link_to nil, root_url %>
+ and enter the above Candidate ID to being your test.
We will reach back to you once we have evaluated your answers. Good luck!
diff --git a/app/views/candidate_mailer/welcome.text.erb b/app/views/candidate_mailer/welcome.text.erb
index 6194b9a..5e1fe81 100644
--- a/app/views/candidate_mailer/welcome.text.erb
+++ b/app/views/candidate_mailer/welcome.text.erb
@@ -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!
diff --git a/config/routes.rb b/config/routes.rb
index ba5d123..ba4630d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,30 +1,32 @@
Rails.application.routes.draw do
- post "/validate", to: "candidate#validate", as: :validate_candidate
- get "/welcome", to: "candidate#welcome", as: :welcome
- get "/thankyou", to: "candidate#thankyou", as: :thankyou
- get "/saved", to: "candidate#saved", as: :saved
+ 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 "/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
- get "/live-coder-entry/:question_id", to: "candidate#live_coder", as: :live_coder
+ post "/question(/:answer_id)", to: "candidate#update_answer", as: :post_answer
+ get "/question(/:question_id)", to: "candidate#question", as: :question
+ get "/live-coder-entry/:question_id", to: "candidate#live_coder", as: :live_coder
- post "/summary", to: "candidate#update_summary", as: :post_summary
- get "/summary", to: "candidate#summary", as: :summary
+ 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 "/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
- 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
+ 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#login"
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
diff --git a/test/controllers/candidate_controller_test.rb b/test/controllers/candidate_controller_test.rb
index 6be3d0d..adba814 100644
--- a/test/controllers/candidate_controller_test.rb
+++ b/test/controllers/candidate_controller_test.rb
@@ -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