diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 13ca462ab1..2eac524a65 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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. diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index a2330f6124..03111f42c6 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -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 diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb index 1389d62d1a..add0c3354d 100644 --- a/spec/models/spree/payment_spec.rb +++ b/spec/models/spree/payment_spec.rb @@ -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