Update type handling in PaymentMethodsController and add tests

This commit is contained in:
Matt-Yorkley
2021-03-08 16:13:28 +00:00
parent 6d51ece69c
commit 707d089419
2 changed files with 19 additions and 2 deletions

View File

@@ -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

View File

@@ -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