-
-
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 Country factory states_required attribute #4272
Fix Country factory states_required attribute #4272
Conversation
This change has potential to break codebase's tests if they have not modified the 'country' factory 'states_required' attribute to be the intended behaviour, because the attribute can be |
Thanks, @RyanofWoods! What about a warning in the address factory? Something like: after(:build) do |address, evaluator|
carmen_country = Carmen::Country.code(adress.country.iso)
Spree::Deprecation.warn <<~MSG if address.state.nil? && Spree::Config.address_require_state && carmen_country.subregions? && address.country.states_required == false
You built an inconsistent country......
whether use a country that doesn't require subregions (e.g. ?) or add a state to the address
MSG
end |
@waiting-for-dev I am not really sure there is something we can do, other than perhaps realise it on a minor release and make a note of it in the changelog 🤔 (I think this warning could be annoying if the have custom logic where some countries's |
Hey @RyanofWoods!
I'm not familiar with this part of the codebase, but I tried to dig a bit, and it seemed to be that the only place where that could happen is on the address model because of a custom validator.
AFAIK,
It seemed that there's no frontend for WDYT? Let's also wait for the opinion of others. |
We can we wait for further opinions @waiting-for-dev 🙂 |
I'd explore if you are making the right assumption in the first place: are we sure that just having subregions is enough to determine if states are required to make an address valid in a given country? That information doesn't seem to live in Carmen (for a good reason, it's just a repository of geographies, doesn't include addresses concerns), but I guess there are places where we have subregions and they are not mandatory for address validity. |
That's a good point @kennyadsl 🙂 I don't think it is for the reasons you mentioned. The following issue touches upon this: I can look into this more 👍 |
@kennyadsl, it seems that's the condition we're checking on our seeds:
|
Hey @RyanofWoods, after talking with the core team, @spaghetticode came up with an idea that we think could solve the concern about breaking tests. What about modifying the address factory so that:
WDYT? |
Hey, @RyanofWoods! 👋 Did you find the time to think about the proposed solution? Do you think it's something that makes sense? |
Resolves issue: solidusio#4270 Some tests were modified to give a state with the address parameters as they used a country which will now get the states_required attribute of true, meaning a state must be present on the address.
Improves the readability of the next commit.
0efc121
to
02e6c5c
Compare
For some countries such as Italy, its states are nested within regions, and not at the first level of subregions like 'US'. `country > region > states` `Carmen::Country.coded('IT').subregions.first.type` Now nested subregions exist, it will use this instead. This will be useful for when using the state factory, but also necessary for the upcoming commit, where if a state is not given, but a country is, for the address factory, it can automatically use/create the first state of that country.
60af8a8
to
1906f9c
Compare
Two rationales for this change: 1. Now that the states_required attribute is now functioning in the country factory, some specs for codebases might start breaking, due to them using an address factory, not giving a state, but using a country that requires a state. This should prevent many breaking tests * 2. Less setup is now needed for specs. Only a state or country is needed for a valid non-US (default) address * But not all, for example address API endpoint specs might break, which happened for Solidus: cf84832
1906f9c
to
bd8ad62
Compare
Hi @waiting-for-dev 👋 I added some commits implementing the suggested solution. So it was possible, but the |
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.
Thanks, @RyanofWoods. I think now the logic is better covered. However, I'd like another review by someone with more experience than me dealing with this part of Solidus. cc @solidusio/core-team
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.
👍 Thanks Ryan, this is a nice improvement!
Due to the following PR, the Country factory no longer always returns true for `states_required`. It can be true for the appropriate countries that require a state in shipping addresses. Because of this, addresses using a country where `states_required` is true, such as the US, need a state in the Spree::Address record to be valid. solidusio/solidus#4272
Due to the following PR, the Country factory no longer always returns true for `states_required`. It can be true for the appropriate countries that require a state in shipping addresses. Because of this, addresses using a country where `states_required` is true, such as the US, need a state in the Spree::Address record to be valid. solidusio/solidus#4272
Due to the following PR, the Country factory no longer always returns true for `states_required`. It can be true for the appropriate countries that require a state in shipping addresses. Because of this, addresses using a country where `states_required` is true, such as the US, need a state in the Spree::Address record to be valid. solidusio/solidus#4272
Due to the following PR, the Country factory no longer always returns true for `states_required`. It can be true for the appropriate countries that require a state in shipping addresses. Because of this, addresses using a country where `states_required` is true, such as the US, need a state in the Spree::Address record to be valid. solidusio/solidus#4272
In a recent change to core, an `after(:build)` hook was added to set the state on the address record for countries which require states. This interferes with the spec setup by ignoring the state attribute we were setting to `nil`. Instead we have moved that to a `before` block so that we can correctly setup the test address to not have a state. Relevant change upstream - solidusio/solidus#4272 Co-authored-by: Andrew Stewart <[email protected]>
In a recent change to core, an `after(:build)` hook was added to set the state on the address record for countries which require states. This interferes with the spec setup by ignoring the state attribute we were setting to `nil`. Instead we have moved that to a `before` block so that we can correctly setup the test address to not have a state. Relevant change upstream - solidusio/solidus#4272 Co-authored-by: Andrew Stewart <[email protected]>
Country factory was changed to assign a realistic states_required field. We update our test suite to account for this change. See solidusio/solidus#4272 [skip ci]
Country factory was changed to assign a realistic states_required field. We update our test suite to account for this change. See solidusio/solidus#4272 [skip ci]
Country factory was changed to assign a realistic states_required field. We update our test suite to account for this change. See solidusio/solidus#4272 [skip ci]
Country factory was changed to assign a realistic states_required field. We update our test suite to account for this change. See solidusio/solidus#4272 [skip ci]
Country factory was changed to assign a realistic states_required field. We update our test suite to account for this change. See solidusio/solidus#4272 [skip ci]
Country factory was changed to assign a realistic states_required field. We update our test suite to account for this change. See solidusio/solidus#4272 [skip ci]
Description
Resolves issue: #4270
Some tests were modified to give a state with the address parameters
as they used a country which will now get the states_required attribute
of true, meaning a state must be present on the address.
Checklist: