sorcery
sorcery copied to clipboard
Problem with integration tests under Rails 6
Configuration
- Sorcery Version: 0.16.4
- Ruby Version: 2.6.6
- Framework: ruby on rails v 6.0
- Platform: Ubuntu
Expected Behavior
Integration tests should work with the login method
Actual Behavior
All tests work under Rails 5.4. Under Rails 6.0 , tests that inherit from ActionController::TestCase work just fine. However, tests that inherit from ActionDispatch::IntegrationTest do not work. The result is Filter chain halted as :require_login rendered or redirected
Steps to Reproduce
- Here's a test example:
require 'test_helper'
class ImportAliyotTest < ActionDispatch::IntegrationTest
include Sorcery::TestHelpers::Rails::Integration
include Sorcery::TestHelpers::Rails::Controller
setup do
user = users(:one)
authenticate_user(user)
@current_user = user
@cutid = user.tenant.id
end
And here's the test_helper
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'capybara/rails'
class ActiveSupport::TestCase
include Sorcery::TestHelpers::Rails::Integration
include Sorcery::TestHelpers::Rails::Controller
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
Capybara.server = :puma # Until your setup is working
Capybara.default_driver = :selenium_chrome
# Add more helper methods to be used by all tests here...
def login_user(user)
# post the login and follow through
post "/sessions", params: {
email: user.email,
password: user.password
}
puts user.inspect
follow_redirect!
end
def authenticate_user(user = users(:one))
post sessions_url, params: {
email: user.email,
password: "hac56wsn"
}
assert_equal session[:user_id].to_i, user.id
end
end