diff --git a/app/controllers/spree/admin/payment_methods_controller.rb b/app/controllers/spree/admin/payment_methods_controller.rb index aaee7fb306..9cfd7c2492 100644 --- a/app/controllers/spree/admin/payment_methods_controller.rb +++ b/app/controllers/spree/admin/payment_methods_controller.rb @@ -33,7 +33,7 @@ module Spree invoke_callbacks(:update, :before) - if @payment_method['type'].to_s != payment_method_class + if @payment_method.type.to_s != payment_method_class @payment_method.update_columns( type: payment_method_class, updated_at: Time.zone.now @@ -97,7 +97,7 @@ module Spree private def payment_method_class - base_params.delete(:type) + @payment_method_class ||= base_params.delete(:type) end def force_environment diff --git a/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/spec/controllers/spree/admin/payment_methods_controller_spec.rb index 1ed6f5de1a..497d430de6 100644 --- a/spec/controllers/spree/admin/payment_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/payment_methods_controller_spec.rb @@ -81,6 +81,23 @@ module Spree expect(payment_method.calculator.preferred_amount).to eq 456 expect(payment_method.calculator.preferred_currency).to eq "GBP" end + + context "when the given payment method type does not match" do + let(:params) { + { + id: payment_method.id, + payment_method: { + type: "Spree::Gateway::Bogus" + } + } + } + + it "updates the payment method type" do + spree_post :update, params + + expect(PaymentMethod.find(payment_method.id).type).to eq "Spree::Gateway::Bogus" + end + end end context "on a StripeConnect payment method" do