Fix route namespace singularization for plural module names #313
+1
−1
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.
While trying to integrate
madmininto my project which also uses the pricing_plans and usage_credits gems, I started getting errors like these on anymadminpage, none was loading:I came across all these errors just by following the README instructions, so I thought it could be a bug, which I think it is. Fortunately, it seems like it's just a single line.
The problem was the
.singularizecall in here:madmin/lib/madmin/resource.rb
Line 87 in 5b481d6
Which incorrectly transforms plural namespace module names. Both pricing_plans and usage_credits have multiple namespaced models, which get incorrectly converted by
madmin:This caused undefined method errors like:
undefined method 'madmin_pricing_plan_assignments_path'(expected:'madmin_pricing_plans_assignments_path')The bug probably went undetected because Rails' built-in engines work because they're singular:
ActionText,ActiveStorage,ActionMailboxdon't change when singularized. Also the test suite only testsActionText::RichTextResource, which doesn't expose the bug.This affects all four path methods (index, new, show, edit) for any namespaced model with a plural namespace name.
After the fix all tests pass, and I also tested it manually in my app while using my other gems and now everything works fine!