solidus_act_as_tenant 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +62 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +1 -0
  5. data/.github_changelog_generator +2 -0
  6. data/.gitignore +21 -0
  7. data/.rspec +2 -0
  8. data/.rubocop.yml +5 -0
  9. data/CHANGELOG.md +3 -0
  10. data/Gemfile +47 -0
  11. data/LICENSE +26 -0
  12. data/README.md +100 -0
  13. data/Rakefile +7 -0
  14. data/app/decorators/spree/store_credit_decorator.rb +16 -0
  15. data/app/decorators/spree/variant_decorator.rb +22 -0
  16. data/app/models/spree/products_taxon.rb +9 -0
  17. data/app/models/spree/reimbursement_credit.rb +9 -0
  18. data/app/models/spree/tenant.rb +9 -0
  19. data/bin/console +17 -0
  20. data/bin/rails +7 -0
  21. data/bin/rails-engine +13 -0
  22. data/bin/rails-sandbox +16 -0
  23. data/bin/rake +7 -0
  24. data/bin/sandbox +76 -0
  25. data/bin/setup +8 -0
  26. data/config/locales/en.yml +4 -0
  27. data/config/routes.rb +5 -0
  28. data/db/migrate/20241204043609_add_tenant_id_to_solidus_tables.rb +100 -0
  29. data/db/migrate/20241204055845_update_spree_unique_indexes_with_tenant_scope.rb +17 -0
  30. data/db/migrate/20241204105318_create_spree_tenants.rb +15 -0
  31. data/lib/generators/solidus_act_as_tenant/install/install_generator.rb +38 -0
  32. data/lib/generators/solidus_act_as_tenant/install/templates/initializer.rb +8 -0
  33. data/lib/generators/solidus_act_as_tenant/install/templates/tenant_aware_models.yml +95 -0
  34. data/lib/solidus_act_as_tenant/configuration.rb +19 -0
  35. data/lib/solidus_act_as_tenant/engine.rb +23 -0
  36. data/lib/solidus_act_as_tenant/factories/preference_factory.rb +7 -0
  37. data/lib/solidus_act_as_tenant/factories/tenant_factory.rb +9 -0
  38. data/lib/solidus_act_as_tenant/tenant_aware.rb +50 -0
  39. data/lib/solidus_act_as_tenant/testing_support/factories.rb +5 -0
  40. data/lib/solidus_act_as_tenant/utils/tenant_selector.rb +74 -0
  41. data/lib/solidus_act_as_tenant/version.rb +5 -0
  42. data/lib/solidus_act_as_tenant.rb +8 -0
  43. data/solidus_act_as_tenant.gemspec +38 -0
  44. data/spec/lib/solidus_act_as_tenant/tenant_aware_spec.rb +48 -0
  45. data/spec/models/spree/store_credit_spec.rb +15 -0
  46. data/spec/models/spree/variant_spec.rb +37 -0
  47. data/spec/spec_helper.rb +32 -0
  48. data/spec/support/config.rb +21 -0
  49. metadata +177 -0
@@ -0,0 +1,15 @@
1
+ class CreateSpreeTenants < ActiveRecord::Migration[7.0]
2
+ def change
3
+ create_table :spree_tenants do |t|
4
+ t.string :name
5
+ t.string :subdomain # Only used if setting tenant by subdomain
6
+ t.string :domain # Only used if setting tenant by domain
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :spree_tenants, :name, unique: true
12
+ add_index :spree_tenants, :subdomain, unique: true
13
+ add_index :spree_tenants, :domain, unique: true
14
+ end
15
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusActAsTenant
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ class_option :auto_run_migrations, type: :boolean, default: false
7
+ source_root File.expand_path('templates', __dir__)
8
+
9
+ def self.exit_on_failure?
10
+ true
11
+ end
12
+
13
+ def copy_initializer
14
+ template 'initializer.rb', 'config/initializers/solidus_act_as_tenant.rb'
15
+ end
16
+
17
+ def copy_config
18
+ template 'tenant_aware_models.yml', 'config/tenant_aware_models.yml'
19
+ end
20
+
21
+ def add_migrations
22
+ run 'bin/rails railties:install:migrations FROM=solidus_act_as_tenant'
23
+ end
24
+
25
+ def run_migrations
26
+ puts 'Remember to inspect and adapt the migration files before migrating!' # rubocop:disable Rails/Output
27
+ run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(
28
+ ask('Would you like to run the migrations now? [Y/n]')
29
+ )
30
+ if run_migrations
31
+ run 'bin/rails db:migrate'
32
+ else
33
+ puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ SolidusActAsTenant.configure do |config|
4
+ # This configuration is used to dynamically prepend existing models with the acts_as_tenant concern.
5
+ # See the tenant_aware_classes.yml file for inormation on how to configure this file.
6
+ config.tenant_aware_models =
7
+ YAML.safe_load(ERB.new(File.read(Rails.root.join('config/tenant_aware_models.yml'))).result)
8
+ end
@@ -0,0 +1,95 @@
1
+ # Any model that is already defined and has an a tenant_id column can be added to this list.
2
+ # It is not restricted to the Solidus models so it can be used for any model that is inherited from a gem.
3
+
4
+ # It is importnant to also note that any unique indexes on the database will need to replaced with a unique index on scoped to the tenant_id column.
5
+
6
+ # Format:
7
+ # - [Class name, [uniqueness attributes to update with tenant scope]]
8
+ # The uniqueness attributes array are optional for cases where there is already a uniqueness validation on the model that are not scoped to the tenant_id column.
9
+
10
+ # Notes regarding Solidus models:
11
+ # These are are classes that are created in this extention because they are not defined in Solidus:
12
+ # [Spree::ProductTaxon, []],
13
+ # [Spree::ReimbursementCredit, []],
14
+
15
+ # These are classes that don't need a tenancy but may be desired:
16
+ # [Spree::Country, []],
17
+ # [Spree::State, []],
18
+ # [Spree::PermissionSet, []],
19
+ # [Spree::Role, [:name]],
20
+ # [Spree::RolePermission, []],
21
+
22
+ # These are not needed at all as they are internal to Solidus (and may cause issues):
23
+ # [Spree::OrderMutex, []],
24
+
25
+
26
+ ---
27
+ - [<%= ::Spree.user_class.to_s %>, [email]]
28
+ - [Spree::Address, []]
29
+ - [Spree::AdjustmentReason, [name, code]]
30
+ - [Spree::Adjustment, []]
31
+ - [Spree::Asset, []]
32
+ - [Spree::Calculator, []]
33
+ - [Spree::Carton, []]
34
+ - [Spree::CreditCard, []]
35
+ - [Spree::CustomerReturn, []]
36
+ - [Spree::InventoryUnit, []]
37
+ - [Spree::LineItemAction, []]
38
+ - [Spree::LineItem, []]
39
+ - [Spree::LogEntry, []]
40
+ - [Spree::OptionType, [name]]
41
+ - [Spree::OptionValue, [name]]
42
+ - [Spree::OptionValuesVariant, []]
43
+ - [Spree::Order, []]
44
+ - [Spree::PaymentCaptureEvent, []]
45
+ - [Spree::PaymentMethod, []]
46
+ - [Spree::Payment, []]
47
+ - [Spree::Preference, [key]]
48
+ - [Spree::Price, []]
49
+ - [Spree::ProductOptionType, []]
50
+ - [Spree::ProductProperty, []]
51
+ - [Spree::Product, [slug]]
52
+ - [Spree::Property, []]
53
+ - [Spree::RefundReason, [name]]
54
+ - [Spree::Refund, []]
55
+ - [Spree::ReimbursementType, [name]]
56
+ - [Spree::Reimbursement, []]
57
+ - [Spree::ReturnAuthorization, []]
58
+ - [Spree::ReturnItem, []]
59
+ - [Spree::ReturnReason, []]
60
+ - [Spree::RoleUser, []]
61
+ - [Spree::Shipment, []]
62
+ - [Spree::ShippingCategory, []]
63
+ - [Spree::ShippingMethodCategory, []]
64
+ - [Spree::ShippingMethodStockLocation, []]
65
+ - [Spree::ShippingMethodZone, []]
66
+ - [Spree::ShippingMethod, []]
67
+ - [Spree::ShippingRateTax, []]
68
+ - [Spree::StateChange, []]
69
+ - [Spree::ShippingRate, []]
70
+ - [Spree::StockItem, []]
71
+ - [Spree::StockLocation, [code]]
72
+ - [Spree::StockMovement, []]
73
+ - [Spree::StoreCreditCategory, []]
74
+ - [Spree::StoreCreditEvent, []]
75
+ - [Spree::StoreCreditType, []]
76
+ - [Spree::StoreCredit, []]
77
+ - [Spree::StorePaymentMethod, []]
78
+ - [Spree::Store, [code]]
79
+ - [Spree::StoreShippingMethod, []]
80
+ - [Spree::StoreCreditReason, [name]]
81
+ - [Spree::TaxCategory, [name]]
82
+ - [Spree::Taxonomy, [name]]
83
+ - [Spree::Taxon, []]
84
+ - [Spree::TaxRate, []]
85
+ - [Spree::TaxRateTaxCategory, []]
86
+ - [Spree::UnitCancel, []]
87
+ - [Spree::UserAddress, []]
88
+ - [Spree::UserStockLocation, []]
89
+ - [Spree::VariantPropertyRuleCondition, []]
90
+ - [Spree::VariantPropertyRuleValue, []]
91
+ - [Spree::VariantPropertyRule, []]
92
+ - [Spree::Variant, [sku]]
93
+ - [Spree::WalletPaymentSource, []]
94
+ - [Spree::ZoneMember, []]
95
+ - [Spree::Zone, [name]]
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusActAsTenant
4
+ class Configuration
5
+ attr_accessor :tenant_aware_models
6
+ end
7
+
8
+ class << self
9
+ def configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+
13
+ alias config configuration
14
+
15
+ def configure
16
+ yield configuration
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'solidus_core'
4
+ require 'solidus_support'
5
+
6
+ module SolidusActAsTenant
7
+ class Engine < Rails::Engine
8
+ include SolidusSupport::EngineExtensions
9
+
10
+ isolate_namespace ::Spree
11
+
12
+ engine_name 'solidus_act_as_tenant'
13
+
14
+ # use rspec for tests
15
+ config.generators do |g|
16
+ g.test_framework :rspec
17
+ end
18
+
19
+ config.after_initialize do
20
+ SolidusActAsTenant::TenantAware.setup_tenant_aware_models
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :preference, class: Spree::Preference do
5
+ sequence(:key) { |i| "Key#{i}" }
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :tenant, class: Spree::Tenant do
5
+ sequence(:name) { |i| "Demo #{i}" }
6
+ sequence(:subdomain) { |i| "demo-#{i}" }
7
+ sequence(:domain) { |i| "demo-#{i}.com" }
8
+ end
9
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusActAsTenant
4
+ # TenantAware automatically adds multi-tenant support to models
5
+ # by adding tenant scoping and updating uniqueness validations to be tenant-aware.
6
+ module TenantAware
7
+ class << self
8
+ def setup_tenant_aware_models
9
+ tenant_aware_models = SolidusActAsTenant.config.tenant_aware_models || []
10
+
11
+ tenant_aware_models.each do |klass, validator_attributes|
12
+ Module.new do
13
+ @validator_attributes = validator_attributes
14
+ define_singleton_method(:prepended) do |base|
15
+ base.acts_as_tenant :tenant, class_name: 'Spree::Tenant'
16
+
17
+ @validator_attributes&.each do |attribute|
18
+ TenantAware.update_uniqueness_validation(base, attribute)
19
+ end
20
+ end
21
+
22
+ klass.constantize.prepend(self)
23
+ end
24
+ end
25
+ end
26
+
27
+ def update_uniqueness_validation(base, attribute)
28
+ attribute = attribute.to_sym
29
+ validator = base._validators[attribute].find { _1.kind == :uniqueness }
30
+ raise "No uniqueness validator found for #{attribute} on #{base}" unless validator
31
+
32
+ new_options = validator.options.dup
33
+ new_options[:scope] = Array(new_options[:scope]).push(:tenant_id)
34
+
35
+ remove_existing_validation(base, attribute)
36
+ base.validates_uniqueness_of attribute, **new_options
37
+ end
38
+
39
+ def remove_existing_validation(base, attribute)
40
+ base._validators[attribute].reject! { _1.kind == :uniqueness }
41
+ base._validate_callbacks.each do |callback|
42
+ next unless callback.filter.try(:attributes)&.include?(attribute) &&
43
+ callback.filter.kind == :uniqueness
44
+
45
+ callback.filter.attributes.delete(attribute)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir["#{File.dirname(__FILE__)}/../factories/**"].each do |f|
4
+ require File.expand_path(f)
5
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusActAsTenant
4
+ module Utils
5
+ class TenantSelector
6
+ MESSAGES = {
7
+ available: "Available tenants: %<tenants>s",
8
+ prompt: "Select tenant: ",
9
+ not_found: "Tenant not found in list '%<tenants>s'",
10
+ current: "You are now Tenant '%<name>s'"
11
+ }.freeze
12
+
13
+ def ask
14
+ return if tenants.empty?
15
+
16
+ puts format(MESSAGES[:available], tenants: tenants) # rubocop:disable Rails/Output
17
+ print MESSAGES[:prompt] # rubocop:disable Rails/Output
18
+
19
+ tenant_name = ENV["DEFAULT_TENANT"] || gets.strip
20
+ switch_tenant!(tenant_name) unless tenant_name.empty?
21
+ end
22
+
23
+ def tenants
24
+ @tenants ||= fetch_tenants
25
+ end
26
+
27
+ def switch_tenant!(tenant_name)
28
+ if exists?(tenant_name)
29
+ switch(tenant_name)
30
+ elsif numeric_tenant?(tenant_name)
31
+ switch(tenants[tenant_name.to_i])
32
+ else
33
+ puts format(MESSAGES[:not_found], tenants: tenants) # rubocop:disable Rails/Output
34
+ return false
35
+ end
36
+
37
+ puts format(MESSAGES[:current], name: current) # rubocop:disable Rails/Output
38
+ true
39
+ end
40
+
41
+ def current
42
+ ActsAsTenant.current_tenant&.name
43
+ end
44
+
45
+ private
46
+
47
+ def fetch_tenants
48
+ [*tenant_names].uniq
49
+ .each_with_index
50
+ .to_h { |name, index| [index, name] }
51
+ end
52
+
53
+ def tenant_names
54
+ @tenant_names ||= ::Spree::Tenant.pluck(:name).sort
55
+ end
56
+
57
+ def switch(tenant_name)
58
+ return false unless tenants.value?(tenant_name)
59
+
60
+ tenant = ::Spree::Tenant.find_by(name: tenant_name)
61
+ ActsAsTenant.current_tenant = tenant
62
+ true
63
+ end
64
+
65
+ def exists?(tenant_name)
66
+ tenant_names.include?(tenant_name)
67
+ end
68
+
69
+ def numeric_tenant?(tenant_name)
70
+ tenant_name =~ /^\d+$/ && tenants.key?(tenant_name.to_i)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusActAsTenant
4
+ VERSION = '0.0.2'
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'acts_as_tenant'
4
+ require 'solidus_act_as_tenant/tenant_aware'
5
+ require 'solidus_act_as_tenant/utils/tenant_selector'
6
+ require 'solidus_act_as_tenant/configuration'
7
+ require 'solidus_act_as_tenant/version'
8
+ require 'solidus_act_as_tenant/engine'
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/solidus_act_as_tenant/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'solidus_act_as_tenant'
7
+ spec.version = SolidusActAsTenant::VERSION
8
+ spec.authors = ['Ikraam Ghoor']
9
+ spec.email = 'consult.ikraam@gmail.com'
10
+
11
+ spec.summary = 'Adds tenant functionality to solidus using the row level acts_as_tenant gem'
12
+ spec.description = 'Adds tenant functionality to solidus using the row level acts_as_tenant gem'
13
+ spec.homepage = 'https://github.com/solidusio-contrib/solidus_act_as_tenant#readme'
14
+ spec.license = 'BSD-3-Clause'
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = 'https://github.com/solidusio-contrib/solidus_act_as_tenant'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/solidusio-contrib/solidus_act_as_tenant/blob/main/CHANGELOG.md'
19
+
20
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5', '< 4')
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ files = Dir.chdir(__dir__) { `git ls-files -z`.split("\x0") }
25
+
26
+ spec.files = files.grep_v(%r{^(test|spec|features)/})
27
+ spec.test_files = files.grep(%r{^(test|spec|features)/})
28
+ spec.bindir = "exe"
29
+ spec.executables = files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency 'acts_as_tenant', '~> 1.0.1'
33
+ spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 5']
34
+ spec.add_dependency 'solidus_support', '~> 0.5'
35
+
36
+ spec.add_development_dependency 'pry'
37
+ spec.add_development_dependency 'solidus_dev_support', '~> 2.9'
38
+ end
@@ -0,0 +1,48 @@
1
+ describe SolidusActAsTenant::TenantAware do
2
+ describe '#setup_tenant_aware_models' do
3
+ let!(:tenant) { Spree::Tenant.find_or_create_by!(name: 'Test') }
4
+ let!(:tenant2) { create(:tenant, name: 'Test2') }
5
+
6
+ SolidusActAsTenant.config.tenant_aware_models.each do |klass, validator_attributes|
7
+ describe "for #{klass}" do
8
+ it 'has a tenant accessor and the current tenant is already set', set_tenant: true do
9
+ expect(klass.constantize.new.tenant).to eq tenant
10
+ end
11
+
12
+ validator_attributes.each do |attribute|
13
+ it "validates uniqueness of #{attribute}", set_tenant: true do
14
+ entry = create(klass.demodulize.underscore.downcase.to_sym, attribute => 'test@test.com')
15
+ duplicate = entry.dup
16
+
17
+ if klass == 'Spree::Product'
18
+ duplicate.master = entry.master
19
+ duplicate.slug = entry.slug
20
+ end
21
+
22
+ duplicate.valid?
23
+
24
+ expect(duplicate.errors[attribute]).to include('has already been taken')
25
+ end
26
+
27
+ it 'allows duplicate values across different tenants' do
28
+ ::ActsAsTenant.current_tenant = tenant
29
+ entry = create(klass.demodulize.underscore.downcase.to_sym, attribute => 'test@test.com',
30
+ tenant: tenant)
31
+ duplicate = entry.dup
32
+
33
+ if klass == 'Spree::Product'
34
+ duplicate.master = entry.master
35
+ duplicate.slug = entry.slug
36
+ end
37
+
38
+ ::ActsAsTenant.current_tenant = tenant2
39
+ duplicate.tenant = tenant2
40
+ duplicate.valid?
41
+
42
+ expect(duplicate.errors[attribute]).to be_empty
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Spree::StoreCredit, set_tenant: true do
4
+ describe '#shipping_category' do
5
+ let(:store_credit) { described_class.new }
6
+
7
+ it 'does not raise an error when #payment_method_id is called' do
8
+ expect { store_credit.payment_method_id }.not_to raise_error
9
+ end
10
+
11
+ it 'returns nil for #payment_method_id' do
12
+ expect(store_credit.payment_method_id).to be_nil
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Spree::Variant, set_tenant: true do
4
+ describe '#shipping_category' do
5
+ let(:variant) { described_class.new }
6
+ let(:shipping_category) { create(:shipping_category) }
7
+ let(:product) { create(:product, shipping_category: shipping_category) }
8
+
9
+ it 'returns nil for shipping_category when not set' do
10
+ expect(variant.shipping_category).to be_nil
11
+ end
12
+
13
+ it 'returns nil for shipping_category_id when not set' do
14
+ expect(variant.shipping_category_id).to be_nil
15
+ end
16
+
17
+ it 'returns the product shipping category when the variant shipping category is nil' do
18
+ variant.product = product
19
+ expect(variant.shipping_category).to eq(product.shipping_category)
20
+ end
21
+
22
+ it 'returns the product shipping category id when the variant shipping category is nil' do
23
+ variant.product = product
24
+ expect(variant.shipping_category_id).to eq(product.shipping_category_id)
25
+ end
26
+
27
+ it 'returns the correct shipping category id when the variant shipping category is set' do
28
+ variant.shipping_category = shipping_category
29
+ expect(variant.shipping_category_id).to eq(shipping_category.id)
30
+ end
31
+
32
+ it 'returns the correct shipping category when the variant shipping category is set' do
33
+ variant.shipping_category = shipping_category
34
+ expect(variant.shipping_category).to eq(shipping_category)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Configure Rails Environment
4
+ ENV['RAILS_ENV'] = 'test'
5
+
6
+ # Run Coverage report
7
+ require 'solidus_dev_support/rspec/coverage'
8
+
9
+ # Create the dummy app if it's still missing.
10
+ dummy_env = "#{__dir__}/dummy/config/environment.rb"
11
+ system 'bin/rake extension:test_app' unless File.exist? dummy_env
12
+ require dummy_env
13
+
14
+ # Requires factories and other useful helpers defined in spree_core.
15
+ require 'solidus_dev_support/rspec/feature_helper'
16
+
17
+ # Requires supporting ruby files with custom matchers and macros, etc,
18
+ # in spec/support/ and its subdirectories.
19
+ Dir["#{__dir__}/support/**/*.rb"].sort.each { |f| require f }
20
+
21
+ # Requires factories defined in Solidus core and this extension.
22
+ # See: lib/solidus_act_as_tenant/testing_support/factories.rb
23
+ SolidusDevSupport::TestingSupport::Factories.load_for(SolidusActAsTenant::Engine)
24
+
25
+ RSpec.configure do |config|
26
+ config.infer_spec_type_from_file_location!
27
+ config.use_transactional_fixtures = false
28
+
29
+ if Spree.solidus_gem_version < Gem::Version.new('2.11')
30
+ config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pry'
4
+
5
+ RSpec.configure do |config|
6
+ config.before(:each, set_tenant: true) do
7
+ unless ::ActsAsTenant.current_tenant
8
+ ::ActsAsTenant.current_tenant = Spree::Tenant.find_or_create_by!(name: 'Test')
9
+ end
10
+ end
11
+
12
+ config.before(:suite, set_tenant: true) do
13
+ unless ::ActsAsTenant.current_tenant
14
+ ::ActsAsTenant.current_tenant = Spree::Tenant.find_or_create_by!(name: 'Test')
15
+ end
16
+ end
17
+
18
+ config.after do
19
+ ::ActsAsTenant.current_tenant = nil
20
+ end
21
+ end