skill-assessment-app/test/controllers/admin/question_controller_test.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

93 lines
2.8 KiB
Ruby

# frozen_string_literal: true
require 'test_helper'
module Admin
class QuestionControllerTest < ActionDispatch::IntegrationTest
def setup
post admin_auth_url, params: { auth:
{ email: 'alan.admin@mailinator.com', password: 'password' } }
end
test "should get index" do
get admin_questions_url
assert_response :success
assert assigns :questions
end
test "should get new" do
get admin_new_question_url
assert_response :success
assert assigns :question
end
test "should fail create" do
assert_difference("Question.count", 0) do
post admin_create_question_url, params: { question: { question: 'foo bar baz' } }
end
assert :success
assert_match(/failed/i, session[:flash].values.join)
end
test "should fail to create without quiz id" do
assert_difference("Question.count", 0) do
post admin_create_question_url, params: { question:
{ question: 'foo bar baz', category: 'ops', input_type: 'text' } }
end
assert :success
assert_match(/failed/i, session[:flash].values.join)
end
test "should post create" do
assert_difference("Question.count", 1) do
post admin_create_question_url, params: { question:
{ quiz_id: quizzes(:fed).to_i, question: 'foo bar baz', category: 'ops', input_type: 'text' } }
end
assert_redirected_to admin_questions_url
end
test "should get view" do
get admin_question_url questions(:fed5).to_i
assert_response :success
assert assigns :question
end
test "should get edit" do
get admin_edit_question_url questions(:fed5).to_i
assert_response :success
assert assigns :question
end
test "should post update quiz" do
question = questions(:fed9)
post admin_update_question_url(question.to_i), params: { question:
{ quiz_id: quizzes(:fed).to_i, question: 'foo bar baz', category: 'ops', input_type: 'text' } }
assert_redirected_to admin_question_path(question.to_i)
get admin_question_path question.to_i
assert_select 'p', 'foo bar baz'
end
test "should fail to update question" do
question = questions(:fed9)
post admin_update_question_url(question.to_i), params: { question: { question: nil } }
assert :success
assert_match(/failed/i, session[:flash].values.join)
end
test "should gracefully fail input_type" do
get admin_question_option_form_url(input_type: 'fooBarBaz')
assert :success
assigns :locals
end
test "should return partial for new radio" do
get admin_question_option_form_url(input_type: 'radio')
assert :success
assigns :locals
assert_select "input[id^=question_multi_choice_]"
end
end
end