From 60b0ac3bd233955323301ebcedb34fb4f877ac63 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 25 Nov 2022 12:53:38 +0100 Subject: [PATCH 1/2] Don't test twice the alternative frontend option names Those are already covered in the installer generator spec. --- .circleci/config.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4fad28271b2..6a3a004a763 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -224,12 +224,9 @@ jobs: - install_solidus: { flags: "--sample=false --frontend=none --authentication=none" } - test_page: { expected_text: "Ruby on Rails" } - - install_solidus: { flags: "--sample=false --frontend=solidus_frontend --authentication=custom" } + - install_solidus: { flags: "--sample=false --frontend=classic --authentication=custom" } - test_page: { expected_text: "data-hook=" } - - install_solidus: { flags: "--sample=false --frontend=solidus_starter_frontend --authentication=devise" } - - test_page: { expected_text: "The only eCommerce platform you’ll ever need." } - - run: name: "Test `rake task: extensions:test_app`" command: | From d40a01c9db89cb11e9fc7d05c3889aa6f8e968c4 Mon Sep 17 00:00:00 2001 From: Elia Schito <elia@schito.me> Date: Fri, 25 Nov 2022 12:55:54 +0100 Subject: [PATCH 2/2] Restore the payment method "paypal" option for the starter frontend --- .circleci/config.yml | 10 +++++ .../app_templates/payment_method/paypal.rb | 3 +- .../solidus/install/install_generator.rb | 24 +++++++---- .../solidus/install/install_generator_spec.rb | 40 ++++++++++++++++++- 4 files changed, 68 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6a3a004a763..4a05b36879b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -220,12 +220,22 @@ jobs: - install_solidus: { flags: "--sample=false --frontend=starter --authentication=devise" } - test_page: { expected_text: "The only eCommerce platform you’ll ever need." } + - run: + name: Ensure the correct PayPal is installed for SSF + command: | + cd /tmp/my_app + bundle list | grep 'solidus_paypal_commerce_platform (1.' - install_solidus: { flags: "--sample=false --frontend=none --authentication=none" } - test_page: { expected_text: "<title>Ruby on Rails" } - install_solidus: { flags: "--sample=false --frontend=classic --authentication=custom" } - test_page: { expected_text: "data-hook=" } + - run: + name: Ensure the correct PayPal is installed for SSF + command: | + cd /tmp/my_app + bundle list | grep 'solidus_paypal_commerce_platform (0.' - run: name: "Test `rake task: extensions:test_app`" diff --git a/core/lib/generators/solidus/install/app_templates/payment_method/paypal.rb b/core/lib/generators/solidus/install/app_templates/payment_method/paypal.rb index 65826d549b3..de28c310085 100644 --- a/core/lib/generators/solidus/install/app_templates/payment_method/paypal.rb +++ b/core/lib/generators/solidus/install/app_templates/payment_method/paypal.rb @@ -3,7 +3,8 @@ end unless Bundler.locked_gems.dependencies['solidus_paypal_commerce_platform'] - bundle_command 'add solidus_paypal_commerce_platform' + version = @selected_frontend == 'classic' ? '< 1' : '>= 1.a' + bundle_command "add solidus_paypal_commerce_platform --version='#{version}'" end generate 'solidus_paypal_commerce_platform:install' diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb index 6c0d40c672f..831b53bdca6 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -16,6 +16,7 @@ class InstallGenerator < Rails::Generators::AppBase classic starter ] + LEGACY_FRONTENDS = %w[ solidus_starter_frontend solidus_frontend @@ -322,18 +323,27 @@ def detect_payment_method_to_install return 'paypal' if Bundler.locked_gems.dependencies['solidus_paypal_commerce_platform'] return 'bolt' if Bundler.locked_gems.dependencies['solidus_bolt'] - options[:payment_method] || - (options[:auto_accept] && @selected_frontend == 'classic' ? 'paypal' : 'none') || - (@selected_frontend != 'classic' && 'none') || # bail out if it's not classic + descriptions = { + paypal: "- [#{set_color 'paypal', :bold}] Install `solidus_paypal_commerce_platform` (#{set_color :default, :bold}).", + bolt: "- [#{set_color 'bolt', :bold}] Install `solidus_bolt`.", + none: "- [#{set_color 'none', :bold}] Skip installing a payment method.", + } + + payment_methods = PAYMENT_METHODS + + if @selected_frontend != 'classic' + payment_methods -= ['bolt'] + descriptions.delete(:bolt) + end + + selected = options[:payment_method] || (options[:auto_accept] && 'paypal') || ask_with_description( default: 'paypal', - limited_to: PAYMENT_METHODS, + limited_to: payment_methods, desc: <<~TEXT Which payment method would you like to use? - - [#{set_color 'paypal', :bold}] Install `solidus_paypal_commerce_platform` (#{set_color :default, :bold}). - - [#{set_color 'bolt', :bold}] Install `solidus_bolt`. - - [#{set_color 'none', :bold}] Skip installing a payment method. + #{descriptions.values.join("\n")} TEXT ) end diff --git a/core/spec/generators/solidus/install/install_generator_spec.rb b/core/spec/generators/solidus/install/install_generator_spec.rb index a1db03f062f..88f4b7ce26f 100644 --- a/core/spec/generators/solidus/install/install_generator_spec.rb +++ b/core/spec/generators/solidus/install/install_generator_spec.rb @@ -12,7 +12,7 @@ aggregate_failures do expect(generator.instance_variable_get(:@selected_frontend)).to eq("starter") expect(generator.instance_variable_get(:@selected_authentication)).to eq("devise") - expect(generator.instance_variable_get(:@selected_payment_method)).to eq("none") + expect(generator.instance_variable_get(:@selected_payment_method)).to eq("paypal") expect(generator.instance_variable_get(:@run_migrations)).to eq(true) expect(generator.instance_variable_get(:@load_seed_data)).to eq(true) expect(generator.instance_variable_get(:@load_sample_data)).to eq(true) @@ -96,5 +96,43 @@ expect(generator.instance_variable_get(:@selected_frontend)).to eq('starter') end end + + context 'when asked interactively' do + it 'presents different options for the "classic"' do + questions = [] + generator = described_class.new([], ['--frontend=classic', '--authentication=devise']) + allow(generator).to receive(:ask_with_description) { |**args| questions << args } + + generator.prepare_options + + expect(questions.size).to eq(1) + expect(questions.first[:limited_to]).to eq(['paypal', 'bolt', 'none']) + expect(questions.first[:default]).to eq('paypal') + expect(strip_ansi questions.first[:desc]).to include('[paypal]') + expect(strip_ansi questions.first[:desc]).to include('[bolt]') + expect(strip_ansi questions.first[:desc]).to include('[none]') + end + + it 'presents different options for the "classic"' do + questions = [] + generator = described_class.new([], ['--frontend=starter', '--authentication=devise']) + allow(generator).to receive(:ask_with_description) { |**args| questions << args } + + generator.prepare_options + + expect(questions.size).to eq(1) + expect(questions.first[:limited_to]).to eq(['paypal', 'none']) + expect(questions.first[:default]).to eq('paypal') + expect(strip_ansi questions.first[:desc]).to include('[paypal]') + expect(strip_ansi questions.first[:desc]).not_to include('[bolt]') + expect(strip_ansi questions.first[:desc]).to include('[none]') + end + end + end + + private + + def strip_ansi(string) + string.gsub(/\u001b\[.*?m/, '') end end