live coder seeding - completes #16
This commit is contained in:
2
test/fixtures/questions.yml
vendored
2
test/fixtures/questions.yml
vendored
@ -68,6 +68,8 @@ fed7:
|
||||
category: Javascript
|
||||
input_type: live_code
|
||||
input_options:
|
||||
:html: "<p>sample seed html</p>"
|
||||
:css: "body { color: #644; }"
|
||||
sort: 6
|
||||
active: true
|
||||
|
||||
|
@ -15,4 +15,13 @@ class QuestionLiveCoderTest < ActionDispatch::IntegrationTest
|
||||
# TODO: add in capybara and test form post
|
||||
# assert_redirected summary_path
|
||||
end
|
||||
|
||||
test "should load seed data into live coder" do
|
||||
setup_auth candidates(:juan)
|
||||
question = questions(:fed7)
|
||||
|
||||
get question_path(question.id)
|
||||
assert_response :success
|
||||
assert_select '#answer_live_code_html', question.input_options['html']
|
||||
end
|
||||
end
|
||||
|
@ -11,4 +11,11 @@ class QuestionTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal 2, question.input_options.count
|
||||
end
|
||||
|
||||
test 'should have seed input for live_coder' do
|
||||
question = Question.find questions(:fed7).to_i
|
||||
|
||||
assert_kind_of Hash, question.input_options
|
||||
assert question.input_options.keys.include? :html
|
||||
end
|
||||
end
|
||||
|
@ -3,13 +3,15 @@ class AnswerValidatable
|
||||
|
||||
attr_accessor :answer
|
||||
attr_accessor :question
|
||||
attr_accessor :question_id
|
||||
|
||||
validates :answer, answer_format: true
|
||||
|
||||
MockQuestion = Struct.new(:input_type)
|
||||
|
||||
def initialize input_type
|
||||
def initialize input_type, qid = nil
|
||||
@input_type = input_type
|
||||
@question_id = qid
|
||||
end
|
||||
|
||||
def question
|
||||
|
@ -48,4 +48,20 @@ class AnswerFormatValidatorTest < ActiveSupport::TestCase
|
||||
assert obj.valid?
|
||||
assert obj.errors.messages.empty?
|
||||
end
|
||||
|
||||
test "live_code should PASS using seed data" do
|
||||
obj = AnswerValidatable.new('live_code', questions(:fed7).id)
|
||||
obj.answer = { text: "no thanks", html: "<p>sample seed html</p>", css: "body { color: #644; }", js: "" }
|
||||
|
||||
assert obj.valid?
|
||||
assert obj.errors.messages.empty?
|
||||
end
|
||||
|
||||
test "live_code should FAIL with seed data only" do
|
||||
obj = AnswerValidatable.new('live_code', questions(:fed7).id)
|
||||
obj.answer = { text: "", html: "<p>sample seed html</p>", css: "body { color: #644; }", js: "" }
|
||||
|
||||
refute obj.valid?
|
||||
assert_match(/write.*code/, obj.errors.messages[:answer][0])
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user