-
-
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
Improve Taxon validations and factory #4851
Improve Taxon validations and factory #4851
Conversation
b739ef5
to
913a336
Compare
It was difficult to understand the use of the spec that was deleted in |
913a336
to
665546d
Compare
665546d
to
f4c685e
Compare
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.
Love it! I've been hit by this issue in the past, thanks for taking care of this. I left some comments but overall this is a great change I look forward to merge.
f4c685e
to
681c790
Compare
681c790
to
3379110
Compare
@RyanofWoods would love to move this forward. Can you please rebase? |
3379110
to
7887cbf
Compare
I rebased and added one new commit @kennyadsl. It fixes a mistake I made in the Taxon factory. On approval, I can squash it into the |
core/spec/lib/spree/core/testing_support/factories/taxon_factory_spec.rb
Show resolved
Hide resolved
7887cbf
to
a696f43
Compare
When creating a Taxon under a Taxonomy normally via admin it will make set the taxonomy correctly and the parent to a given specific parent or the the taxonomy root by default. This makes the factory behave in a similar way. If you want a root Taxon, you should create a Taxonomy and grab the root, as a root is automatically created upon creating a Taxonomy. Note, some reason icons were not being correctly set by the factory for nested Taxons so it had to be changed to do after creation.
Spree::Taxonomy rightfully assumes there's only one root [1]. Before, it was it easy to create another "root" taxon, which would not appear in the admin and/or the Taxonomy would return the wrong root. This is because `parent_id: nil` is the defining factor of a root. As the validation is checking uniqueness on taxonomy_id, a spec was added to ensure a Taxonomy can still have multiple Taxons (just not multiple ones with a parent_id of nil). [1] https://github.com/solidusio/solidus/blob/2b79f72aa53f5caa850c587888fff46c1c91f7b7/core/app/models/spree/taxonomy.rb#L10
This spec didn't really test the regression issue well: 1. This spec should call first_or_create! instead to trigger errors as well as test attributes; 2. The Taxon would be incorrectly created anyway as no taxonomy_id or parent_id is given; and 3. Rails should be responsible for testing this method. Implementation of spec: - spree/spree@425cea4 Original issue: - spree/spree#2703
In the next commit, a validation will be added to ensure their names are unique if they belong to the same parent. This will indirectly cause Taxonomies roots to fail if the Taxonomy name already exists. This will mean the Taxonomy will be created but not the root. To prevent creation of unuseful Taxonomy, a validation was added to prevent this at a higher level.
It doesn't make sense to Taxons with the same name under the same parent. A spec was also added to ensure Taxons with the same name can exist if they have different parents.
a696f43
to
6df4c2b
Compare
The specs on `solidus_starter_frontend` were failing due to recent improvements with taxon/taxonomy factories made in the solidus repository, specifically related to PR solidusio/solidus#4851. This commit updates the specs to be compatible with the latest changes and ensures that the test suite passes successfully.
The specs on `solidus_starter_frontend` were failing due to recent improvements with taxon/taxonomy factories made in the solidus repository, specifically related to: solidusio/solidus#4851 This commit updates the specs to be compatible with the latest changes and ensures that the test suite passes successfully.
The specs on `solidus_starter_frontend` were failing due to recent improvements with taxon/taxonomy factories made in the solidus repository, specifically related to: solidusio/solidus#4851 This commit updates the specs to be compatible with the latest changes and ensures that the test suite passes successfully.
In Solidus core we improved how taxon factories are built and we need to reflect that change in the frontend specs as well. Ref solidusio/solidus#4851
1. There's no more a frontend 2. Something changed in how images are saved and now they require access to the database, we can't use build_stubbed anymore in variant specs 3. some taxon/taxonomy validations was failing due to solidusio/solidus#4851
1. There's no more a frontend 2. Something changed in how images are saved and now they require access to the database, we can't use build_stubbed anymore in variant specs 3. some taxon/taxonomy validations was failing due to solidusio/solidus#4851
1. There's no more a frontend 2. Something changed in how images are saved and now they require access to the database, we can't use build_stubbed anymore in variant specs 3. some taxon/taxonomy validations was failing due to solidusio/solidus#4851
See solidusio/solidus#4851 We also create an unrelated taxon to make the test more reliable
See solidusio/solidus#4851 We also create an unrelated taxon to make the test more reliable [skip ci]
See solidusio/solidus#4851 We also create an unrelated taxon in the integration test to make it more reliable [skip ci]
See solidusio/solidus#4851 We also create an unrelated taxon in the integration test to make it more reliable [skip ci]
See solidusio/solidus#4851 We also create an unrelated taxon in the integration test to make it more reliable [skip ci]
See solidusio/solidus#4851 We also create an unrelated taxon in the integration test to make it more reliable [skip ci]
See solidusio/solidus#4851 We also create an unrelated taxon in the integration test to make it more reliable [skip ci]
See solidusio/solidus#4851 We also create an unrelated taxon in the integration test to make it more reliable [skip ci]
The specs on `solidus_starter_frontend` were failing due to recent improvements with taxon/taxonomy factories made in the solidus repository, specifically related to: solidusio/solidus#4851 This commit updates the specs to be compatible with the latest changes and ensures that the test suite passes successfully.
Summary
Fixes #4849
To resolve the two main issues outlined in #4849. This will help prevent stores from creating problematic Taxons when creating them manually as well as making it easier to setup Taxons correctly via its factory.
Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs:
The following are not always needed (
cross them outif they are not):- [ ] I have attached screenshots to demo visual changes.- [ ] I have opened a PR to update the guides.- [ ] I have updated the README to account for my changes.Release notes
New Taxon and Taxonomy validations
New validations were added to the
Taxon
andTaxonomy
models but are behind the new temporaryextra_taxon_validations
andextra_taxonomy_validations
preferences.Due to the upgrading process, you have the opportunity to introduce these preferences and validations at a later time after upgrading to 3.4.
Before using the new preferences via uncommenting them in
new_solidus_defaults
or loading3.4
defaults, ensure you don't have any now invalid Taxons or Taxonomies on production.You can do this by:
true
;Spree::Taxon.all.select(&:valid?)
andSpree::Taxonomy.all.select(&:valid?)
; andNotes:
Improved Taxon testing factory
parent
Taxon, the Taxonomy will be inferred from theparent
;taxonomy
, a Taxonomy and its root Taxon will be made;parent
will be inferred from the giventaxonomy
or default created Taxonomy - this means, the created Taxon will always be nested (If you want a root Taxon, create a Taxonomy and get its root);These changes help to create valid Taxons and makes setup easier.