Skip to content
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

Merged
merged 6 commits into from
Nov 22, 2017

Conversation

tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Nov 17, 2017

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 some
flaws 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 generated
custom 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 names
what 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.

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`.
@tvdeyen tvdeyen requested a review from mamhoff November 17, 2017 12:12
Copy link
Contributor

@mamhoff mamhoff left a 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)

@tvdeyen
Copy link
Member Author

tvdeyen commented Nov 17, 2017

This also fixes the duplicate migration issue reported here: AlchemyCMS/alchemy-solidus#14

Indeed! Nice find @mamhoff

Copy link
Member

@kennyadsl kennyadsl left a 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!

Copy link
Contributor

@cbrunsdon cbrunsdon left a 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 👍

@mamhoff mamhoff merged commit f8a2350 into solidusio:master Nov 22, 2017
@tvdeyen tvdeyen deleted the fixes-customer-user-generator branch July 10, 2021 09:26
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.

4 participants