bug: resolve false positive "oops" redirect

This commit is contained in:
Mark Moser 2017-04-18 10:39:49 -05:00
parent 76e7401cec
commit 49035929fb
3 changed files with 31 additions and 0 deletions

View File

@ -45,6 +45,7 @@ class CandidateController < ApplicationController
end
def send_to_oops
redirect_to welcome_path and return if current_candidate && current_candidate.stale?
redirect_to oops_path if current_candidate
end
end

View File

@ -48,6 +48,17 @@ class Candidate < ApplicationRecord
answers.where(submitted: true)
end
def last_answered_at
return Time.current unless submitted_answers.count.positive?
submitted_answers.order(updated_at: :desc).first.updated_at
end
def stale?
return true unless answers.count.positive?
minutes_since_answered = (Time.current.minus_with_coercion(last_answered_at) / 60).round
minutes_since_answered > 45
end
def answered_questions
answers.where.not(answer: nil)
.where("answers.answer not like '%later:%'")

View File

@ -34,4 +34,23 @@ class CandidateTest < ActiveSupport::TestCase
candidate.build_reviews
assert_equal 3, candidate.votes.count
end
test 'can get last answer timestamp' do
candidate = candidates(:roy)
roy_last = answers(:roy2).updated_at
assert_equal roy_last, candidate.last_answered_at
end
test 'gillian is stale with no answers' do
candidate = candidates(:gillian)
assert candidate.stale?
end
test 'roy is stale with answers' do
candidate = candidates(:roy)
assert candidate.stale?
end
end