-
-
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
Fix factory loading #3907
Fix factory loading #3907
Conversation
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.
Left a preliminary question about the approach used, thanks @elia!
fbb44b0
to
db292dc
Compare
db292dc
to
640d52d
Compare
248bcd8
to
a753fa3
Compare
a753fa3
to
b10dd0f
Compare
00a7bf8
to
252c673
Compare
252c673
to
4a551bb
Compare
FYI: This change and the PR that introduced it breaks every gem/app in our eco system in a minor version that loads individual factories. We probably should revert it in 2.11 or add a fix that still supports loading individual factories and only remove it in 3.0 |
@tvdeyen thanks for the feedback, the goal of this PR is to still provide support for loading individual factories without breaking any application. Do you have any evidence that it is breaking things? I tried this PR with a couple of real stores and they just give deprecation warnings. Of course, I don't expect to have covered all possible scenarios for factory_bot configuration. |
@kennyadsl I have not tested this PR, but this CI run is from a recent Solidus v2.11 https://github.com/AlchemyCMS/alchemy-solidus/runs/1888940075?check_suite_focus=true |
@elia @kennyadsl the switch to mutate FactoryBot factory load paths to load factories breaks the current way of requiring individual factories in tests suites of gems and apps. The errors you are getting are missing factories, duplicated factories and missing sequences. I think there is no easy way of supporting both ways the same time. I agree that the FactoryBot way is better and we should not require individual factories in test suites, but this is an widely used approach and we should figure out a way to a) support both or b) revert this change in 2.11 |
For gems, I made this PR on Solidus Support that, once this is merged, "should" fix all extensions. I only tried with a couple so I'm not really sure it works for everyone. For stores, reverting breaking changes is exactly what this PR has been made for. If you can help us understand the exact problem you are facing, we'd be happy to explore it or if not solvable, I agree we should revert and add this breaking behavior in a major. |
@tvdeyen I'm taking a look at There's one big thing we didn't consider: when cherry-picking a file we are showing a deprecation message but not loading the specific dependency of that factory anymore. For example when requiring the product_factory individually, we print the deprecation message but we are not re-requiring all the factories that this file was relying on, which were:
I'll talk with @elia to see if there's a way to make it work but it's becoming uncomfortable to keep adding code again and again to fix all the possible cases, so I'd strongly consider a revert. Thanks again for pointing this out. |
05e3762
to
dbe45fe
Compare
@tvdeyen the last pushed code restores backward compatibility to require factories individually, I tested it with alchemy-solidus (checking out to a commit previous to your fix in AlchemyCMS/alchemy-solidus#72). I think that after some git commit improvements we can merge and backport this into 2.11. Projects that are requiring factories individually will keep their stores/gems working and we also print a deprecation warning since this behavior will not be supported anymore with Solidus 3.0. What do you think? |
Give them their own file in order to be consistent with the other files under testing_support/. Everything was deprecated except the constants, since deprecate_contstant wasn't working across different namespaces and it's unlikely anyone was relying on them.
Also, improves the line targeted by the factory cherry picking deprecation pointing to the first line that's not part of spree/core. Rely on the factories.rb deprecation if the require is coming from there.
dbe45fe
to
1f88781
Compare
@kennyadsl wow. Thanks. This looks promising 🙏🏻 @mamhoff and I will test this and provide feedback asap. |
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.
Looks great.
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.
Worked together with @elia here.
We tested this change on a real application, 2-3 extensions and an external gem (alchemy-solidus
) that was cherry-picking individual factories. Apparently fixed the backward-compatibility issues in all of them, printing a deprecation warning as well.
Description
The current FactoryBot support code doesn't take into account that Solidus factories need to be loaded before app-level factories, to allow modifications.
With this change using
factory_bot_rails
it will work out of the box (the initializer works with v4.8 up to v6).Nothing is done if
FactoryBot
is used directly, assuming the a more fine grained control/configuration is being used.The code will be activated only if FactoryBotRails is defined, so to avoid running it in production is enough to keep the gem in the developmen/test groups as advised by the factory_bot readme.
Ref #3906 (this issue will be fixed by a back port of this PR to v2.11).
Checklist: