From ec55118c976144559479abca4ae84a7235350627 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 18 Oct 2022 11:24:14 +0200 Subject: [PATCH 01/12] Typo: missing dot --- core/lib/generators/solidus/install/install_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb index a364a35d5e0..0d89c586328 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -263,7 +263,7 @@ def detect_frontend_to_install - [#{set_color 'starter', :bold}] Generate all necessary controllers and views directly in your Rails app (#{set_color :default, :bold}). - [#{set_color 'classic', :bold}] Install `solidus_frontend`, was the default in previous solidus versions (#{set_color :deprecated, :bold}). - - [#{set_color 'none', :bold}] Skip installing a frontend + - [#{set_color 'none', :bold}] Skip installing a frontend. Selecting `starter` is recommended, however, some extensions are still only compatible with `classic`. TEXT From e959faea6a2ed62f8278366e852ead614f310211 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 18 Oct 2022 11:01:12 +0200 Subject: [PATCH 02/12] Remove the dummy app support for parallel testing Probably a TeamCity thing, an ancient CI solution in use 10 years ago. Ref: 6f3db2a02d2c55c73912f80cd149953fd33bbdd3. --- .../spree/dummy/templates/rails/database.yml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/core/lib/generators/spree/dummy/templates/rails/database.yml b/core/lib/generators/spree/dummy/templates/rails/database.yml index 8378ed815cb..8041f137b17 100644 --- a/core/lib/generators/spree/dummy/templates/rails/database.yml +++ b/core/lib/generators/spree/dummy/templates/rails/database.yml @@ -1,6 +1,3 @@ -<% if agent_number = ENV['TC_AGENT_NUMBER'] -database_prefix = agent_number + '_' -end %> <% db = case ENV['DB'] when 'mysql' 'mysql' @@ -22,14 +19,11 @@ end %> <% db_username = ENV['DB_USERNAME'] %> <% db_password = ENV['DB_PASSWORD'] %> - - - <% case ENV['DB'] when 'mysql' %> development: adapter: mysql2 - database: <%= database_prefix %><%= options[:lib_name] %>_solidus_development + database: <%= options[:lib_name] %>_solidus_development <% unless db_username.blank? %> username: <%= db_username %> <% end %> @@ -42,7 +36,7 @@ development: encoding: utf8 test: adapter: mysql2 - database: <%= database_prefix %><%= options[:lib_name] %>_solidus_test + database: <%= options[:lib_name] %>_solidus_test <% unless db_username.blank? %> username: <%= db_username %> <% end %> @@ -55,7 +49,7 @@ test: encoding: utf8 production: adapter: mysql2 - database: <%= database_prefix %><%= options[:lib_name] %>_solidus_production + database: <%= options[:lib_name] %>_solidus_production <% unless db_username.blank? %> username: <%= db_username %> <% end %> @@ -69,7 +63,7 @@ production: <% when 'postgres', 'postgresql' %> development: adapter: postgresql - database: <%= database_prefix %><%= options[:lib_name] %>_solidus_development + database: <%= options[:lib_name] %>_solidus_development <% unless db_username.blank? %> username: <%= db_username %> <% end %> @@ -82,7 +76,7 @@ development: min_messages: warning test: adapter: postgresql - database: <%= database_prefix %><%= options[:lib_name] %>_solidus_test + database: <%= options[:lib_name] %>_solidus_test <% unless db_username.blank? %> username: <%= db_username %> <% end %> @@ -95,7 +89,7 @@ test: min_messages: warning production: adapter: postgresql - database: <%= database_prefix %><%= options[:lib_name] %>_solidus_production + database: <%= options[:lib_name] %>_solidus_production <% unless db_username.blank? %> username: <%= db_username %> <% end %> From 2299d5bdb5daec3a709bfd265e0ed688d5d7ad02 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Mon, 3 Oct 2022 16:02:05 +0200 Subject: [PATCH 03/12] Don't install solidus_bolt unless requested --- .circleci/config.yml | 1 - .../solidus/install/app_templates/frontend/classic.rb | 6 +++++- .../generators/solidus/install/install_generator.rb | 11 +++++++++++ core/lib/spree/testing_support/common_rake.rb | 1 - 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 67a3aec8046..db0666b3eb7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -177,7 +177,6 @@ commands: command: | cd /tmp/my_app bundle add solidus --git "file://$(ruby -e"puts File.expand_path ENV['CIRCLE_WORKING_DIRECTORY']")" - export SKIP_SOLIDUS_BOLT='true' # workaround for solidus_frontend not being able to properly install bolt in this context unset RAILS_ENV # avoid doing everything on the test environment bin/rails generate solidus:install --auto-accept <> test_page: diff --git a/core/lib/generators/solidus/install/app_templates/frontend/classic.rb b/core/lib/generators/solidus/install/app_templates/frontend/classic.rb index 29f73f7a534..a5f60a9de47 100644 --- a/core/lib/generators/solidus/install/app_templates/frontend/classic.rb +++ b/core/lib/generators/solidus/install/app_templates/frontend/classic.rb @@ -9,4 +9,8 @@ bundle_command("add solidus_frontend #{github_solidus_frontend}") end -generate 'solidus_frontend:install' +# Disable solidus_bolt installation from solidus_frontend as it can be +# explicitly selected directly from the solidus installer. +with_env('SKIP_SOLIDUS_BOLT' => 'true') do + generate 'solidus_frontend:install' +end diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb index 0d89c586328..8b8fc7d529e 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -245,6 +245,17 @@ def apply_template_for(topic, selected) apply template_path end + def with_env(vars) + original = ENV.to_hash + vars.each { |k, v| ENV[k] = v } + + begin + yield + ensure + ENV.replace(original) + end + end + def detect_frontend_to_install # We need to support names that were available in v3.2 selected_frontend = 'starter' if options[:frontend] == 'solidus_starter_frontend' diff --git a/core/lib/spree/testing_support/common_rake.rb b/core/lib/spree/testing_support/common_rake.rb index 9e68751d193..82cefcc9d72 100644 --- a/core/lib/spree/testing_support/common_rake.rb +++ b/core/lib/spree/testing_support/common_rake.rb @@ -24,7 +24,6 @@ def initialize # While the dummy app is generated the current directory # within ruby is changed to that of the dummy app. sh({ - 'SKIP_SOLIDUS_BOLT' => '1', 'FRONTEND' => ENV['FRONTEND'] || 'classic', }, [ 'bin/rails', From 2558f4a41ab86d95c3799bfc153edfbc0b65683e Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 18 Oct 2022 11:22:45 +0200 Subject: [PATCH 04/12] Add a test for default options to the installer --- .../solidus/install/install_generator_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/spec/generators/solidus/install/install_generator_spec.rb b/core/spec/generators/solidus/install/install_generator_spec.rb index aa3b765329f..9b2d2c61e2b 100644 --- a/core/spec/generators/solidus/install/install_generator_spec.rb +++ b/core/spec/generators/solidus/install/install_generator_spec.rb @@ -5,6 +5,16 @@ RSpec.describe Solidus::InstallGenerator do describe '#prepare_options' do + it 'has a default setup' do + generator = described_class.new([], ['--auto-accept']) + generator.prepare_options + + aggregate_failures do + expect(generator.instance_variable_get(:@selected_frontend)).to eq("starter") + expect(generator.instance_variable_get(:@selected_authentication)).to eq("devise") + end + end + it 'disables "seeds" and "sample" if "migrate" are disabled' do generator = described_class.new([], ['--auto-accept', '--migrate=false']) generator.prepare_options From abeef5494550fac5a25b613a0b73d8d530909fe7 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 18 Oct 2022 11:44:01 +0200 Subject: [PATCH 05/12] Remove unused source paths from the install generator The first two were fundamentally wrong and chaining a relative path (`..`) with an absolute one (`__FILE__`). Examples in the rails documentation won't bother with calling super either and we actually don't need any templates other that those we prepared, so switching to `source_root` is fine. --- core/lib/generators/solidus/install/install_generator.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb index 8b8fc7d529e..6317476d2e9 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -47,13 +47,7 @@ class InstallGenerator < Rails::Generators::AppBase class_option :enforce_available_locales, type: :boolean, hide: true, default: nil class_option :lib_name, type: :string, hide: true, default: nil - def self.source_paths - paths = superclass.source_paths - paths << File.expand_path('../templates', "../../#{__FILE__}") - paths << File.expand_path('../templates', "../#{__FILE__}") - paths << File.expand_path('templates', __dir__) - paths.flatten - end + source_root "#{__dir__}/templates" def self.exit_on_failure? true From 06ab00ffdfefc3e7459eac88e49260604005666a Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 18 Oct 2022 11:47:00 +0200 Subject: [PATCH 06/12] Declare all option instance variables together in the installer --- .../generators/solidus/install/install_generator.rb | 9 ++------- .../solidus/install/install_generator_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb index 6317476d2e9..0d25907ddbf 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -55,8 +55,8 @@ def self.exit_on_failure? def prepare_options @run_migrations = options[:migrate] - @load_seed_data = options[:seed] - @load_sample_data = options[:sample] + @load_seed_data = options[:seed] && @run_migrations + @load_sample_data = options[:sample] && @run_migrations @selected_frontend = detect_frontend_to_install @selected_authentication = detect_authentication_to_install @@ -77,11 +77,6 @@ def prepare_options "DEPRECATION WARNING: using `solidus:install --lib-name` is now deprecated and has no effect. " \ "The option is legacy and should be removed from scripts still using it." end - - unless @run_migrations - @load_seed_data = false - @load_sample_data = false - end end def add_files diff --git a/core/spec/generators/solidus/install/install_generator_spec.rb b/core/spec/generators/solidus/install/install_generator_spec.rb index 9b2d2c61e2b..122c2474817 100644 --- a/core/spec/generators/solidus/install/install_generator_spec.rb +++ b/core/spec/generators/solidus/install/install_generator_spec.rb @@ -12,6 +12,9 @@ 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(:@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) end end @@ -48,6 +51,15 @@ ) end + it 'skips seed and sample data if migrations are disabled' do + generator = described_class.new([], ['--auto-accept', '--migrate=false']) + generator.prepare_options + + expect(generator.instance_variable_get(:@run_migrations)).to eq(false) + expect(generator.instance_variable_get(:@load_seed_data)).to eq(false) + expect(generator.instance_variable_get(:@load_sample_data)).to eq(false) + end + context 'supports legacy frontend option names' do it 'transform "solidus_frontend" into "classic"' do generator = described_class.new([], ['--auto-accept', '--frontend=solidus_frontend']) From d0cf978f7410b4353c9dc332f71a83bf149447e4 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 18 Oct 2022 11:51:20 +0200 Subject: [PATCH 07/12] Move auth seeds installation to the proper app-template --- .../solidus/install/app_templates/authentication/devise.rb | 4 ++++ core/lib/generators/solidus/install/install_generator.rb | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/lib/generators/solidus/install/app_templates/authentication/devise.rb b/core/lib/generators/solidus/install/app_templates/authentication/devise.rb index f48daf72d6a..3549029bb4e 100644 --- a/core/lib/generators/solidus/install/app_templates/authentication/devise.rb +++ b/core/lib/generators/solidus/install/app_templates/authentication/devise.rb @@ -10,3 +10,7 @@ end generate "solidus:auth:install #{migrations_flag}" + +append_file "db/seeds.rb", <<~RUBY + Spree::Auth::Engine.load_seed +RUBY diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb index 0d25907ddbf..cf67661b375 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -112,9 +112,7 @@ def create_overrides_directory def include_seed_data append_file "db/seeds.rb", <<~RUBY - Spree::Core::Engine.load_seed if defined?(Spree::Core) - Spree::Auth::Engine.load_seed if defined?(Spree::Auth) RUBY end From e2e164c3720c19f78f716a5f55fa3226ba14ba2b Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 18 Oct 2022 11:51:56 +0200 Subject: [PATCH 08/12] Be less defensive about loading seeds In no scenario we would be installing solidus without having installed solidus_core. --- core/lib/generators/solidus/install/install_generator.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb index cf67661b375..347327e40aa 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -112,7 +112,7 @@ def create_overrides_directory def include_seed_data append_file "db/seeds.rb", <<~RUBY - Spree::Core::Engine.load_seed if defined?(Spree::Core) + Spree::Core::Engine.load_seed RUBY end From d930744bcde73665aa04155bfc45599ea9533f7b Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 18 Oct 2022 12:00:55 +0200 Subject: [PATCH 09/12] Don't try to load samples without first running seeds --- core/lib/generators/solidus/install/install_generator.rb | 4 ++-- .../generators/solidus/install/install_generator_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb index 347327e40aa..7e04397493f 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -30,7 +30,7 @@ class InstallGenerator < Rails::Generators::AppBase class_option :migrate, type: :boolean, default: true, banner: 'Run Solidus migrations' class_option :seed, type: :boolean, default: true, banner: 'Load seed data (migrations must be run)' - class_option :sample, type: :boolean, default: true, banner: 'Load sample data (migrations must be run)' + class_option :sample, type: :boolean, default: true, banner: 'Load sample data (migrations and seeds must be run)' class_option :active_storage, type: :boolean, default: ( Rails.gem_version >= Gem::Version.new("6.1.0") ), banner: 'Install ActiveStorage as image attachments handler for products and taxons' @@ -56,7 +56,7 @@ def self.exit_on_failure? def prepare_options @run_migrations = options[:migrate] @load_seed_data = options[:seed] && @run_migrations - @load_sample_data = options[:sample] && @run_migrations + @load_sample_data = options[:sample] && @run_migrations && @load_seed_data @selected_frontend = detect_frontend_to_install @selected_authentication = detect_authentication_to_install diff --git a/core/spec/generators/solidus/install/install_generator_spec.rb b/core/spec/generators/solidus/install/install_generator_spec.rb index 122c2474817..a2e74536a76 100644 --- a/core/spec/generators/solidus/install/install_generator_spec.rb +++ b/core/spec/generators/solidus/install/install_generator_spec.rb @@ -60,6 +60,15 @@ expect(generator.instance_variable_get(:@load_sample_data)).to eq(false) end + it 'skips sample data if seeds are disabled' do + generator = described_class.new([], ['--auto-accept', '--seed=false']) + generator.prepare_options + + expect(generator.instance_variable_get(:@run_migrations)).to eq(true) + expect(generator.instance_variable_get(:@load_seed_data)).to eq(false) + expect(generator.instance_variable_get(:@load_sample_data)).to eq(false) + end + context 'supports legacy frontend option names' do it 'transform "solidus_frontend" into "classic"' do generator = described_class.new([], ['--auto-accept', '--frontend=solidus_frontend']) From 733eec7e2fe0dc60e944f2cda87a026d3be53b6b Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 4 Oct 2022 16:19:58 +0200 Subject: [PATCH 10/12] Add back the --payment-method option for `solidus:install` --- .../app_templates/payment_method/none.rb | 1 + .../solidus/install/install_generator.rb | 23 +++++++++++++++++++ core/lib/spree/testing_support/common_rake.rb | 1 + .../solidus/install/install_generator_spec.rb | 1 + 4 files changed, 26 insertions(+) create mode 100644 core/lib/generators/solidus/install/app_templates/payment_method/none.rb diff --git a/core/lib/generators/solidus/install/app_templates/payment_method/none.rb b/core/lib/generators/solidus/install/app_templates/payment_method/none.rb new file mode 100644 index 00000000000..740503eb56b --- /dev/null +++ b/core/lib/generators/solidus/install/app_templates/payment_method/none.rb @@ -0,0 +1 @@ +# noop diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb index 7e04397493f..54a19f853fe 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -28,6 +28,10 @@ class InstallGenerator < Rails::Generators::AppBase none ] + PAYMENT_METHODS = %w[ + none + ] + class_option :migrate, type: :boolean, default: true, banner: 'Run Solidus migrations' class_option :seed, type: :boolean, default: true, banner: 'Load seed data (migrations must be run)' class_option :sample, type: :boolean, default: true, banner: 'Load sample data (migrations and seeds must be run)' @@ -41,6 +45,7 @@ class InstallGenerator < Rails::Generators::AppBase class_option :frontend, type: :string, enum: FRONTENDS + LEGACY_FRONTENDS, default: nil, desc: "Indicates which frontend to install." class_option :authentication, type: :string, enum: AUTHENTICATIONS, default: nil, desc: "Indicates which authentication system to install." + class_option :payment_method, type: :string, enum: PAYMENT_METHODS, default: nil, desc: "Indicates which payment method to install." # DEPRECATED class_option :with_authentication, type: :boolean, hide: true, default: nil @@ -59,6 +64,7 @@ def prepare_options @load_sample_data = options[:sample] && @run_migrations && @load_seed_data @selected_frontend = detect_frontend_to_install @selected_authentication = detect_authentication_to_install + @selected_payment_method = detect_payment_method_to_install # Silence verbose output (e.g. Rails migrations will rely on this environment variable) ENV['VERBOSE'] = 'false' @@ -159,6 +165,10 @@ def install_frontend apply_template_for :frontend, @selected_frontend end + def install_payment_method + apply_template_for :payment_method, @selected_payment_method + end + def populate_seed_data if @load_seed_data say_status :loading, "seed data" @@ -305,5 +315,18 @@ def detect_authentication_to_install TEXT ) end + + def detect_payment_method_to_install + options[:payment_method] || + ask_with_description( + default: 'none', + limited_to: PAYMENT_METHODS, + desc: <<~TEXT + Which payment method would you like to use? + + - [#{set_color 'none', :bold}] Skip installing a payment method. + TEXT + ) + end end end diff --git a/core/lib/spree/testing_support/common_rake.rb b/core/lib/spree/testing_support/common_rake.rb index 82cefcc9d72..d0dde963686 100644 --- a/core/lib/spree/testing_support/common_rake.rb +++ b/core/lib/spree/testing_support/common_rake.rb @@ -32,6 +32,7 @@ def initialize Dir.pwd, # use the current dir as Rails.root "--auto-accept", "--authentication=none", + "--payment-method=none", "--migrate=false", "--seed=false", "--sample=false", diff --git a/core/spec/generators/solidus/install/install_generator_spec.rb b/core/spec/generators/solidus/install/install_generator_spec.rb index a2e74536a76..a6c45bf0556 100644 --- a/core/spec/generators/solidus/install/install_generator_spec.rb +++ b/core/spec/generators/solidus/install/install_generator_spec.rb @@ -12,6 +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(:@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) From 21c1549797e16f7b825f426085685836f549f314 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 18 Oct 2022 11:23:55 +0200 Subject: [PATCH 11/12] Add back PayPal as the default payment method in the installer --- .../install/app_templates/payment_method/paypal.rb | 9 +++++++++ .../generators/solidus/install/install_generator.rb | 7 ++++++- .../solidus/install/install_generator_spec.rb | 11 +++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 core/lib/generators/solidus/install/app_templates/payment_method/paypal.rb 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 new file mode 100644 index 00000000000..65826d549b3 --- /dev/null +++ b/core/lib/generators/solidus/install/app_templates/payment_method/paypal.rb @@ -0,0 +1,9 @@ +unless Bundler.locked_gems.dependencies['solidus_frontend'] + say_status :warning, "Support for frontends other than `solidus_frontend` by `solidus_paypal_commerce_platform` is still in progress.", :yellow +end + +unless Bundler.locked_gems.dependencies['solidus_paypal_commerce_platform'] + bundle_command 'add solidus_paypal_commerce_platform' +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 54a19f853fe..00c66735f98 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -29,6 +29,7 @@ class InstallGenerator < Rails::Generators::AppBase ] PAYMENT_METHODS = %w[ + paypal none ] @@ -317,13 +318,17 @@ def detect_authentication_to_install end def detect_payment_method_to_install + return 'paypal' if Bundler.locked_gems.dependencies['solidus_paypal_commerce_platform'] options[:payment_method] || + (options[:auto_accept] && @selected_frontend == 'classic' ? 'paypal' : 'none') || + (@selected_frontend != 'classic' && 'none') || # bail out if it's not classic ask_with_description( - default: 'none', + default: 'paypal', 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 'none', :bold}] Skip installing a payment method. TEXT ) diff --git a/core/spec/generators/solidus/install/install_generator_spec.rb b/core/spec/generators/solidus/install/install_generator_spec.rb index a6c45bf0556..a1db03f062f 100644 --- a/core/spec/generators/solidus/install/install_generator_spec.rb +++ b/core/spec/generators/solidus/install/install_generator_spec.rb @@ -19,6 +19,17 @@ end end + it 'defaults to "paypal" for payments when frontend is "classic"' do + generator = described_class.new([], ['--auto-accept', '--frontend=classic']) + generator.prepare_options + + aggregate_failures do + expect(generator.instance_variable_get(:@selected_frontend)).to eq("classic") + expect(generator.instance_variable_get(:@selected_authentication)).to eq("devise") + expect(generator.instance_variable_get(:@selected_payment_method)).to eq("paypal") + end + end + it 'disables "seeds" and "sample" if "migrate" are disabled' do generator = described_class.new([], ['--auto-accept', '--migrate=false']) generator.prepare_options From 374c8f299dc3277f7c500381349a350db9c7ed39 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Tue, 18 Oct 2022 11:24:54 +0200 Subject: [PATCH 12/12] Add Bolt as an alternative payment method option --- .../install/app_templates/payment_method/bolt.rb | 13 +++++++++++++ .../generators/solidus/install/install_generator.rb | 4 ++++ 2 files changed, 17 insertions(+) create mode 100644 core/lib/generators/solidus/install/app_templates/payment_method/bolt.rb diff --git a/core/lib/generators/solidus/install/app_templates/payment_method/bolt.rb b/core/lib/generators/solidus/install/app_templates/payment_method/bolt.rb new file mode 100644 index 00000000000..fdb6d602fec --- /dev/null +++ b/core/lib/generators/solidus/install/app_templates/payment_method/bolt.rb @@ -0,0 +1,13 @@ +unless Bundler.locked_gems.dependencies['solidus_frontend'] + say_status :warning, "Support for frontends other than `solidus_frontend` by `solidus_bolt` is still in progress.", :yellow +end + +unless Bundler.locked_gems.dependencies['solidus_auth_devise'] + say_status :warning, "Running solidus_bolt without solidus_auth_devise is not supported.", :yellow +end + +unless Bundler.locked_gems.dependencies['solidus_bolt'] + bundle_command 'add solidus_bolt' +end + +generate 'solidus_bolt:install' diff --git a/core/lib/generators/solidus/install/install_generator.rb b/core/lib/generators/solidus/install/install_generator.rb index 00c66735f98..6c0d40c672f 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -30,6 +30,7 @@ class InstallGenerator < Rails::Generators::AppBase PAYMENT_METHODS = %w[ paypal + bolt none ] @@ -319,6 +320,8 @@ def detect_authentication_to_install 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 @@ -329,6 +332,7 @@ def detect_payment_method_to_install 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. TEXT )