-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix linting errors #6240
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
base: main
Are you sure you want to change the base?
Fix linting errors #6240
Conversation
cb337c8
to
998621e
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.
WOW 😲
Many great things in here, BUT "Fix linting errors" is an understatement 🤣
Most of these changes warrant a dedicated PR.
-> { includes(:credit_type) }, | ||
foreign_key: "user_id", | ||
class_name: "Spree::StoreCredit", | ||
dependent: :nullify, |
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 be totally fine for deactivated users to actually lose their store credit as well, but since store credit might be used for past payments as source we cannot do that, is that right?
@@ -26,7 +26,8 @@ class BaseController < ActionController::Base | |||
before_action :load_user | |||
before_action :authorize_for_order, if: proc { order_token.present? } | |||
before_action :authenticate_user | |||
before_action :load_user_roles | |||
# This is deprecated and will be removed in Spree 5.0 | |||
before_action :load_deprecated_user_roles |
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 is a really great change. I would like that to appear as it's own PR in the changelog, though.
attr_accessor :current_api_user | ||
|
||
before_action :load_user | ||
before_action :deprecated_load_user |
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 as well is a really great change. I would like that to appear as it's own PR in the changelog, though.
foreign_key: "user_id", | ||
class_name: "Spree::Order", | ||
inverse_of: :user, | ||
dependent: :nullify |
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 change is also very welcome, but warrants its own PR.
@@ -2,7 +2,7 @@ | |||
|
|||
module Spree | |||
class AdjustmentReason < Spree::Base | |||
has_many :adjustments, inverse_of: :adjustment_reason | |||
has_many :adjustments, inverse_of: :adjustment_reason, dependent: :restrict_with_exception |
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.
What do you think about using restrict_with_error
instead? So that we can display the error message on the record we try do delete instead of rendering a 500 in the admin. Otherwise we would need to rescue_from ActiveRecord::DeleteRestrictionError
in the backend.
belongs_to :reimbursement, inverse_of: :refunds, optional: true | ||
|
||
has_many :log_entries, as: :source | ||
has_many :log_entries, as: :source, dependent: :destroy |
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.
Not sure about this 🤔 . Actually I do not think refunds should ever be allowed to be destroyed. They are kind of legal records. I know that this just makes sure that if we delete a refund the log entry is removed as well, but I am not so sure about this as well.
core/app/models/spree/taxon.rb
Outdated
@@ -13,9 +13,6 @@ class Taxon < Spree::Base | |||
has_many :classifications, -> { order(:position) }, dependent: :delete_all, inverse_of: :taxon | |||
has_many :products, through: :classifications | |||
|
|||
has_many :promotion_rule_taxons |
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 should be a separate PR, so we can back port it.
@@ -347,6 +347,10 @@ Rails/FindEach: | |||
Exclude: | |||
- "db/migrate/**/*" | |||
|
|||
Rails/LexicallyScopedActionFilter: | |||
Exclude: | |||
- "backend/app/controllers/**/*" |
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.
Why not remove the empty useless methods instead?
@@ -15,7 +15,7 @@ def check_for_constant | |||
klass | |||
rescue NameError | |||
@shell.say "Couldn't find #{class_name}. Are you sure that this class exists within your application and is loaded?", :red | |||
exit(1) | |||
exit(1) # rubocop: disable Rails/Exit |
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.
abort
is probably a better way of exiting in a generator?
legacy_promotions/app/patches/models/solidus_legacy_promotions/spree_taxon_patch.rb
Outdated
Show resolved
Hide resolved
I looked through my notifications starting from the most recent. I was wondering where all these excellent little changes from @mamhoff came from... and now I know. |
I've opted for dependent: :destroy for records that do not need to be saved for posterity in the scenario of completed orders, and for :nullify if those records do need to be saved.
We should not delete adjustment reasons if there are adjustments created with them.
We already have a `before_save` callback that runs `inventory_units.destroy_all`. In order to save us all testing whether adding `dependent: :destroy` would be a subtle change in behavior, I just set the dependent: behavior to `false`.
I opted for `dependent: false` for addresses, because Spree::Address records are immutable and therefore one user's address might give another user's orders, which would be strange (also Spree::Address, for this reason, does not have an `orders` association). `valid_store_credit_payments` can have a dependent: :destroy just like normal payments in the line above. Orders that have reimbursement should not be able to be destroyed, because semantically that can only happen once they have shipped.
If there are payments associated with the payment method, we can't just destroy them. We could :nullify, but I prefer that an error is raised and eventually handled.
When a payment is actually deleted, we should destroy the records that belong to it as well. This is very rarely the case, payments mostly get invalidated instead.
When a permission set is destroyed, the join table entries to spree_roles should also be destroyed.
Stock locations with cartons or shipments should not be destroyed, but rather set to "inactive".
This adds dependent: x options to models related to store credits.
For join tables, dependent: :destroy is right. For orders, we restrict with an error - otherwise they orders would silently reassociate to the default store on the next save, which is probably not what stores want.
We should not delete tax rates that have adjustments. Otherwise we end up with invalid data on adjustments, or even adjustments changing their type, which would be BAD.
This cop wants us to write ``` def edit; super; end ``` This, in turn, wakes another cop "Useless method definition".
We do this all the time, and it's really time-consuming to fix. Also, no clear benefit.
This is fine.
e1dc7b6
to
52605d6
Compare
Summary
This fixes the linting errors introduced by yet another release of Rubocop.
I've chosen to actually do the
inverse_of
/dependent
dance because it does improve the software.Checklist
Check out our PR guidelines for more details.
The following are mandatory for all PRs: