Submit summary
This commit is contained in:
parent
988f1346c1
commit
7bdb86f89f
@ -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
|
||||
|
@ -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
|
||||
|
@ -26,13 +26,13 @@
|
||||
</fieldset>
|
||||
</div>
|
||||
</article>
|
||||
<% end #questions loop %>
|
||||
<% end #form_tag %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if @status.can_submit %>
|
||||
<div class="btn-container-right">
|
||||
<input type="submit" class="submit-button" value="Submit all answers" name="submit" />
|
||||
</div>
|
||||
<%= form_tag post_summary_path, class: "btn-container-right" do %>
|
||||
<input type="submit" class="submit-button" value="Submit all answers" name="submit" />
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div class="error">Sorry, you must answer all questions before you can submit.</div>
|
||||
<% end %>
|
||||
|
@ -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
|
||||
|
92
test/fixtures/answers.yml
vendored
92
test/fixtures/answers.yml
vendored
@ -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 <h1>I'm a little tealpot</h1>", 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 <p>This means <strong>jQuery</strong> needs to be available in live-coder!</p>', 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 %>
|
||||
|
||||
|
10
test/fixtures/candidates.yml
vendored
10
test/fixtures/candidates.yml
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user