From 2a7cb50fa981723e17812f4af8aa337a8060c940 Mon Sep 17 00:00:00 2001 From: James Wu Date: Sat, 18 Mar 2023 23:02:23 +0900 Subject: [PATCH] Keep and display submitted data on new payment method page --- .../spree/admin/payment_methods_controller.rb | 4 ++ .../payment_methods/_providers.html.haml | 2 +- spec/system/admin/payment_method_spec.rb | 38 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/controllers/spree/admin/payment_methods_controller.rb b/app/controllers/spree/admin/payment_methods_controller.rb index 9fc0207d77..077cddbca8 100644 --- a/app/controllers/spree/admin/payment_methods_controller.rb +++ b/app/controllers/spree/admin/payment_methods_controller.rb @@ -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 diff --git a/app/views/spree/admin/payment_methods/_providers.html.haml b/app/views/spree/admin/payment_methods/_providers.html.haml index aa1fce7fe8..b25a7b09c5 100644 --- a/app/views/spree/admin/payment_methods/_providers.html.haml +++ b/app/views/spree/admin/payment_methods/_providers.html.haml @@ -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" } diff --git a/spec/system/admin/payment_method_spec.rb b/spec/system/admin/payment_method_spec.rb index e079252694..dd35e75471 100644 --- a/spec/system/admin/payment_method_spec.rb +++ b/spec/system/admin/payment_method_spec.rb @@ -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