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

91 lines
2.7 KiB
Ruby

# frozen_string_literal: true
require 'test_helper'
module Admin
class AuthControllerTest < ActionDispatch::IntegrationTest
test "should get login" do
get admin_login_url
assert_response :success
assert_template 'admin/auth/login'
end
test "should get logout" do
post admin_auth_url, params: { auth:
{ email: 'alan.admin@mailinator.com', password: 'password' } }
get admin_logout_url
assert_redirected_to admin_login_url
assert session[:user].nil?
end
test "should auth to dashboard" do
post admin_auth_url, params: { auth:
{ email: 'alan.admin@mailinator.com', password: 'password' } }
assert_redirected_to admin_url
end
test "recruiter should not admin auth" do
post admin_auth_url, params: { auth:
{ email: 'pdr.recruiter@mailinator.com', password: 'password' } }
assert_redirected_to admin_login_url
assert_match(/incorrect.*email/, flash[:error])
end
test "reviewer should not admin auth" do
post admin_auth_url, params: { auth:
{ email: 'fed.reviewer@mailinator.com', password: 'password' } }
assert_redirected_to admin_login_url
assert_match(/incorrect.*email/, flash[:error])
end
test "should get reset_request" do
get admin_reset_request_url
assert_response :success
end
test "should process a reset request" do
user = users(:admin)
assert_difference("ActionMailer::Base.deliveries.size", 1) do
post admin_send_reset_url, params: { auth: { email: user.email } }
end
refute_equal user.reset_token, User.find(user.id).reset_token
assert_redirected_to admin_reset_request_url
assert_match(/request.*sent/i, flash[:success])
end
test "should redirect with invalid reset_token" do
get admin_reset_url('fooBarBaz')
assert_redirected_to admin_reset_request_url
end
test "should get reset form" do
user = users(:admin)
user.setup_reset
get admin_reset_url(user.reset_token)
assert :success
end
test "should post password reset" do
user = users(:admin)
user.setup_reset
post admin_reset_password_url, params: { auth:
{ reset_token: user.reset_token, password: '12345', password_confirmation: '12345' } }
assert_redirected_to admin_auth_path
assert_match(/reset.*log/i, flash[:success])
end
test "should fail to reset with mistyped password" do
user = users(:admin)
user.setup_reset
post admin_reset_password_url, params: { auth:
{ reset_token: user.reset_token, password: '12345', password_confirmation: 'abcde' } }
assert :success
assert flash[:error]
end
end
end