I'm trying to adapt a pre-devise unit test to make sure that an unconfirmed user is not logged in and is redirected to the sign in page with the devise.failure.unconfirmed message. I keep running into a warden error. I know that I can get rid of the error by confirming the user, but that would defeat the purpose of the test. I believe this version of devise includes the relevant warden test setup in devise's integration_helpers.rb (warden.test_mode!, etc.).
The test code generates: UncaughtThrowError: uncaught throw :warden
The equivalent actions in a localhost:3000 browser generate: 401 with a response body of devise.failure.unconfirmed which displays as expected.
users_controller_test.rb
require 'test_helper'
class UsersControllerTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
test "should redirect index when not confirmed" do
sign_in User.create!(name: 'Bob', email: 'bob@bob.com', password: 'password', password_confirmation: 'password)
get users_path
end
end
test_helper.rb
require File.expand_path('../../config/environment',__FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
fixtures :all
end
user.rb
class User < ApplicationRecord
devise :lockable, :confirmable, :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
validates :name, presence: true, length: { maximum: 50 }
...
end
versions: devise 4.4.1, rails 5.1.4, ruby 2.5.0
Aucun commentaire:
Enregistrer un commentaire