-
-
Notifications
You must be signed in to change notification settings - Fork 729
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
Changes from 2 commits
7d5bb4a
d95bb77
980f86c
3199118
5def2b5
0d4904d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Spree::Admin::TaxCategoriesHelper | ||
Check warning on line 1 in app/helpers/spree/admin/tax_categories_helper.rb GitHub Actions / runner / rubocop
Check warning on line 1 in app/helpers/spree/admin/tax_categories_helper.rb GitHub Actions / runner / rubocop
|
||
def tax_category_dropdown_options(require_tax_category) | ||
Check warning on line 2 in app/helpers/spree/admin/tax_categories_helper.rb GitHub Actions / runner / rubocop
|
||
{ | ||
:include_blank => Spree::Config.products_require_tax_category ? false : t(:none), | ||
Check warning on line 4 in app/helpers/spree/admin/tax_categories_helper.rb GitHub Actions / runner / rubocop
Check warning on line 4 in app/helpers/spree/admin/tax_categories_helper.rb GitHub Actions / runner / rubocop
|
||
selected: Spree::Config.products_require_tax_category ? Spree::TaxCategory.find_by(is_default: true)&.id : nil | ||
Check warning on line 5 in app/helpers/spree/admin/tax_categories_helper.rb GitHub Actions / runner / rubocop
|
||
} | ||
end | ||
end | ||
Check warning on line 8 in app/helpers/spree/admin/tax_categories_helper.rb GitHub Actions / runner / rubocop
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, tax_category_dropdown_options(Spree::Config.products_require_tax_category), {:class => "select2 fullwidth"}) | ||
= f.error_message_on :tax_category_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.
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.