-
-
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
We can now use plugins, and require only local modules.
This commit changes `validate_presence_of :x` and friends to `validate :x, presence: true`. No functional changes here.
We should not use `puts` here, but instead the configured Rails logger. A log level of `info` is appropriate for all of these instances.
Prior to this commit, we had a before action populating the `current_user_roles` instance variable, and then we used that instance variable in helpers. This refactors it into an actual helper that we can then use as we need.
In the same spirit as the previous commit, which refactored `@current_user_roles` into a helper method, we do the same for the `current_api_user`.
This is to satisfy Rubocop, but it's also just good behavior. If a user record is destroyed, we should also destroy their address book. For the default addresses, we don't add cascading deleted, because these are also present in the `has_many :user_addresses`.
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.
Variant property rules belong to the product, if the product goes, the property rules can go as well. For the master variant and the non-master variants, we specify to do nothing when deleting the product, because they will be deleted from the `variants_including_master` association.
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 was forgotten when extracting the legacy_promotions gem. Also adds a dependent: :destroy.
When deleting a taxonomy, its root taxon will delete all taxons, so the taxons association does not have to do it. The has_many has the inverse for taxon already defined, so we won't define another inverse.
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.
cb337c8
to
998621e
Compare
to be renamed later
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.
@@ -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
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. |
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: