Keep and display submitted data on new payment method page

This commit is contained in:
James Wu
2023-03-18 23:02:23 +09:00
committed by David Cook
parent 29ddc68d20
commit 2a7cb50fa9
3 changed files with 43 additions and 1 deletions

View File

@@ -16,6 +16,10 @@ module Spree
@payment_method = payment_method_class.constantize.new(base_params)
@object = @payment_method
if !base_params["calculator_type"] && gateway_params["calculator_type"]
@payment_method.calculator_type = gateway_params["calculator_type"]
end
load_hubs
if @payment_method.save

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, (!@object.persisted? ? { :selected => "Spree::PaymentMethod::Check"} : {}), { class: 'select2 fullwidth', 'provider-prefs-for' => "#{@object.id}"})
= collection_select(:payment_method, :type, @providers, :to_s, :clean_name, {}, { class: 'select2 fullwidth', 'provider-prefs-for' => "#{@object.id}"})
%div{"ng-include" => "include_html" }

View File

@@ -112,6 +112,44 @@ describe '
expect(page).to have_field "payment_method_distributor_ids_#{@distributors[2].id}",
checked: false
end
it "retains and displays data that was just submitted" do
login_as_admin_and_visit spree.edit_admin_general_settings_path
click_link 'Payment Methods'
click_link 'New Payment Method'
fill_in "payment_method_name", with: 'Cheque payment method'
fill_in "payment_method_description", with: "Payment description"
select2_select "PayPal Express", from: "payment_method_type"
select2_select "Flat Percent", from: 'calc_type'
click_button 'Create'
expect(page).to have_field "payment_method_name", with: "Cheque payment method"
expect(page).to have_field "payment_method_description", with: "Payment description"
expect(page).to have_select("payment_method_type", selected: "PayPal Express")
expect(page).to have_select("calc_type", selected: "Flat Percent")
select2_select "Price Sack", from: 'calc_type'
click_button 'Create'
expect(page).to have_select("calc_type", selected: "Price Sack")
expect(page).to have_field "payment_method_name", with: "Cheque payment method"
expect(page).to have_field "payment_method_description", with: "Payment description"
expect(page).to have_select("payment_method_type", selected: "PayPal Express")
check "payment_method_distributor_ids_#{@distributors[0].id}"
click_button 'Create'
expect(page).to have_field "payment_method_distributor_ids_#{@distributors[0].id}",
checked: true
expect(page).to have_select("calc_type", selected: "Price Sack")
expect(page).to have_field "payment_method_name", with: "Cheque payment method"
expect(page).to have_field "payment_method_description", with: "Payment description"
expect(page).to have_select("payment_method_type", selected: "PayPal Express")
end
end
it "updating a payment method" do