ahem... new worker tests.

This commit is contained in:
Mark Moser 2016-08-16 14:24:37 -05:00
parent f44b11fde8
commit a3d1363842
4 changed files with 75 additions and 0 deletions

View File

@ -40,6 +40,7 @@ group :development, :test do
gem 'pry-byebug'
gem 'pry-rails'
gem 'rubocop', '~> 0.42.0'
gem 'simplecov', require: false
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end

View File

@ -58,6 +58,7 @@ GEM
coderay (1.1.1)
concurrent-ruby (1.0.2)
debug_inspector (0.0.2)
docile (1.1.5)
domain_name (0.5.20160615)
unf (>= 0.0.5, < 1.0.0)
em-websocket (0.5.1)
@ -220,6 +221,11 @@ GEM
tilt (>= 1.1, < 3)
settingslogic (2.0.9)
shellany (0.0.1)
simplecov (0.12.0)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
spring (1.7.2)
spring-watcher-listen (2.0.0)
@ -288,6 +294,7 @@ DEPENDENCIES
rubocop (~> 0.42.0)
sass-rails (~> 5.0)
settingslogic (~> 2.0.9)
simplecov
spring
spring-watcher-listen (~> 2.0.0)
turbolinks (~> 5)

View File

@ -0,0 +1,47 @@
require 'test_helper'
class CandidateQuizQuestionTest < ActiveSupport::TestCase
def setup
@row = {
"candidate_id" => "12345",
"quiz_id" => 9876,
"question_id" => 5,
"answer_id" => 6,
"question" => 'what now?',
"input_type" => 'text',
"input_options" => %w(one two three).to_yaml,
"answer" => { test: 1, foo: 'bar', cheer: 'huzzah!' }.to_yaml
}
end
test "propper dot attributes work" do
question = CandidateQuizQuestion.new @row
assert_equal '12345', question.candidate_id
assert_equal 9876, question.quiz_id
assert_equal 5, question.question_id
assert_equal 6, question.answer_id
assert_equal 'what now?', question.question
assert_equal 'text', question.input_type
assert_kind_of Array, question.input_options
assert_kind_of Hash, question.answer
end
test "should handle string answer" do
question = CandidateQuizQuestion.new("answer" => "this is a text answer".to_yaml)
assert_kind_of String, question.answer
end
test "should handle array answer" do
question = CandidateQuizQuestion.new("answer" => %w(one two three four).to_yaml)
assert_kind_of Array, question.answer
end
test "should handle hash answer" do
question = CandidateQuizQuestion.new @row
assert_kind_of Hash, question.answer
end
end

View File

@ -0,0 +1,20 @@
require 'test_helper'
class CandidateQuizTest < ActiveSupport::TestCase
test "can get quiz question" do
fed8 = questions(:fed8)
quiz = CandidateQuiz.new candidates(:richard)
fetched = quiz.fetch_question(fed8.id)
assert_equal fed8.id, fetched.question_id
assert_equal fed8.question, fetched.question
end
test "can build full quiz" do
quiz = CandidateQuiz.new(candidates(:richard)).build_my_quiz
assert_equal questions(:fed1).question, quiz.first.question
assert_equal answers(:richard10).answer, quiz[9].answer
end
end