From 7bdb86f89fdfdb6cd2056cd2cc7a0ac4ba8c959c Mon Sep 17 00:00:00 2001 From: Derek Montgomery Date: Tue, 2 Aug 2016 16:27:27 -0500 Subject: [PATCH] Submit summary --- app/controllers/candidate_controller.rb | 13 ++- app/models/candidate.rb | 11 +++ app/views/candidate/summary.html.erb | 10 +- test/controllers/candidate_controller_test.rb | 13 ++- test/fixtures/answers.yml | 92 ++++++++++++++++++- test/fixtures/candidates.yml | 10 ++ 6 files changed, 135 insertions(+), 14 deletions(-) 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 %> -
- -
+ <%= form_tag post_summary_path, class: "btn-container-right" do %> + + <% end %> <% else %>
Sorry, you must answer all questions before you can submit.
<% end %> diff --git a/test/controllers/candidate_controller_test.rb b/test/controllers/candidate_controller_test.rb index c013fab..6be3d0d 100644 --- a/test/controllers/candidate_controller_test.rb +++ b/test/controllers/candidate_controller_test.rb @@ -57,11 +57,22 @@ class CandidateControllerTest < ActionDispatch::IntegrationTest assert_equal qid, flash[:answer_error] end - test "should send mailers on submission" do + test "should NOT send mailers on submission" do setup_auth candidates(:dawn) + assert_difference("ActionMailer::Base.deliveries.size", 0) do + post post_summary_path + end + assert_redirected_to summary_path + assert_match 'must complete', flash[:error] + end + + test "should send mailers on submission" do + setup_auth candidates(:peggy) + assert_difference("ActionMailer::Base.deliveries.size", 3) do post post_summary_path end + assert_redirected_to thankyou_path end end diff --git a/test/fixtures/answers.yml b/test/fixtures/answers.yml index 7ae3270..901f60d 100644 --- a/test/fixtures/answers.yml +++ b/test/fixtures/answers.yml @@ -108,6 +108,97 @@ dawn10: created_at: <%= DateTime.now() - 38.hours - 40.minutes %> updated_at: <%= DateTime.now() - 38.hours - 20.minutes %> +peggy1: + candidate: peggy + question: fed1 + answer: option-1 + saved: 0 + submitted: true + created_at: <%= DateTime.now() - 38.hours - 50.minutes %> + updated_at: <%= DateTime.now() - 38.hours - 50.minutes %> + +peggy2: + candidate: peggy + question: fed2 + answer: ["option2", "option-4"] + saved: 0 + submitted: true + created_at: <%= DateTime.now() - 38.hours - 50.minutes %> + updated_at: <%= DateTime.now() - 38.hours - 50.minutes %> + +peggy3: + candidate: peggy + question: fed3 + answer: {html: "peggy3

I'm a little tealpot

", css: 'h1 {color: teal;}', js: ''} + saved: 0 + submitted: true + created_at: <%= DateTime.now() - 38.hours - 50.minutes %> + updated_at: <%= DateTime.now() - 38.hours - 50.minutes %> + +peggy4: + candidate: peggy + question: fed4 + answer: Vestibulum id ligula porta felis euismod semper. Sed posuere consectetur est at lobortis. + saved: 0 + submitted: true + created_at: <%= DateTime.now() - 38.hours - 50.minutes %> + updated_at: <%= DateTime.now() - 38.hours - 50.minutes %> + +peggy5: + candidate: peggy + question: fed5 + answer: "option 3" + saved: 0 + submitted: true + created_at: <%= DateTime.now() - 38.hours - 50.minutes %> + updated_at: <%= DateTime.now() - 38.hours - 50.minutes %> + +peggy6: + candidate: peggy + question: fed6 + answer: Integer posuere erat a ante venenatis dapibus posuere velit aliquet. + saved: 0 + submitted: true + created_at: <%= DateTime.now() - 38.hours - 32.minutes %> + updated_at: <%= DateTime.now() - 38.hours - 12.minutes %> + +peggy7: + candidate: peggy + question: fed7 + answer: {html: 'peggy7

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