Rails 8 test helpers do not work with fixtures and RSpec
I am still running into this issue even after the merge of a related fix
Environment
- Ruby 3.4
- Rails 8.0.2
- Devise 4.9.4
Test setup
- RSpec with fixtures (users.yml)
- devise_for :users is already set in routes
- Integration and Controller helpers are configured in rails_helper
Error on running on controller tests
RuntimeError:
Could not find a valid mapping for #<User id: ...
Solution that worked for me
Add to spec_helper
# TODO Remove when Devise fixes https://github.com/heartcombo/devise/issues/5705
config.before(:each, type: :controller) do
Rails.application.reload_routes_unless_loaded
end
end
It appears that a release including the commit that fixes this issue hasn’t been made yet.
has the same problem
Are you still running into this even on main?
I solved this issue after upgrading to Rails 8.0 by setting config.eager_load = true in my config/environments/test.rb
Anyone tried with Devise main? It should be fixed there, and we hope to release a new version soon-ish.
Anyone tried with Devise main? It should be fixed there, and we hope to release a new version soon-ish.
Main branch fixed this issue in db seed script, perhaps would work for fixtures too, thanks.