-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changes from all commits
1cb3c8d
7a7bcc2
c1af035
853af00
6c3325d
568b2ce
45145af
8d188fa
8e71e40
5d8a9c3
12472e5
934f33b
2dfd7cf
2cc0638
3cc7865
e150f91
f5b5c75
31b2a03
a51cb30
18f1f85
75e8cad
369b2a5
0104561
ea1dee3
52605d6
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 |
|---|---|---|
|
|
@@ -11,20 +11,58 @@ module UserMethods | |
| included do | ||
| extend Spree::DisplayMoney | ||
|
|
||
| has_many :role_users, foreign_key: "user_id", class_name: "Spree::RoleUser", dependent: :destroy | ||
| has_many :spree_roles, through: :role_users, source: :role, class_name: "Spree::Role" | ||
|
|
||
| has_many :user_stock_locations, foreign_key: "user_id", class_name: "Spree::UserStockLocation" | ||
| has_many :stock_locations, through: :user_stock_locations | ||
|
|
||
| has_many :spree_orders, foreign_key: "user_id", class_name: "Spree::Order" | ||
| has_many :orders, foreign_key: "user_id", class_name: "Spree::Order" | ||
|
|
||
| has_many :store_credits, -> { includes(:credit_type) }, foreign_key: "user_id", class_name: "Spree::StoreCredit" | ||
| has_many :store_credit_events, through: :store_credits | ||
|
|
||
| has_many :credit_cards, class_name: "Spree::CreditCard", foreign_key: :user_id | ||
| has_many :wallet_payment_sources, foreign_key: 'user_id', class_name: 'Spree::WalletPaymentSource', inverse_of: :user | ||
| has_many :role_users, | ||
| foreign_key: "user_id", | ||
| class_name: "Spree::RoleUser", | ||
| dependent: :destroy, | ||
| inverse_of: :user | ||
| has_many :spree_roles, | ||
| through: :role_users, | ||
| source: :role, | ||
| class_name: "Spree::Role", | ||
| inverse_of: :users | ||
|
|
||
| has_many :user_stock_locations, | ||
| foreign_key: "user_id", | ||
| class_name: "Spree::UserStockLocation", | ||
| inverse_of: :user, | ||
| dependent: :destroy | ||
| has_many :stock_locations, | ||
| through: :user_stock_locations, | ||
| inverse_of: :users | ||
|
|
||
| has_many :spree_orders, | ||
| foreign_key: "user_id", | ||
| class_name: "Spree::Order", | ||
| inverse_of: :user, | ||
| dependent: :nullify | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is also very welcome, but warrants its own PR. |
||
| has_many :orders, | ||
| foreign_key: "user_id", | ||
| class_name: "Spree::Order", | ||
| inverse_of: :user, | ||
| dependent: :nullify | ||
|
|
||
| has_many :store_credits, | ||
| -> { includes(:credit_type) }, | ||
| foreign_key: "user_id", | ||
| class_name: "Spree::StoreCredit", | ||
| dependent: :nullify, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
| inverse_of: :user | ||
| has_many :store_credit_events, | ||
| through: :store_credits, | ||
| inverse_of: false | ||
|
|
||
| has_many :credit_cards, | ||
| class_name: "Spree::CreditCard", | ||
| foreign_key: :user_id, | ||
| dependent: :nullify, | ||
| inverse_of: :user | ||
|
|
||
| has_many :wallet_payment_sources, | ||
| foreign_key: 'user_id', | ||
| class_name: 'Spree::WalletPaymentSource', | ||
| inverse_of: :user, | ||
| dependent: :destroy | ||
|
|
||
| after_create :auto_generate_spree_api_key | ||
| before_destroy :check_for_deletion | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about using |
||
|
|
||
| validates :name, presence: true, uniqueness: { case_sensitive: false, allow_blank: true } | ||
| validates :code, presence: true, uniqueness: { case_sensitive: false, allow_blank: true } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,11 @@ module Spree | |
| # The default `source` of a `Spree::Payment`. | ||
| # | ||
| class CreditCard < Spree::PaymentSource | ||
| belongs_to :user, class_name: Spree::UserClassHandle.new, foreign_key: 'user_id', optional: true | ||
| belongs_to :user, | ||
| class_name: Spree::UserClassHandle.new, | ||
| foreign_key: 'user_id', | ||
| optional: true, | ||
| inverse_of: :credit_cards | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this for historical reasons? Credit cards should never be associated directly to a user, but through their wallet payment source, right? Should we deprecate this association? cc @solidusio/core-team |
||
| belongs_to :address, optional: true | ||
|
|
||
| before_save :set_last_digits | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ class LineItem < Spree::Base | |
| has_one :product, through: :variant | ||
|
|
||
| has_many :adjustments, as: :adjustable, inverse_of: :adjustable, dependent: :destroy | ||
| has_many :inventory_units, inverse_of: :line_item | ||
| has_many :inventory_units, inverse_of: :line_item, dependent: false | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Maybe worth adding a comment here and point to the |
||
|
|
||
| before_validation :normalize_quantity | ||
| before_validation :set_required_attributes | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,11 +75,19 @@ class CannotRebuildShipments < StandardError; end | |
| # Customer info | ||
| belongs_to :user, class_name: Spree::UserClassHandle.new, optional: true | ||
|
|
||
| belongs_to :bill_address, foreign_key: :bill_address_id, class_name: 'Spree::Address', optional: true | ||
| belongs_to :bill_address, | ||
| foreign_key: :bill_address_id, | ||
| class_name: 'Spree::Address', | ||
| optional: true, | ||
| inverse_of: false | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You did not added a |
||
| alias_method :billing_address, :bill_address | ||
| alias_method :billing_address=, :bill_address= | ||
|
|
||
| belongs_to :ship_address, foreign_key: :ship_address_id, class_name: 'Spree::Address', optional: true | ||
| belongs_to :ship_address, | ||
| foreign_key: :ship_address_id, | ||
| class_name: 'Spree::Address', | ||
| optional: true, | ||
| inverse_of: false | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. You did not added a |
||
| alias_method :shipping_address, :ship_address | ||
| alias_method :shipping_address=, :ship_address= | ||
|
|
||
|
|
@@ -113,17 +121,22 @@ def states | |
|
|
||
| # Payments | ||
| has_many :payments, dependent: :destroy, inverse_of: :order | ||
| has_many :valid_store_credit_payments, -> { store_credits.valid }, inverse_of: :order, class_name: 'Spree::Payment', foreign_key: :order_id | ||
| has_many :valid_store_credit_payments, | ||
| -> { store_credits.valid }, | ||
| inverse_of: :order, | ||
| class_name: 'Spree::Payment', | ||
| foreign_key: :order_id, | ||
| dependent: :destroy | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do that, can we then also remove all store credit records when we delete a user (see previous comment on |
||
|
|
||
| # Returns | ||
| has_many :return_authorizations, dependent: :destroy, inverse_of: :order | ||
| has_many :return_items, through: :inventory_units | ||
| has_many :customer_returns, -> { distinct }, through: :return_items | ||
| has_many :reimbursements, inverse_of: :order | ||
| has_many :reimbursements, inverse_of: :order, dependent: :restrict_with_exception | ||
| has_many :refunds, through: :payments | ||
|
|
||
| # Logging | ||
| has_many :state_changes, as: :stateful | ||
| has_many :state_changes, as: :stateful, dependent: :destroy | ||
| belongs_to :created_by, class_name: Spree::UserClassHandle.new, optional: true | ||
| belongs_to :approver, class_name: Spree::UserClassHandle.new, optional: true | ||
| belongs_to :canceler, class_name: Spree::UserClassHandle.new, optional: true | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,10 @@ class Payment < Spree::Base | |
| belongs_to :source, polymorphic: true, optional: true | ||
| belongs_to :payment_method, -> { with_discarded }, class_name: 'Spree::PaymentMethod', inverse_of: :payments, optional: true | ||
|
|
||
| has_many :log_entries, as: :source | ||
| has_many :state_changes, as: :stateful | ||
| has_many :capture_events, class_name: 'Spree::PaymentCaptureEvent' | ||
| has_many :refunds, inverse_of: :payment | ||
| has_many :log_entries, as: :source, dependent: :destroy | ||
| has_many :state_changes, as: :stateful, dependent: :destroy | ||
| has_many :capture_events, class_name: 'Spree::PaymentCaptureEvent', dependent: :destroy | ||
| has_many :refunds, inverse_of: :payment, dependent: :destroy | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not so sure about this one. Refunds are associated with reimbursements and we won't delete those, right? |
||
|
|
||
| before_validation :validate_source, unless: :invalid? | ||
| before_create :set_unique_identifier | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,9 +23,9 @@ class UnsupportedPaymentMethod < StandardError; end | |
|
|
||
| validates :name, :type, presence: true | ||
|
|
||
| has_many :payments, class_name: "Spree::Payment", inverse_of: :payment_method | ||
| has_many :credit_cards, class_name: "Spree::CreditCard" | ||
| has_many :store_payment_methods, inverse_of: :payment_method | ||
| has_many :payments, class_name: "Spree::Payment", inverse_of: :payment_method, dependent: :restrict_with_exception | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we could also use |
||
| has_many :credit_cards, class_name: "Spree::CreditCard", dependent: :restrict_with_exception | ||
| has_many :store_payment_methods, inverse_of: :payment_method, dependent: :destroy | ||
| has_many :stores, through: :store_payment_methods | ||
|
|
||
| scope :ordered_by_position, -> { order(:position) } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ class PaymentSource < Spree::Base | |
|
|
||
| belongs_to :payment_method, optional: true | ||
|
|
||
| has_many :payments, as: :source | ||
| has_many :payments, as: :source, dependent: :restrict_with_error | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is interesting. Why you opted for |
||
| has_many :wallet_payment_sources, | ||
| class_name: 'Spree::WalletPaymentSource', | ||
| as: :payment_source, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,14 @@ class Refund < Spree::Base | |
| include Metadata | ||
|
|
||
| belongs_to :payment, inverse_of: :refunds, optional: true | ||
| belongs_to :reason, class_name: 'Spree::RefundReason', foreign_key: :refund_reason_id, optional: true | ||
| belongs_to :reason, | ||
| class_name: 'Spree::RefundReason', | ||
| foreign_key: :refund_reason_id, | ||
| optional: true, | ||
| inverse_of: :refunds | ||
| belongs_to :reimbursement, inverse_of: :refunds, optional: true | ||
|
|
||
| has_many :log_entries, as: :source | ||
| has_many :log_entries, as: :source, dependent: :destroy | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| validates :payment, presence: true | ||
| validates :reason, presence: true | ||
|
|
||
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?