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/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/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/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/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/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 a364a35d5e0..6c0d40c672f 100644 --- a/core/lib/generators/solidus/install/install_generator.rb +++ b/core/lib/generators/solidus/install/install_generator.rb @@ -28,9 +28,15 @@ class InstallGenerator < Rails::Generators::AppBase none ] + PAYMENT_METHODS = %w[ + paypal + bolt + 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 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' @@ -41,19 +47,14 @@ 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 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 @@ -61,10 +62,11 @@ 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 && @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' @@ -83,11 +85,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 @@ -123,9 +120,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) + Spree::Core::Engine.load_seed RUBY end @@ -172,6 +167,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" @@ -245,6 +244,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' @@ -263,7 +273,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 @@ -307,5 +317,25 @@ def detect_authentication_to_install TEXT ) end + + 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 + ask_with_description( + 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 'bolt', :bold}] Install `solidus_bolt`. + - [#{set_color 'none', :bold}] Skip installing a payment method. + TEXT + ) + end end end 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 %> diff --git a/core/lib/spree/testing_support/common_rake.rb b/core/lib/spree/testing_support/common_rake.rb index 9e68751d193..d0dde963686 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', @@ -33,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 aa3b765329f..a1db03f062f 100644 --- a/core/spec/generators/solidus/install/install_generator_spec.rb +++ b/core/spec/generators/solidus/install/install_generator_spec.rb @@ -5,6 +5,31 @@ 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") + 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) + 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 @@ -38,6 +63,24 @@ ) 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 + + 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'])