Merge pull request #13920 from mkllnk/clean-name

Stop pre-selecting Paypal when creating a payment method
This commit is contained in:
Rachel Arnould
2026-02-19 11:38:56 +01:00
committed by GitHub
10 changed files with 30 additions and 21 deletions

View File

@@ -138,7 +138,7 @@ module Spree
providers.delete("Spree::Gateway::StripeSCA") unless show_stripe?
providers.map(&:constantize)
providers
end
# Show Stripe as an option if enabled, or if the

View File

@@ -0,0 +1,18 @@
# frozen_string_literal: true
module Spree
module Admin
module PaymentMethodsHelper
def payment_method_type_name(class_name)
scope = "spree.admin.payment_methods.providers"
key = class_name.demodulize.downcase
I18n.t(key, scope:)
end
def payment_method_type_options(providers)
providers.map { |p| [payment_method_type_name(p), p] }
end
end
end
end

View File

@@ -109,11 +109,6 @@ module Spree
distributors.include?(distributor)
end
def self.clean_name
scope = "spree.admin.payment_methods.providers"
I18n.t(name.demodulize.downcase, scope:)
end
private
def distributor_validation

View File

@@ -3,6 +3,6 @@
.alpha.four.columns
= label :payment_method, :type, t('.provider')
.omega.twelve.columns
= collection_select(:payment_method, :type, @providers, :to_s, :clean_name, {}, { class: 'select2 fullwidth', 'provider-prefs-for' => "#{@object.id}"})
= select(:payment_method, :type, payment_method_type_options(@providers), {}, { class: 'select2 fullwidth', required: true, placeholder: t("admin.choose"), 'provider-prefs-for' => "#{@object.id}"})
%div{"ng-include" => "include_html" }

View File

@@ -37,7 +37,7 @@
- method.distributors.each do |distributor|
= distributor.name
%br/
%td= method.class.clean_name
%td= payment_method_type_name(method.class.name)
- if spree_current_user.admin?
%td.align-center= method.environment.to_s.titleize
%td.align-center= method.display_on.blank? ? t('.both') : t('.' + method.display_on.to_s)

View File

@@ -131,13 +131,6 @@ RSpec.describe Spree::PaymentMethod do
expect(pm.errors.to_a).to eq(["Name can't be blank", "At least one hub must be selected"])
end
it "generates a clean name for known Payment Method types" do
expect(Spree::PaymentMethod::Check.clean_name)
.to eq('Cash/EFT/etc. (payments for which automatic validation is not required)')
expect(Spree::Gateway::PayPalExpress.clean_name).to eq('PayPal Express')
expect(Spree::Gateway::StripeSCA.clean_name).to eq('Stripe SCA')
end
it "computes the amount of fees" do
order = create(:order)

View File

@@ -92,9 +92,7 @@ RSpec::Matchers.define :have_select2 do |id, options = {}|
end
def selected_option_is(from, text)
within find(from) do
find("a.select2-choice").text == text
end
find("#{from} a.select2-choice", text:)
end
def with_select2_open(from)

View File

@@ -69,8 +69,6 @@ module WebHelper
.find(:css, '.select2-drop-active .select2-result-label',
text: options[:select_text] || value)
.click
expect(page).to have_select2 options[:from], selected: options[:select_text] || value
end
def open_select2(selector)

View File

@@ -152,7 +152,7 @@ RSpec.describe '
click_link 'Adjustments'
page.find('tr', text: 'Extra Adjustment').find('a.icon-edit').click
expect(page).to have_select2 :adjustment_tax_category_id, selected: []
expect(page).to have_select2 :adjustment_tax_category_id, selected: "None"
# When I edit the adjustment, setting a tax rate
select2_select 'GST', from: :adjustment_tax_category_id

View File

@@ -20,7 +20,11 @@ RSpec.describe '
click_link 'Payment Methods'
click_link 'New Payment Method'
expect(page).to have_select2 "payment_method_type", selected: "Choose..."
fill_in 'payment_method_name', with: 'Cheque payment method'
cash_name = "Cash/EFT/etc. (payments for which automatic validation is not required)"
select2_select cash_name, from: "payment_method_type"
check "payment_method_distributor_ids_#{@distributors[0].id}"
click_button 'Create'
@@ -243,6 +247,9 @@ RSpec.describe '
it "creates payment methods" do
visit spree.new_admin_payment_method_path
fill_in 'payment_method_name', with: 'Cheque payment method'
cash_name = "Cash/EFT/etc. (payments for which automatic validation is not required)"
select2_select cash_name, from: "payment_method_type"
expect(page).to have_field 'payment_method_description'
expect(page).to have_select 'payment_method_display_on'