From 162c58ac39e20d07c515be431a909fdcd4776822 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 3 Feb 2026 15:08:31 +1100 Subject: [PATCH] Check which methods we need to delegate This implicit delegation makes it impossible to know which code is used and which code is dead. The refund method is very rarely used though. So we'll need to wait for a while. --- app/models/spree/gateway.rb | 6 +++++- spec/models/spree/gateway_spec.rb | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/spree/gateway.rb b/app/models/spree/gateway.rb index 2cbfc76a15..c480d9c251 100644 --- a/app/models/spree/gateway.rb +++ b/app/models/spree/gateway.rb @@ -5,7 +5,7 @@ module Spree acts_as_taggable include PaymentMethodDistributors - delegate :authorize, :purchase, :capture, :void, :credit, to: :provider + delegate :authorize, :purchase, :capture, :void, :credit, :refund, to: :provider validates :name, :type, presence: true @@ -35,6 +35,10 @@ module Spree end def method_missing(method, *) + message = "Deprecated delegation of Gateway##{method}" + Alert.raise(message) + raise message if Rails.env.local? + if @provider.nil? || !@provider.respond_to?(method) super else diff --git a/spec/models/spree/gateway_spec.rb b/spec/models/spree/gateway_spec.rb index 0b46238436..f6e975ba38 100644 --- a/spec/models/spree/gateway_spec.rb +++ b/spec/models/spree/gateway_spec.rb @@ -14,8 +14,14 @@ RSpec.describe Spree::Gateway do end it "passes through all arguments on a method_missing call" do + expect(Rails.env).to receive(:local?).and_return(false) gateway = test_gateway.new expect(gateway.provider).to receive(:imaginary_method).with('foo') gateway.imaginary_method('foo') end + + it "raises an error in test env" do + gateway = test_gateway.new + expect { gateway.imaginary_method('foo') }.to raise_error StandardError + end end