skill-assessment-app/app/controllers/candidate_controller.rb
Mark Moser 4bbd93ded1 rubocop noise: fixes FrozenStringLiteralComment
Adding the .ruby-verison file triggered previously un-run cops, specifically:

  This cop is designed to help upgrade to Ruby 3.0. It will add the
  comment `# frozen_string_literal: true` to the top of files to enable
  frozen string literals. Frozen string literals will be default in Ruby
  3.0. The comment will be added below a shebang and encoding comment. The
  frozen string literal comment is only valid in Ruby 2.3+.

More info on rubocop [Automatic-Corrections](https://github.com/bbatsov/rubocop/wiki/Automatic-Corrections)
2016-09-08 10:30:13 -05:00

51 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class CandidateController < ApplicationController
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
render :welcome_back if current_candidate.answers.count > 0
end
def saved
end
def oops
end
def thankyou
redirect_to root_path if session[:test_id].nil?
reset_session
end
def validate
candidate = Candidate.find_by(test_hash: params['test_id'])
redirect_to(root_path, flash: { error: "Sorry, incorrect test id" }) and return if candidate.nil?
session[:test_id] = candidate.test_hash
redirect_to :thankyou and return if candidate.completed?
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
end