-
-
Notifications
You must be signed in to change notification settings - Fork 725
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
Added the :selected option with the default tax category #12989 #13009
base: master
Are you sure you want to change the base?
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.
Thank you so much for working on this. I was wondering if we could handle the use case shared below.
@@ -1,5 +1,5 @@ | |||
= f.field_container :tax_category_id do | |||
= f.label :tax_category_id, t(:tax_category) | |||
%br | |||
= f.collection_select(:tax_category_id, Spree::TaxCategory.all, :id, :name, {:include_blank => Spree::Config.products_require_tax_category ? false : t(:none)}, {:class => "select2 fullwidth"}) | |||
= f.collection_select(:tax_category_id, Spree::TaxCategory.all, :id, :name, {:include_blank => Spree::Config.products_require_tax_category ? false : t(:none), selected: Spree::TaxCategory.find_by(is_default: true)&.id}, {:class => "select2 fullwidth"}) |
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.
This looks right, however, I was wondering if this way users might end up unintentionally selecting the tax category when it's not required. To prevent this, I think nothing should be selected if the products don't require a tax category (Spree::Config.products_require_tax_category = false
). Otherwise, the default category should be selected.
Given that we are incorporating the above logic, is it possible we could move this logic to the view helper to clean up the logic from the view? Thanks.
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.
I have the logic requested above (in case Spree::Config.products_require_tax_category = false it shows nothing, otherwise it selects the default category). Don't know where to put the code in the helper tho. Can i put it in tax_helper.rb file in the helpers folder?
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.
Moved to a new file (app/helpers/spree/admin/tax_categories_helper.rb) the new logic requested, hope it's within the structure of the project.
P.S. I think some specs are failing due to this change, can you please look into those as well? Thanks. |
I think the failing spec might be related to the tax category existence so maybe the updated logic might solve it, need to check this idea. |
I think the failing spec might be related to a new :selected attribute added to the view (selected: Spree::TaxCategory.find_by(is_default: true)&.id) |
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.
We are getting there :)
Apparently, we have lint issues with the newly added helper, are you happy to look into these? Thanks.
Yes, however, we need to validate the specs whether the code is breaking some usecase in the specs or the specs need to be updated accordingly :) |
Let me check these lint issues. |
Was able to resolve the lint issues in the code. |
… (like original version)
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 for working through this. 👍🏻
Now we will wait for the 2nd review. 🙂
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.
It's a good practise to add unit test for your code, even if the logic seems trivial. Could you add some test for the new helper ? Have a look here for some inspiration https://github.com/openfoodfoundation/openfoodnetwork/blob/master/spec/helpers/admin/products_helper_spec.rb
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.
I can add some tests, sorry if i did not start with a test, i am still learning Rails.
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.
I would like to ask if you guys know any good resource for rspec in rails? i will search for it as well, thanks in advance
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.
No worries 🙂
I find this playlist helpful, maybe it would help:
https://www.youtube.com/watch?v=2jX-FLcznDE&list=PLS6F722u-R6Ik3fbeLXbSclWkT6Qsp9ng
Please let us know you face any issues, no worries ⭐
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.
Hello, thank you. I will check it out.
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 for adding the spec ! Just one last change and we should be good to go.
context 'when products do not require a tax category' do | ||
it 'returns include_blank as the translated "none" string' do | ||
options = helper.tax_category_dropdown_options(false) | ||
expect(options[:include_blank]).to eq(I18n.t(:none)) |
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.
It's better to actually check the translation is working,ie:
expect(options[:include_blank]).to eq(I18n.t(:none)) | |
expect(options[:include_blank]).to eq("None") |
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 for your hardwork, @MrBowmanXD. Looks good to me. 👍
Now we will have a round of manual testing by our testing team before the merge. Thanks.
This pull request solves the default tax category not showing problem when you create a new product in the admin panel
Added the following code:
selected: Spree::TaxCategory.find_by(is_default: true)&.id
in the _tax_category_form.html.haml file.
What should we test?
Release notes
Changelog Category (reviewers may add a label for the release notes):
The title of the pull request will be included in the release notes.
Dependencies
Documentation updates