ahem... new worker tests.
This commit is contained in:
47
test/workers/candidate_quiz_question_test.rb
Normal file
47
test/workers/candidate_quiz_question_test.rb
Normal 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
|
20
test/workers/candidate_quiz_test.rb
Normal file
20
test/workers/candidate_quiz_test.rb
Normal 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
|
Reference in New Issue
Block a user