rails / rails

Ruby on Rails
https://rubyonrails.org
MIT License
55.92k stars 21.64k forks source link

Broken devise testing with rails 8 lazy loading of routes #53373

Open ylecuyer opened 2 days ago

ylecuyer commented 2 days ago

Hello, I noticed that since this commit https://github.com/rails/rails/commit/cdb283566c5d5251e2f7e663e655e57e8e10abbc which enforces lazy loading of routes in the upcoming rails 8 release, devise tests are broken.

Would it be possible to have a flag to opt out of lazy loading?

Steps to reproduce

Clone https://github.com/ylecuyer/broken_rails8_devise
Run bundle install

Run tests with rails 7.2: bundle exec rspec

Run tests with rails 8: next bundle exec rspec
ylecuyer@inwin:/tmp/broken_rails8_devise$ bundle exec rspec
.

Finished in 0.02885 seconds (files took 0.57112 seconds to load)
1 example, 0 failures

ylecuyer@inwin:/tmp/broken_rails8_devise$ next bundle exec rspec
DEPRECATION WARNING: `to_time` will always preserve the full timezone rather than offset of the receiver in Rails 8.0. To opt in to the new behavior, set `config.active_support.to_time_preserves_timezone = :zone`. (called from <top (required)> at /tmp/broken_rails8_devise/config/environment.rb:5)
DEPRECATION WARNING: `to_time` will always preserve the full timezone rather than offset of the receiver in Rails 8.0. To opt in to the new behavior, set `config.active_support.to_time_preserves_timezone = :zone`. (called from <top (required)> at /tmp/broken_rails8_devise/config/environment.rb:5)
F

Failures:

  1) TestController works
     Failure/Error: sign_in user

     RuntimeError:
       Could not find a valid mapping for #<User id: 1, email: [FILTERED], created_at: "2024-10-18 22:18:00.403692000 +0000", updated_at: "2024-10-18 22:18:00.403692000 +0000">
     # ./spec/controllers/test_controller_spec.rb:6:in `block (2 levels) in <top (required)>'

Finished in 0.05526 seconds (files took 0.53186 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/controllers/test_controller_spec.rb:9 # TestController works

Expected behavior

I can opt out of route lazy loading (without having to eager load the whole app)

Actual behavior

Routes aren't loaded during test which makes devise testing fail

System configuration

Rails version: 8.0.0.beta1

Ruby version: doesn't apply

skipkayhil commented 2 days ago

cc @gmcgibbon

yahonda commented 2 days ago

It looks like duplicate with https://github.com/heartcombo/devise/issues/5705 and https://github.com/heartcombo/devise/pull/5695 should fix it.