Upgrade madmin to v2.x#371
Conversation
There was a problem hiding this comment.
Pull request overview
Upgrades the app’s admin interface dependency (madmin) from 1.x to 2.x to restore compatibility with Ruby 3.4, and updates supporting views/assets/tests to match the newer madmin + pagy + sass-rails behavior.
Changes:
- Bump
madminto~> 2.0(and update related dependencies likepagy,sass-rails,sprocketsin the lockfile). - Update madmin view overrides to work with madmin 2.x (pagination rendering + replacing removed
npm_rails_versionhelper behavior). - Add request specs covering madmin authorization and key CRUD/navigation routes, plus a pagination regression spec; adjust production CSS compressor behavior and SCSS output for modern CSS functions.
Reviewed changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| spec/requests/madmin/authorization_spec.rb | Adds request coverage to ensure non-admins are redirected and admins can access madmin routes. |
| spec/requests/madmin/dashboard_spec.rb | Smoke test for the madmin dashboard and shared layout rendering. |
| spec/requests/madmin/estimates_spec.rb | Request coverage for estimates index/new/show/destroy in madmin. |
| spec/requests/madmin/pagination_spec.rb | Regression test for pagination rendering when results exceed one page. |
| spec/requests/madmin/projects_spec.rb | Request coverage for projects index/new/show/destroy in madmin. |
| spec/requests/madmin/stories_spec.rb | Request coverage for stories CRUD routes in madmin. |
| spec/requests/madmin/users_spec.rb | Request coverage for users index/new/show/destroy in madmin. |
| spec/requests/madmin/version_jumps_spec.rb | Request coverage for version_jumps CRUD routes in madmin. |
| Gemfile | Bumps madmin and sass-rails constraints to match the new dependency requirements. |
| Gemfile.lock | Locks updated versions for madmin 2.x and its dependency graph (notably pagy/sprockets-related changes). |
| config/environments/production.rb | Disables the Sass-based CSS compressor in production to avoid invalid calc/min evaluation errors. |
| app/views/madmin/application/index.html.erb | Reworks pagination rendering to avoid the removed madmin/pagy/_nav partial and support newer pagy APIs. |
| app/views/madmin/application/_javascript.html.erb | Restores npm_rails_version behavior locally for importmap URLs after upstream helper removal. |
| app/assets/stylesheets/stories.scss | Prevents Sass re-processing of CSS min() by emitting it as a literal string. |
| app/assets/stylesheets/project.scss | Imports shared variables to ensure $white and other variables are available under the updated Sass toolchain. |
| app/assets/stylesheets/4-molecules/_floors.scss | Prevents Sass re-processing of CSS calc() by emitting it as a literal string. |
| app/assets/stylesheets/1-utilities/_basic.scss | Prevents Sass re-processing of CSS calc() by emitting it as a literal string. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| get "/madmin/projects" | ||
|
|
||
| expect(response).to have_http_status(:ok) | ||
| expect(response.body).to include(project.title.truncate(20)) |
Production (points-production) is crashing on boot with: madmin-1.2.8/lib/madmin/resource.rb:39:in 'attribute': uninitialized constant OpenStruct (NameError) Ruby 3.4 removed ostruct from the default gems (it is now a bundled gem that must be declared in the Gemfile). madmin 1.2.8 uses OpenStruct without requiring "ostruct", so on Ruby 3.4 the constant is undefined, Puma fails to boot, and every request returns 503 (H10 App crashed). madmin's rescue in resource.rb re-raises the NameError as a misleading "couldn't find attribute 'id'" ArgumentError, which masks the real cause. Declaring gem "ostruct" makes Bundler.require load it at boot so OpenStruct is defined. Applied to Gemfile.lock and Gemfile.next.lock. This is a hotfix to restore production; the madmin 2.x upgrade (#371) is the longer-term fix and removes the incompatibility entirely.
Upgraded sass-rails from 5.0 to 6.0 (which uses sassc-rails 2.1) to support modern CSS features like rgb() syntax used in madmin 2.3.3. Updated SCSS files to properly escape calc() and min() expressions using unquote() to prevent SassC from trying to evaluate unit-mixed expressions at compile time. Added variables import to project.scss since each SCSS file is compiled independently. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
The SassC/libsass CSS compressor re-parses already-compiled CSS and evaluates arithmetic inside calc()/min() (e.g. `100vh - 160px`), raising "Incompatible units: 'px' and 'vh'" on otherwise valid CSS. This only manifests during production precompilation, since the compressor does not run in development. Setting css_compressor to nil explicitly (sprockets-rails defaults to :sass when sassc is present) skips CSS compression while keeping terser for JS. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Cover every route under /madmin with integration (request) specs: - Authorization: unauthenticated and non-admin users are redirected to the root path; admins get access across all controllers. - Dashboard: GET /madmin renders successfully (guards against layout / partial regressions like the removed npm_rails_version helper). - Each resource (projects, stories, estimates, users, version_jumps): index/new/show, plus create/update/destroy where those routes exist. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
madmin 2.x dropped the madmin/pagy/_nav partial and renders pagination via pagy's own helpers. The app's overridden index.html.erb still rendered the old partial, raising ActionView::MissingTemplate for any resource list with more than one page (pagy's default limit is 20). Replace the stale partial render with pagy's helpers, mirroring the gem's own index template (series_nav/info_tag on pagy 43+, pagy_nav/pagy_info on older versions). Add a request spec that creates 21 records to exercise the multi-page path, which the single-record index specs never hit. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The compressor re-parses compiled CSS and evaluates calc()/min() unit arithmetic (e.g. 100vh - 160px), raising "Incompatible units" on valid CSS. It was only disabled in production, but madmin request specs compile assets in the test env too. Move the setting to application.rb so all envs skip it.
0895b6b to
f166fac
Compare
The previous version branched at runtime on @pagy.respond_to?(:series_nav) to support both the pagy 43+ object helpers and the older pagy_nav/pagy_info module helpers. pagy is pinned to 43.x in both Gemfile.lock and Gemfile.next.lock, so the else branch was dead code that never executed. Call the pagy 43 object helpers directly (series_nav/info_tag), dropping the feature-detection branch.
madmin 2.x renders the full project title in the index table, not a 20-char truncation. Assert the full title instead of title.truncate(20), which produced 'Dietrich, Reichel...' and never matched the rendered 'Dietrich, Reichel and Lueilwitz'.
| @@ -1,3 +1,6 @@ | |||
| <%# madmin's npm_rails_version helper was removed in 2.x; reproduce it here. | |||
| Pins @rails/* unpkg packages to the matching Rails version (or "main" for prereleases). %> | |||
| <% npm_rails_version = Rails.version.match?(/\A\d+\.\d+\.\d+\z/) ? Rails.version : "main" %> | |||
There was a problem hiding this comment.
This app is dual-booted; should we use the NextRails.next? instead of the Rails.version.match?(/\A\d+\.\d+\.\d+\z/)
In fact, why are we adding this now, how npm_rails_version was resolved in the past if we didn't set that variable.
There was a problem hiding this comment.
@JuanVqz It seems that the new version of madmin removed that helper method.
Motivation / Context
Using madmin 1.2.8 with ruby 3.4 is raising this error:
QA / Testing Instructions
Smoke test madmin interface.
I will abide by the code of conduct.