Fix flaky madmin projects spec and Devise mappings on Rails 8.1#375
Merged
Conversation
The spec asserted the raw project title appears in the rendered page, but the title is HTML-escaped (e.g. an apostrophe becomes '), so it failed intermittently whenever Faker generated a company name with special characters. Compare against the HTML-escaped title instead.
Rails 8.1 loads routes lazily. Devise registers its scope mappings while the routes are drawn (devise_for), so before the routes load Devise.mappings is empty and every controller-spec sign_in raises 'Could not find a valid mapping'. Force the routes to load in a before(:suite) hook, which fixes the build-rails-next lane and is harmless on Rails 8.0.
JuanVqz
marked this pull request as ready for review
July 21, 2026 15:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation / Context
This PR fixes two independent test-suite problems that were making CI red.
1. Flaky
madmin/projectsspec (build-rails-current)spec/requests/madmin/projects_spec.rbasserted the raw project title appears in the rendered page:The title is HTML-escaped when rendered (an apostrophe becomes
', an ampersand&, etc.). The factory usesFaker::Company.name, which sometimes generates names with these characters (e.g.O'Conner, Reichel and Sanford), so the assertion failed intermittently depending on the random name. Fixed by comparing againstCGI.escapeHTML(project.title).2. Devise mappings empty on Rails 8.1 (build-rails-next)
Every controller-spec
sign_inraisedCould not find a valid mapping for #<User ...>on thebuild-rails-nextlane (Rails 8.1), causing 34 failures. Rails 8.1 loads routes lazily, and Devise registers its scope mappings while the routes are drawn (devise_for). Until the routes load,Devise.mappingsis empty, soDevise::Mapping.find_scope!iterates nothing and raises, even though the specs set@request.env["devise.mapping"].Fixed by forcing the routes to load in a
before(:suite)hook:This is harmless on Rails 8.0 (routes are already loaded there) and repopulates the mappings on Rails 8.1.
QA / Testing Instructions
bundle exec rspecon the current Gemfile: green.BUNDLE_GEMFILE=Gemfile.next bundle exec rspec: green (previously 34sign_infailures).I will abide by the code of conduct.