diff --git a/app/controllers/candidate_controller.rb b/app/controllers/candidate_controller.rb index bd99277..8b537bc 100644 --- a/app/controllers/candidate_controller.rb +++ b/app/controllers/candidate_controller.rb @@ -37,14 +37,13 @@ class CandidateController < ApplicationController redirect_to :question and return unless prep_status.current_question_id.nil? end - # TODO def update_summary - # redirect_to :summary - - # only after successful submission - CandidateMailer.submitted(current_candidate).deliver_now - RecruiterMailer.candidate_submitted(current_candidate).deliver_now - ReviewerMailer.candidate_submission(current_candidate).deliver_now + prep_status + not_completed_error = 'You must complete all questions to submit your test.' + record_error = 'There was a problem with your submission. Please try again later.' + redirect_to :summary, flash: { error: not_completed_error } and return unless @status.can_submit + redirect_to :thankyou and return if current_candidate.complete! + redirect_to :summary, flash: { error: record_error } end def validate diff --git a/app/models/candidate.rb b/app/models/candidate.rb index afae0eb..bea5dae 100644 --- a/app/models/candidate.rb +++ b/app/models/candidate.rb @@ -33,6 +33,17 @@ class Candidate < ApplicationRecord "--" end + def complete! + if update_attributes(completed: true) + CandidateMailer.submitted(self).deliver_now + RecruiterMailer.candidate_submitted(self).deliver_now + ReviewerMailer.candidate_submission(self).deliver_now + return true + end + false + end + + private def generate_test_hash diff --git a/app/views/candidate/summary.html.erb b/app/views/candidate/summary.html.erb index 4596e34..c9e4874 100644 --- a/app/views/candidate/summary.html.erb +++ b/app/views/candidate/summary.html.erb @@ -26,13 +26,13 @@ - <% end #questions loop %> - <% end #form_tag %> + <% end %> + <% end %> <% if @status.can_submit %> -
This means jQuery needs to be available in live-coder!
', css: "strong {font-size: 1.6em;}\n.green {color: green;}", js: '$("strong").addClass("green");'} + saved: 0 + submitted: true + created_at: <%= DateTime.now() - 38.hours - 34.minutes %> + updated_at: <%= DateTime.now() - 38.hours - 14.minutes %> + +peggy8: + candidate: peggy + question: fed8 + answer: option2 + saved: 0 + submitted: true + created_at: <%= DateTime.now() - 38.hours - 38.minutes %> + updated_at: <%= DateTime.now() - 38.hours - 16.minutes %> + +peggy9: + candidate: peggy + question: fed9 + answer: Grunt + saved: 0 + submitted: true + created_at: <%= DateTime.now() - 38.hours - 38.minutes %> + updated_at: <%= DateTime.now() - 38.hours - 18.minutes %> + +peggy10: + candidate: peggy + question: fed10 + answer: ["Live long and prosper", "Who you calling Scruffy?"] + saved: 1 + submitted: true + created_at: <%= DateTime.now() - 38.hours - 40.minutes %> + updated_at: <%= DateTime.now() - 38.hours - 20.minutes %> + + richard1: candidate: richard question: fed1 @@ -197,4 +288,3 @@ richard10: submitted: true created_at: <%= DateTime.now() - 36.hours - 40.minutes %> updated_at: <%= DateTime.now() - 36.hours - 20.minutes %> - diff --git a/test/fixtures/candidates.yml b/test/fixtures/candidates.yml index 7eeca9e..f845583 100644 --- a/test/fixtures/candidates.yml +++ b/test/fixtures/candidates.yml @@ -30,6 +30,16 @@ dawn: reminded: true test_hash: OvP0ZqGKwJ0 +peggy: + name: Peggy Blisters + email: peggy.blisters@mailinator.com + experience: 0-2 + recruiter: recruiter + quiz: fed + completed: false + reminded: true + test_hash: 242a9d5d085 + richard: name: Richard Burns email: richard.burns@mailinator.com