skill-assessment-app/test/controllers/admin/quiz_controller_test.rb

70 lines
1.9 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-08-17 17:49:09 -05:00
require 'test_helper'
module Admin
class QuizControllerTest < ActionDispatch::IntegrationTest
2016-08-18 15:35:17 -05:00
def setup
post admin_auth_url, params: { auth:
{ email: 'alan.admin@mailinator.com', password: 'password' } }
end
2016-08-17 17:49:09 -05:00
test "should get index" do
get admin_quizzes_url
assert_response :success
2016-08-18 15:35:17 -05:00
assert assigns :quizzes
2016-08-17 17:49:09 -05:00
end
test "should get new" do
get admin_new_quiz_url
assert_response :success
2016-08-18 15:35:17 -05:00
assert assigns :quiz
end
test "should fail create" do
assert_difference("Quiz.count", 0) do
post admin_create_quiz_url, params: { quiz: { dept: nil } }
end
assert :success
assert_match(/failed/i, session[:flash].values.join)
2016-08-17 17:49:09 -05:00
end
test "should post create" do
2016-08-18 15:35:17 -05:00
assert_difference("Quiz.count", 1) do
2016-08-18 18:22:57 -05:00
post admin_create_quiz_url, params: { quiz:
{ name: 'PDW Mobile team screening', unit: 'PDW', dept: 'MBL' } }
2016-08-18 15:35:17 -05:00
end
assert_redirected_to admin_quizzes_url
2016-08-17 17:49:09 -05:00
end
test "should get view" do
2016-08-18 15:35:17 -05:00
quiz = quizzes :fed
get admin_quiz_url quiz.to_i
2016-08-17 17:49:09 -05:00
assert_response :success
2016-08-18 15:35:17 -05:00
assert_select 'p', quiz.dept
2016-08-17 17:49:09 -05:00
end
test "should get edit" do
2016-08-18 15:35:17 -05:00
quiz = quizzes :fed
get admin_edit_quiz_url quiz.to_i
2016-08-17 17:49:09 -05:00
assert_response :success
2016-08-18 15:35:17 -05:00
assert_select "[value=?]", quiz.dept
2016-08-17 17:49:09 -05:00
end
test "should post update quiz" do
2016-08-18 15:35:17 -05:00
quiz = quizzes(:fed)
post admin_update_quiz_url(quiz.to_i), params: { quiz: { dept: 'new', unit: 'another' } }
assert_redirected_to admin_quiz_path(quiz.to_i)
get admin_quiz_path quiz.to_i
assert_select 'p', 'another'
end
test "should fail to update quiz" do
quiz = quizzes(:fed)
post admin_update_quiz_url(quiz.to_i), params: { quiz: { dept: nil } }
assert :success
assert_match(/failed/i, session[:flash].values.join)
2016-08-17 17:49:09 -05:00
end
end
end