Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Setup storefront sandbox/test app with devise for full end-to-end testing

Damian Legawiec8d81a5406d39
diff --git a/core/lib/generators/spree/install/install_generator.rb b/core/lib/generators/spree/install/install_generator.rb
index f08d3f2981..ece1ecf2f2 100644
--- a/core/lib/generators/spree/install/install_generator.rb
+++ b/core/lib/generators/spree/install/install_generator.rb
@@ -12,7 +12,6 @@ module Spree
class_option :sample, type: :boolean, default: false, banner: 'load sample data (migrations must be run)'
class_option :install_storefront, type: :boolean, default: false, banner: 'installs default rails storefront'
class_option :install_admin, type: :boolean, default: false, banner: 'installs default rails admin'
- class_option :copy_storefront, type: :boolean, default: false, banner: 'copy all storefront views and stylesheets'
class_option :auto_accept, type: :boolean
class_option :user_class, type: :string
class_option :admin_email, type: :string
@@ -35,7 +34,6 @@ module Spree
@load_sample_data = options[:sample]
@install_storefront = options[:install_storefront]
@install_admin = options[:install_admin]
- @copy_storefront = options[:copy_storefront]
@authentication = options[:authentication]
unless @run_migrations
@@ -92,12 +90,6 @@ module Spree
end
end
- def copy_storefront
- if @copy_storefront && Spree::Core::Engine.frontend_available?
- generate 'spree:storefront:copy_storefront'
- end
- end
-
def configure_application
application <<-APP.strip_heredoc.indent!(4)
diff --git a/core/lib/spree/testing_support/common_rake.rb b/core/lib/spree/testing_support/common_rake.rb
index d9ef743c98..8d0cffdc9b 100644
--- a/core/lib/spree/testing_support/common_rake.rb
+++ b/core/lib/spree/testing_support/common_rake.rb
@@ -33,13 +33,19 @@ namespace :common do
system('bin/rails stimulus:install')
end
+ # install devise if it's not the legacy user, useful for testing storefront
+ if args[:authentication] == 'devise' && args[:user_class] != 'Spree::LegacyUser'
+ system('bin/rails g devise:install --force --auto-accept')
+ system("bin/rails g devise #{args[:user_class]} --force --auto-accept")
+ system('rm -rf spec') # we need to cleanup factories created by devise to avoid naming conflict
+ end
+
Spree::InstallGenerator.start [
"--lib_name=#{ENV['LIB_NAME']}",
'--auto-accept',
'--migrate=false',
'--seed=false',
'--sample=false',
- '--copy_storefront=false',
"--install_storefront=#{args[:install_storefront]}",
"--install_admin=#{args[:install_admin]}",
"--user_class=#{args[:user_class]}",
diff --git a/core/lib/spree/testing_support/factories/user_factory.rb b/core/lib/spree/testing_support/factories/user_factory.rb
index 5ae420054a..536fa57b45 100644
--- a/core/lib/spree/testing_support/factories/user_factory.rb
+++ b/core/lib/spree/testing_support/factories/user_factory.rb
@@ -5,8 +5,8 @@ FactoryBot.define do
password { 'secret' }
password_confirmation { password }
- first_name { FFaker::Name.first_name } if Spree.user_class.attribute_method?(:first_name)
- last_name { FFaker::Name.last_name } if Spree.user_class.attribute_method?(:last_name)
+ first_name { FFaker::Name.first_name }
+ last_name { FFaker::Name.last_name }
public_metadata { {} }
private_metadata { {} }
diff --git a/storefront/Gemfile b/storefront/Gemfile
index 1dc0e76e77..6a7fc947ba 100644
--- a/storefront/Gemfile
+++ b/storefront/Gemfile
@@ -4,6 +4,8 @@ gem 'spree_core', path: '../core'
gem 'spree_api', path: '../api'
gem 'spree_emails', path: '../emails'
+gem 'devise'
+
group :test, :development do
gem 'selenium-webdriver'
end
diff --git a/storefront/Rakefile b/storefront/Rakefile
index 56135337be..b546e3604d 100644
--- a/storefront/Rakefile
+++ b/storefront/Rakefile
@@ -11,5 +11,11 @@ task default: :spec
desc "Generates a dummy app for testing"
task :test_app do
ENV['LIB_NAME'] = 'spree/storefront'
- Rake::Task['common:test_app'].execute
+
+ Rake::Task['common:test_app'].execute(
+ user_class: 'User',
+ authentication: 'devise',
+ install_storefront: 'true',
+ install_admin: 'false'
+ )
end