Skip to content

Fix flaky madmin projects spec and Devise mappings on Rails 8.1#375

Merged
JuanVqz merged 2 commits into
mainfrom
fix/flaky-madmin-projects-spec
Jul 21, 2026
Merged

Fix flaky madmin projects spec and Devise mappings on Rails 8.1#375
JuanVqz merged 2 commits into
mainfrom
fix/flaky-madmin-projects-spec

Conversation

@JuanVqz

@JuanVqz JuanVqz commented Jul 21, 2026

Copy link
Copy Markdown
Member

Motivation / Context

This PR fixes two independent test-suite problems that were making CI red.

1. Flaky madmin/projects spec (build-rails-current)

spec/requests/madmin/projects_spec.rb asserted the raw project title appears in the rendered page:

expect(response.body).to include(project.title)

The title is HTML-escaped when rendered (an apostrophe becomes ', an ampersand &, etc.). The factory uses Faker::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 against CGI.escapeHTML(project.title).

2. Devise mappings empty on Rails 8.1 (build-rails-next)

Every controller-spec sign_in raised Could not find a valid mapping for #<User ...> on the build-rails-next lane (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.mappings is empty, so Devise::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:

Rails.application.reload_routes_unless_loaded

This is harmless on Rails 8.0 (routes are already loaded there) and repopulates the mappings on Rails 8.1.

QA / Testing Instructions

  1. bundle exec rspec on the current Gemfile: green.
  2. BUNDLE_GEMFILE=Gemfile.next bundle exec rspec: green (previously 34 sign_in failures).

I will abide by the code of conduct.

The spec asserted the raw project title appears in the rendered page, but the
title is HTML-escaped (e.g. an apostrophe becomes &#39;), so it failed
intermittently whenever Faker generated a company name with special
characters. Compare against the HTML-escaped title instead.
@JuanVqz JuanVqz self-assigned this Jul 21, 2026
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 JuanVqz changed the title Fix flaky madmin projects index spec Fix flaky madmin projects spec and Devise mappings on Rails 8.1 Jul 21, 2026
@JuanVqz
JuanVqz marked this pull request as ready for review July 21, 2026 15:44
@JuanVqz
JuanVqz merged commit 355315f into main Jul 21, 2026
2 checks passed
@JuanVqz
JuanVqz deleted the fix/flaky-madmin-projects-spec branch July 21, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant