heartcombo / devise

Flexible authentication solution for Rails with Warden.
http://blog.plataformatec.com.br/tag/devise/
MIT License
24k stars 5.55k forks source link

Going about asserting if user is signed in with Minitest; ActionDispatch::IntegrationTest/Warden issue #5543

Closed dvodvo closed 1 year ago

dvodvo commented 1 year ago

Current behavior

a test aims to determine if a user is logged in, where users(:one) fixture has email defined, but not an encrypted password stated.

require "test_helper"

class ThisKlassControllerTest < ActionDispatch::IntegrationTest
  include Devise::Test::IntegrationHelpers
  test "should login " do
    sign_in(users(:one))
    is_logged_in?
  end

via a test_helper method

class ActiveSupport::TestCase
  fixtures :all
  parallelize(workers: :number_of_processors)

  def is_logged_in?
puts (session['warden.user.user.key'][0]).present?
    (session['warden.user.user.key'][0]).present?
  end

Returns

NoMethodError: undefined method `session' for nil:NilClass

      @request.session
              ^^^^^^^^
    test/test_helper.rb:38:in `is_logged_in?'

The application runs authentication as expected and will display warden.user.user.key

Thus, there may be an issue with the inclusion of Devise::Test::IntegrationHelpers - or something else is missing/wrong in the above approach.

dvodvo commented 1 year ago

A second test, using the synax from the repository 's tests

require "test_helper"

class ThisKlassControllerTest < ActionDispatch::IntegrationTest
  include Warden::Test::Helpers
  include Devise::Test::IntegrationHelpers

  test "should login " do
    sign_in(users(:one))
    assert warden.authenticated?(:user)
  end

returns NameError: undefined local variable or methodwarden' for [...]ControllerTest[...] Did you mean? warn`

seem to indicate a problem with warden of its inclusion.

dvodvo commented 1 year ago

Having created a second application with the same methods and routes, it is determined the issue lies not with devise, but in the testing environment being somehow corrupted.