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

Reimplement Spree's simple_product in OFN factory #2493

Conversation

HugsDaniel
Copy link
Contributor

@HugsDaniel HugsDaniel commented Jul 22, 2018

What? Why?

Closes #2433

As explained in the PR, Spree's product factory got rid of simple_product in favor of base_product, making all of our tests using simple_product fail.

I reimplemented the Spree<2.0 simple_product factory inside OFN spec/factories.rb, inheriting from OFN's override of Spree's base_product factory.
As before, a simple_product is an extension of a base_product with on_hand 5.

What should we test?

All tests using Spree's product_factory don't fail on simple_product.

Release notes

Spree Upgrade - Reimplementation in OFN of Spree's simple_product, inheriting from base_product, as a test helper.

Changelog Category: Changed

How is this related to the Spree upgrade?

Spree 2.0 removed simple_product in their product_factory, so it has been reimplemented in OFN factories to enable its use in test suite.

Copy link
Contributor

@sauloperez sauloperez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any failures fixed by this change?

@HugsDaniel
Copy link
Contributor Author

On 2-0-stable I have 2692 failing tests, and on 2433-change-from-simple-product-to-base-product I have 2684 failing tests.

@HugsDaniel
Copy link
Contributor Author

A lot of tests still fail because of on_hand attribute, or shipping_method which is called later in the test, etc...

@luisramos0 luisramos0 self-requested a review July 23, 2018 14:29
Copy link
Contributor

@luisramos0 luisramos0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, the simple_product was just an extension of base_product with on_hand = 5.
I am pretty sure tests will depend on that number (5) to pass. How are we planning to address that? Have you considered not changing from simple to base but instead create a new simple product that still extends base product and would address the "on_hand" thing in a spree2 friendly manner?

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this fixes some tests, it doesn't fix the underlying problem that we are relying on Spree's factories here. This change is typical shotgun surgery. The solution would be to create our own simple_product. Long term, I would like to only use our own factories. I always find it annoying to look for a factory, not finding it in our code base and then needing to search the Spree modules to find it.
https://refactoring.guru/smells/shotgun-surgery

Copy link
Contributor

@sauloperez sauloperez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @mkllnk, watching for shotgun surgery will make things more changeable in the future. And we know more upgrades will come.

@HugsDaniel
Copy link
Contributor Author

Ok so I should instead create our own product factory, is that right ?

@sauloperez
Copy link
Contributor

and call it simple_product so no tests need to be changed.

@HugsDaniel
Copy link
Contributor Author

Should I take into account https://github.com/openfoodfoundation/openfoodnetwork/pull/2417/files and keep a on_hand or total_on_hand attribute for simple_product ?

@luisramos0
Copy link
Contributor

@HugsDaniel I think you should keep what's in there. on_hand? I believe we will still have on_hand available after the upgrade. even if only an adapter.

@HugsDaniel HugsDaniel force-pushed the 2433-change-from-simple-product-to-base-product branch from 7ab57b7 to eab04e0 Compare July 24, 2018 14:28
@HugsDaniel HugsDaniel changed the title Change from simple_product to base_product in specs related to Spree's product_factory Reimplement Spree's simple_product in OFN factory Jul 25, 2018
@mkllnk
Copy link
Member

mkllnk commented Jul 26, 2018

Yes @HugsDaniel. You can assume that there will be methods called on_hand and count_on_hand. We decided to keep the old API.

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a tiny style comment below. ;-)

@@ -526,4 +530,5 @@
user.spree_roles << Spree::Role.find_or_create_by_name!('admin')
end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this slipped in accidentally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it did, sorry about that

@mkllnk mkllnk merged commit f04903b into openfoodfoundation:2-0-stable Jul 30, 2018
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