-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes for custom user generator #2382
Fixes for custom user generator #2382
Conversation
The former usage of `Rails::Generators::Migration` forced us to write our own `next_migration_number` generator. This generator was erroneous and sometimes lead to duplicated migration versions. Using the activerecord migration generator uses its own battle proven migration number finder.
This include exists since this generator was introduced but no method is ever called on that module.
Any public method is considered a generator step. These methods are only used in other methdos or templates.
Instead of implementing our own template source path finder, we should just use the Rails' generators default way of defining the template source root path.
We used to do this before as one can see on the template that is no unused. Instead we gsub the initializer file and set the new custom user class name as the `Spree.user_class`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work, thank you!
This also fixes the duplicate migration issue reported here: AlchemyCMS/alchemy-solidus#14 (comment)
Indeed! Nice find @mamhoff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything makes sense for me, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely looks right to me, haven't ran it though 👍
While building an install generator for alchemy-solidus
I came across some quirks in the current custom user generator.
First the migration generator does not use the active record migration generator but its super class.
This made is necessary to write our own
next_migration_number
generator. This implementation had someflaws that lead to duplicated migrations problems. We now use the active record migration generator and
do not need to ship our own custom migration number generator anymore.
Also the generator used to inject the spree initializer and set the
Spree.user_class
to the generatedcustom user. Somehow this got lost. Replaced this by an gsub that ensures that the
Spree.user_class
is never set twice.
This removes an unused module (
Rails::Generators::ResourceHelpers
) that was used to deal with controller nameswhat we do not do anymore in this generator.
On the way I made some code cleanups.
Unfortunately it is not super easy to write generator specs as we do not have a dummy test app anymore.
We do not have tests for any generator actually. We should, but this is not purpose if this PR.
I hope the test suite of alchemy-solidus is proof enough
that this generator works. In its own generator we use the solidus custom user generator to setup the dummy app and test the integration
of Alchemy and Solidus. Would this generator fail, the builds of alchemy-solidus would fail.