progress on #27: test coverage over 96%
This commit is contained in:
parent
c7111ad7ad
commit
14bbd301ed
@ -109,10 +109,4 @@ class QuizController < ApplicationController
|
||||
saved: params.key?(:save),
|
||||
submitted: params.key?(:submit))
|
||||
end
|
||||
|
||||
def process_live_code_text
|
||||
@answer.update(answer: answer_params[:live_code_text].to_h,
|
||||
saved: params.key?(:save),
|
||||
submitted: params.key?(:submit))
|
||||
end
|
||||
end
|
||||
|
@ -37,6 +37,9 @@ class Candidate < ApplicationRecord
|
||||
"#{my_status.progress}%"
|
||||
end
|
||||
|
||||
# FIXME: This feels wrong here. Mail deliveries should be in controller.
|
||||
# Privatize in QuizController
|
||||
# also, bang methods in ruby do an action and replace, or return nil
|
||||
def complete!
|
||||
if update_attributes(completed: true)
|
||||
CandidateMailer.submitted(self).deliver_now
|
||||
|
@ -55,6 +55,14 @@ class CandidateControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to thankyou_path
|
||||
end
|
||||
|
||||
test 'should reset session' do
|
||||
setup_auth candidates(:dawn)
|
||||
get thankyou_path
|
||||
|
||||
assert :success
|
||||
assert session[:test_id].nil?
|
||||
end
|
||||
|
||||
test "should get summary if complete but not submitted" do
|
||||
setup_auth candidates(:dawn)
|
||||
|
||||
|
@ -16,13 +16,75 @@ class QuizControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to login_path
|
||||
end
|
||||
|
||||
# TODO: test models/candidate.complete! == false
|
||||
# test 'should gracefully fail on summary submit' do
|
||||
# # if the mailers fail, should go to thank you still
|
||||
# end
|
||||
|
||||
test "should redirect to saved on save" do
|
||||
setup_auth candidates(:dawn)
|
||||
qid = questions(:fed5).id
|
||||
post post_answer_path, params: { save: 'Save', answer: { question_id: qid, radio: 'an option' } }
|
||||
|
||||
assert_redirected_to saved_path
|
||||
assert session[:test_id].present?
|
||||
end
|
||||
|
||||
test "should redirect to next question on next" do
|
||||
setup_auth candidates(:roy)
|
||||
qid = questions(:fed3).id
|
||||
params = { submit: 'Next', answer: { question_id: qid, live_code: { text: 'stuff' } } }
|
||||
post post_answer_path, params: params
|
||||
|
||||
assert_redirected_to question_path
|
||||
assert session[:test_id].present?
|
||||
end
|
||||
|
||||
test "should get flash message on bad radio response" do
|
||||
setup_auth candidates(:martha)
|
||||
qid = questions(:fed1).id
|
||||
setup_auth candidates(:dawn)
|
||||
qid = questions(:fed5).id
|
||||
post post_answer_path, params: { answer: { question_id: qid, radio: nil } }
|
||||
|
||||
assert_response :success
|
||||
assert session[:test_id].present?
|
||||
assert_equal qid, flash[:error]
|
||||
end
|
||||
|
||||
test "should get flash message on bad text response" do
|
||||
setup_auth candidates(:dawn)
|
||||
qid = questions(:fed4).id
|
||||
post post_answer_path, params: { answer: { question_id: qid, text: nil } }
|
||||
|
||||
assert_response :success
|
||||
assert session[:test_id].present?
|
||||
assert_equal qid, flash[:error]
|
||||
end
|
||||
|
||||
test "should process checkbox" do
|
||||
setup_auth candidates(:dawn)
|
||||
qid = questions(:fed10).id
|
||||
post post_answer_path, params: { answer: { question_id: qid, checkbox: 'an-option' } }
|
||||
|
||||
assert_response :success
|
||||
assert session[:test_id].present?
|
||||
end
|
||||
|
||||
test 'should handle XHR update and complete progress' do
|
||||
setup_auth candidates(:peggy)
|
||||
qid = questions(:fed10).id
|
||||
post post_answer_path, xhr: true, params: { answer: { question_id: qid, checkbox: ['an-option'] } }
|
||||
|
||||
assert_response :success
|
||||
assert_match(/updated successfully/, JSON.parse(@response.body)['message'])
|
||||
assert_equal 100, JSON.parse(@response.body)['progress']
|
||||
end
|
||||
|
||||
test 'should handle XHR fail' do
|
||||
setup_auth candidates(:peggy)
|
||||
qid = questions(:fed10).id
|
||||
post post_answer_path, xhr: true, params: { answer: { question_id: qid, checkbox: nil } }
|
||||
|
||||
assert_response 400
|
||||
assert_match(/select.*answer/i, JSON.parse(@response.body).join)
|
||||
end
|
||||
end
|
||||
|
@ -11,6 +11,14 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test 'should logout and reset session' do
|
||||
setup_auth
|
||||
get recruiter_logout_path
|
||||
|
||||
assert :success
|
||||
assert session[:user].nil?
|
||||
end
|
||||
|
||||
test "should require auth or redirect" do
|
||||
get recruiter_url
|
||||
assert_redirected_to recruiter_login_path
|
||||
@ -55,8 +63,8 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "should create new candidate" do
|
||||
# recruiter = users(:recruiter)
|
||||
setup_auth
|
||||
|
||||
assert_difference("ActionMailer::Base.deliveries.size", 2) do
|
||||
assert_difference("Candidate.count") do
|
||||
post create_candidate_path, params: { candidate:
|
||||
@ -66,4 +74,17 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to recruiter_path
|
||||
assert flash[:notice]
|
||||
end
|
||||
|
||||
test "should fail creation with message" do
|
||||
setup_auth
|
||||
|
||||
assert_difference("ActionMailer::Base.deliveries.size", 0) do
|
||||
assert_difference("Candidate.count", 0) do
|
||||
post create_candidate_path, params: { candidate:
|
||||
{ name: 'new name', email: 'test@mailinatorcom', experience: '0-3', quiz_id: quizzes(:fed).id } }
|
||||
end
|
||||
end
|
||||
assert :success
|
||||
assert_match(/failed.*save/i, flash[:error])
|
||||
end
|
||||
end
|
||||
|
@ -52,4 +52,12 @@ class ReviewControllerTest < ActionDispatch::IntegrationTest
|
||||
get review_test_url(candidates(:richard).test_hash)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test 'should logout and reset session' do
|
||||
setup_auth
|
||||
get review_logout_path
|
||||
|
||||
assert :success
|
||||
assert session[:user].nil?
|
||||
end
|
||||
end
|
||||
|
17
test/services/skill_config_test.rb
Normal file
17
test/services/skill_config_test.rb
Normal file
@ -0,0 +1,17 @@
|
||||
require 'test_helper'
|
||||
|
||||
class SkillConfigTest < ActiveSupport::TestCase
|
||||
test "verify sample file exists" do
|
||||
assert File.exist? "#{Rails.root}/config/application.yml.sample"
|
||||
end
|
||||
|
||||
test "verify config file exists" do
|
||||
assert File.exist? "#{Rails.root}/config/application.yml"
|
||||
end
|
||||
|
||||
test 'config can load and return proper values' do
|
||||
skonfig = SkillConfig.new
|
||||
|
||||
assert_equal 'localhost', skonfig.mysql_host
|
||||
end
|
||||
end
|
@ -3,8 +3,9 @@ ENV['RAILS_ENV'] ||= 'test'
|
||||
# https://github.com/colszowka/simplecov
|
||||
require 'simplecov'
|
||||
SimpleCov.start 'rails' do
|
||||
add_group 'Models', ['app/models', 'app/validators']
|
||||
add_group 'Services & Workers', ['app/workers', 'app/services']
|
||||
add_group 'Models', %w(app/models app/validators)
|
||||
add_group 'Services & Workers', %w(app/workers app/services)
|
||||
add_group "Jobs", 'app/jobs'
|
||||
end
|
||||
|
||||
require File.expand_path('../../config/environment', __FILE__)
|
||||
|
Loading…
Reference in New Issue
Block a user