Fixes rubocop offense inverse_of on payment model

- some clean up unused method too
This commit is contained in:
cyrillefr
2025-03-31 17:10:43 +02:00
parent b9901b91fe
commit 09a6da0c57
3 changed files with 2 additions and 19 deletions

View File

@@ -474,13 +474,12 @@ RSpecRails/InferredSpecType:
- 'spec/requests/voucher_adjustments_spec.rb'
- 'spec/routing/stripe_spec.rb'
# Offense count: 2
# Offense count: 1
# Configuration parameters: IgnoreScopes, Include.
# Include: app/models/**/*.rb
Rails/InverseOf:
Exclude:
- 'app/models/spree/order.rb'
- 'app/models/spree/payment.rb'
# Offense count: 35
# Configuration parameters: Include.

View File

@@ -22,6 +22,7 @@ module Spree
has_many :offsets, -> { where("source_type = 'Spree::Payment' AND amount < 0").completed },
class_name: "Spree::Payment", foreign_key: :source_id,
inverse_of: :source,
dependent: :restrict_with_exception
has_many :log_entries, as: :source, dependent: :destroy
@@ -115,10 +116,6 @@ module Spree
amount - offsets_total
end
def can_credit?
credit_allowed.positive?
end
def build_source
return if source_attributes.nil?
return unless payment_method&.payment_source_class

View File

@@ -607,19 +607,6 @@ RSpec.describe Spree::Payment do
end
end
context "#can_credit?" do
it "is true if credit_allowed > 0" do
payment = build_stubbed(:payment)
allow(payment).to receive(:credit_allowed) { 100 }
expect(payment.can_credit?).to be true
end
it "is false if credit_allowed is 0" do
payment = build_stubbed(:payment)
allow(payment).to receive(:credit_allowed) { 0 }
expect(payment.can_credit?).to be false
end
end
context "#save" do
context "completed payments" do
it "updates order payment total" do