devise icon indicating copy to clipboard operation
devise copied to clipboard

Rails 8 test helpers do not work with fixtures and RSpec

Open Fh-Ndiritu opened this issue 4 months ago • 6 comments

I am still running into this issue even after the merge of a related fix

Environment

  1. Ruby 3.4
  2. Rails 8.0.2
  3. Devise 4.9.4

Test setup

  1. RSpec with fixtures (users.yml)
  2. devise_for :users is already set in routes
  3. 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

Fh-Ndiritu avatar Aug 25 '25 18:08 Fh-Ndiritu

It appears that a release including the commit that fixes this issue hasn’t been made yet.

willnet avatar Aug 27 '25 00:08 willnet

has the same problem

Guoxweii avatar Sep 18 '25 02:09 Guoxweii

Are you still running into this even on main?

carlosantoniodasilva avatar Oct 31 '25 14:10 carlosantoniodasilva

I solved this issue after upgrading to Rails 8.0 by setting config.eager_load = true in my config/environments/test.rb

abbonkers avatar Nov 13 '25 11:11 abbonkers

Anyone tried with Devise main? It should be fixed there, and we hope to release a new version soon-ish.

carlosantoniodasilva avatar Nov 13 '25 11:11 carlosantoniodasilva

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.

goose3228 avatar Nov 30 '25 13:11 goose3228