solidus_acts_as_tenant 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +1 -0
- data/.github/workflows/lint.yml +25 -0
- data/.github/workflows/test.yml +71 -0
- data/.github_changelog_generator +2 -0
- data/.gitignore +21 -0
- data/.rspec +2 -0
- data/.rubocop.yml +24 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +51 -0
- data/LICENSE +26 -0
- data/README.md +99 -0
- data/Rakefile +7 -0
- data/app/decorators/solidus_acts_as_tenant/store_credit_decorator.rb +12 -0
- data/app/decorators/solidus_acts_as_tenant/variant_decorator.rb +31 -0
- data/app/models/spree/products_taxon.rb +9 -0
- data/app/models/spree/reimbursement_credit.rb +9 -0
- data/app/models/spree/tenant.rb +11 -0
- data/bin/console +17 -0
- data/bin/rails +7 -0
- data/bin/rails-engine +13 -0
- data/bin/rails-sandbox +16 -0
- data/bin/rake +7 -0
- data/bin/sandbox +77 -0
- data/bin/setup +8 -0
- data/config/locales/en.yml +4 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20241204043609_add_tenant_id_to_solidus_tables.rb +103 -0
- data/db/migrate/20241204055845_update_spree_unique_indexes_with_tenant_scope.rb +21 -0
- data/db/migrate/20241204105318_create_spree_tenants.rb +16 -0
- data/lib/generators/solidus_acts_as_tenant/install/install_generator.rb +36 -0
- data/lib/generators/solidus_acts_as_tenant/install/templates/initializer.rb +15 -0
- data/lib/generators/solidus_acts_as_tenant/install/templates/tenant_aware_models.yml +98 -0
- data/lib/solidus_acts_as_tenant/configuration.rb +32 -0
- data/lib/solidus_acts_as_tenant/engine.rb +23 -0
- data/lib/solidus_acts_as_tenant/factories/preference_factory.rb +7 -0
- data/lib/solidus_acts_as_tenant/factories/tenant_factory.rb +9 -0
- data/lib/solidus_acts_as_tenant/tenant_aware.rb +51 -0
- data/lib/solidus_acts_as_tenant/testing_support/factories.rb +5 -0
- data/lib/solidus_acts_as_tenant/utils/tenant_selector.rb +74 -0
- data/lib/solidus_acts_as_tenant/version.rb +5 -0
- data/lib/solidus_acts_as_tenant.rb +8 -0
- data/solidus_acts_as_tenant.gemspec +38 -0
- data/spec/lib/solidus_acts_as_tenant/configuration_spec.rb +43 -0
- data/spec/lib/solidus_acts_as_tenant/solidus_acts_as_tenant_spec.rb +27 -0
- data/spec/lib/solidus_acts_as_tenant/tenant_aware_spec.rb +48 -0
- data/spec/models/spree/store_credit_spec.rb +15 -0
- data/spec/models/spree/variant_spec.rb +37 -0
- data/spec/spec_helper.rb +34 -0
- data/spec/support/config.rb +23 -0
- metadata +179 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c67f9e35b620f97b3a738708559055f85d92ac6b43591779aa50f6cf43eb4d76
|
4
|
+
data.tar.gz: 0c4a3960d9d2a8e9fe7800638a88be038ee08f4ba9aaf10b86b532941d733e82
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f63e4c205f38a72b8158e93842dea657703fd762f8fc9780e13463e4f97cfebcf25df664c565481e7fe4b59901b84c02b50811fb405e7441d78d6937cf08b26
|
7
|
+
data.tar.gz: 3939842985001922147fa66e81b080144db9a57270bbace73fcc94308a7802546cd8286efc2fa3abb8bdc8f30c3e9167d08685177a35e957f8dbfd0cfe0668d8
|
data/.gem_release.yml
ADDED
data/.github/stale.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
_extends: .github
|
@@ -0,0 +1,25 @@
|
|
1
|
+
name: Lint
|
2
|
+
|
3
|
+
on: [pull_request]
|
4
|
+
|
5
|
+
concurrency:
|
6
|
+
group: lint-${{ github.ref_name }}
|
7
|
+
cancel-in-progress: ${{ github.ref_name != 'main' }}
|
8
|
+
|
9
|
+
permissions:
|
10
|
+
contents: read
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
ruby:
|
14
|
+
name: Check Ruby
|
15
|
+
runs-on: ubuntu-24.04
|
16
|
+
steps:
|
17
|
+
- name: Checkout code
|
18
|
+
uses: actions/checkout@v3
|
19
|
+
- name: Install Ruby and gems
|
20
|
+
uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: "3.2"
|
23
|
+
bundler-cache: true
|
24
|
+
- name: Lint Ruby files
|
25
|
+
run: bundle exec rubocop -ESP
|
@@ -0,0 +1,71 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
pull_request:
|
8
|
+
schedule:
|
9
|
+
- cron: "0 0 * * 4" # every Thursday
|
10
|
+
|
11
|
+
concurrency:
|
12
|
+
group: test-${{ github.ref_name }}
|
13
|
+
cancel-in-progress: ${{ github.ref_name != 'main' }}
|
14
|
+
|
15
|
+
permissions:
|
16
|
+
contents: read
|
17
|
+
|
18
|
+
jobs:
|
19
|
+
rspec:
|
20
|
+
name: Solidus ${{ matrix.solidus-branch }}, Rails ${{ matrix.rails-version }} and Ruby ${{ matrix.ruby-version }} on ${{ matrix.database }}
|
21
|
+
runs-on: ubuntu-24.04
|
22
|
+
strategy:
|
23
|
+
fail-fast: true
|
24
|
+
matrix:
|
25
|
+
rails-version:
|
26
|
+
- "7.0"
|
27
|
+
- "7.1"
|
28
|
+
- "7.2"
|
29
|
+
ruby-version:
|
30
|
+
- "3.1"
|
31
|
+
- "3.4"
|
32
|
+
solidus-branch:
|
33
|
+
- "v4.1"
|
34
|
+
- "v4.2"
|
35
|
+
- "v4.3"
|
36
|
+
- "v4.4"
|
37
|
+
- "v4.5"
|
38
|
+
database:
|
39
|
+
- "postgresql"
|
40
|
+
- "mysql"
|
41
|
+
- "sqlite"
|
42
|
+
exclude:
|
43
|
+
- rails-version: "7.2"
|
44
|
+
solidus-branch: "v4.3"
|
45
|
+
- rails-version: "7.2"
|
46
|
+
solidus-branch: "v4.2"
|
47
|
+
- rails-version: "7.2"
|
48
|
+
solidus-branch: "v4.1"
|
49
|
+
- rails-version: "7.1"
|
50
|
+
solidus-branch: "v4.2"
|
51
|
+
- rails-version: "7.1"
|
52
|
+
solidus-branch: "v4.1"
|
53
|
+
- ruby-version: "3.4"
|
54
|
+
rails-version: "7.0"
|
55
|
+
env:
|
56
|
+
CODECOV_COVERAGE_PATH: ./coverage/coverage.xml
|
57
|
+
steps:
|
58
|
+
- uses: actions/checkout@v4
|
59
|
+
- name: Run extension tests
|
60
|
+
uses: solidusio/test-solidus-extension@main
|
61
|
+
with:
|
62
|
+
database: ${{ matrix.database }}
|
63
|
+
rails-version: ${{ matrix.rails-version }}
|
64
|
+
ruby-version: ${{ matrix.ruby-version }}
|
65
|
+
solidus-branch: ${{ matrix.solidus-branch }}
|
66
|
+
- name: Upload coverage reports to Codecov
|
67
|
+
uses: codecov/codecov-action@v5
|
68
|
+
continue-on-error: true
|
69
|
+
with:
|
70
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
71
|
+
files: ${{ env.CODECOV_COVERAGE_PATH }}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require:
|
2
|
+
- solidus_dev_support/rubocop
|
3
|
+
|
4
|
+
FactoryBot/CreateList:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
FactoryBot/AssociationStyle:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
FactoryBot/FactoryNameStyle:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
FactoryBot/ConsistentParenthesesStyle:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Capybara/RSpec/PredicateMatcher:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Gemspec/RequiredRubyVersion:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
AllCops:
|
23
|
+
NewCops: disable
|
24
|
+
TargetRubyVersion: 3.2 # Matching the .github/workflow/lint.yml ruby version
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
5
|
+
|
6
|
+
branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
|
7
|
+
gem 'solidus', github: 'solidusio/solidus', branch: branch
|
8
|
+
|
9
|
+
# The solidus_frontend gem has been pulled out since v3.2
|
10
|
+
if branch >= 'v3.2'
|
11
|
+
gem 'solidus_frontend'
|
12
|
+
elsif branch == 'main'
|
13
|
+
gem 'solidus_frontend', github: 'solidusio/solidus_frontend'
|
14
|
+
else
|
15
|
+
gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch
|
16
|
+
end
|
17
|
+
|
18
|
+
rails_version = ENV.fetch('RAILS_VERSION', '7.0')
|
19
|
+
gem 'rails', "~> #{rails_version}"
|
20
|
+
|
21
|
+
case ENV.fetch('DB', nil)
|
22
|
+
when 'mysql'
|
23
|
+
gem 'mysql2'
|
24
|
+
when 'postgresql'
|
25
|
+
gem 'pg'
|
26
|
+
else
|
27
|
+
gem 'sqlite3', rails_version < '7.2' ? '~> 1.4' : '~> 2.0'
|
28
|
+
end
|
29
|
+
|
30
|
+
if rails_version == '7.0'
|
31
|
+
gem 'concurrent-ruby', '< 1.3.5'
|
32
|
+
end
|
33
|
+
|
34
|
+
if RUBY_VERSION >= '3.4'
|
35
|
+
# Solidus Promotions uses CSV but does not have it as dependency yet.
|
36
|
+
gem 'csv'
|
37
|
+
end
|
38
|
+
|
39
|
+
# While we still support Ruby < 3 we need to workaround a limitation in
|
40
|
+
# the 'async' gem that relies on the latest ruby, since RubyGems doesn't
|
41
|
+
# resolve gems based on the required ruby version.
|
42
|
+
gem 'async', '< 3' if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
|
43
|
+
|
44
|
+
gemspec
|
45
|
+
|
46
|
+
# Use a local Gemfile to include development dependencies that might not be
|
47
|
+
# relevant for the project or for other contributors, e.g. pry-byebug.
|
48
|
+
#
|
49
|
+
# We use `send` instead of calling `eval_gemfile` to work around an issue with
|
50
|
+
# how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
|
51
|
+
send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local'
|
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2024 Solidus Contrib
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
* Neither the name Solidus nor the names of its contributors may be used to
|
13
|
+
endorse or promote products derived from this software without specific
|
14
|
+
prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Solidus Acts As Tenant
|
2
|
+
|
3
|
+
[](https://codecov.io/gh/nebulab/solidus_acts_as_tenant)
|
4
|
+
|
5
|
+
|
6
|
+
This extension adds multi-tenant support to solidus using the row-level tenancy [acts_as_tenant](https://github.com/ErwinM/acts_as_tenant/commits/master/) gem.
|
7
|
+
|
8
|
+
It adds tenant scoping to a configurabale set of models and adds a console utility to switch between tenants.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add solidus_acts_as_tenant to your Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'solidus_acts_as_tenant'
|
16
|
+
```
|
17
|
+
|
18
|
+
Bundle your dependencies and run the installation generator:
|
19
|
+
|
20
|
+
```shell
|
21
|
+
bin/rails generate solidus_acts_as_tenant:install
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
See the [acts_as_tenant](https://github.com/ErwinM/acts_as_tenant) gem for an explanation of how tenant scoping works.
|
27
|
+
|
28
|
+
To configure this extension for your project, see:
|
29
|
+
|
30
|
+
- The generated migration files
|
31
|
+
- The generated tenant_aware_models.yml file
|
32
|
+
- The generated initializer.rb file
|
33
|
+
|
34
|
+
|
35
|
+
There is also a console utility that can be used to simply manage tenants in the console.
|
36
|
+
To use it, you can add it to your `~/.irbrc` file or `~/.pryrc` file:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
if defined?(Rails)
|
40
|
+
TS = SolidusActsAsTenant::Utils::TenantSelector.new
|
41
|
+
|
42
|
+
IRB.conf[:IRB_RC] = proc do
|
43
|
+
# * TS.ask => anytime in console, to switch tenant from a list
|
44
|
+
# * TS.current => same as Apartment::Tenant.current
|
45
|
+
# * TS.tenants => hash of tenants. Example: { 0 => "Demo Company" }
|
46
|
+
# * TS.switch_tenant!(tenant_name) => same as ActsAsTenant.current_tenant = Tenant.find_by(name: tenant_name)
|
47
|
+
TS.ask
|
48
|
+
end
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
### Testing the extension
|
55
|
+
|
56
|
+
First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy
|
57
|
+
app if it does not exist, then it will run specs. The dummy app can be regenerated by using
|
58
|
+
`bin/rake extension:test_app`.
|
59
|
+
|
60
|
+
```shell
|
61
|
+
bin/rake
|
62
|
+
```
|
63
|
+
|
64
|
+
To run [Rubocop](https://github.com/bbatsov/rubocop) static code analysis run
|
65
|
+
|
66
|
+
```shell
|
67
|
+
bundle exec rubocop
|
68
|
+
```
|
69
|
+
|
70
|
+
When testing your application's integration with this extension you may use its factories.
|
71
|
+
You can load Solidus core factories along with this extension's factories using this statement:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
SolidusDevSupport::TestingSupport::Factories.load_for(SolidusActsAsTenant::Engine)
|
75
|
+
```
|
76
|
+
|
77
|
+
### Running the sandbox
|
78
|
+
|
79
|
+
To run this extension in a sandboxed Solidus application, you can run `bin/sandbox`. The path for
|
80
|
+
the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands to
|
81
|
+
`sandbox/bin/rails`.
|
82
|
+
|
83
|
+
Here's an example:
|
84
|
+
|
85
|
+
```
|
86
|
+
$ bin/rails server
|
87
|
+
=> Booting Puma
|
88
|
+
=> Rails 6.0.2.1 application starting in development
|
89
|
+
* Listening on tcp://127.0.0.1:3000
|
90
|
+
Use Ctrl-C to stop
|
91
|
+
```
|
92
|
+
|
93
|
+
### Releasing new versions
|
94
|
+
|
95
|
+
Please refer to the [dedicated page](https://github.com/solidusio/solidus/wiki/How-to-release-extensions) in the Solidus wiki.
|
96
|
+
|
97
|
+
## License
|
98
|
+
|
99
|
+
Copyright (c) 2024 Solidus Contrib, released under the New BSD License.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusActsAsTenant::StoreCreditDecorator # rubocop:disable Style/ClassAndModuleChildren
|
4
|
+
# Fixes no method error related to validations added through acts_as_tenant
|
5
|
+
def payment_method_id
|
6
|
+
return if payment_method.nil?
|
7
|
+
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
::Spree::StoreCredit.prepend(self)
|
12
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusActsAsTenant::VariantDecorator # rubocop:disable Style/ClassAndModuleChildren
|
4
|
+
# Fixes errors related to validations added through acts_as_tenant
|
5
|
+
|
6
|
+
def product_shipping_category_id
|
7
|
+
return if product.nil?
|
8
|
+
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def product_shipping_category
|
13
|
+
return if product.nil?
|
14
|
+
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def product_tax_category_id
|
19
|
+
return if product.nil?
|
20
|
+
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def product_tax_category
|
25
|
+
return if product.nil?
|
26
|
+
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
::Spree::Variant.prepend(self)
|
31
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
class Tenant < Spree::Base
|
5
|
+
if SolidusActsAsTenant.config.class_name == 'Spree::Tenant'
|
6
|
+
validates :name, presence: true, uniqueness: true
|
7
|
+
validates :subdomain, uniqueness: true
|
8
|
+
validates :domain, uniqueness: true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require "bundler/setup"
|
6
|
+
require "solidus_acts_as_tenant"
|
7
|
+
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
10
|
+
$LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
|
11
|
+
|
12
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
13
|
+
# require "pry"
|
14
|
+
# Pry.start
|
15
|
+
|
16
|
+
require "irb"
|
17
|
+
IRB.start(__FILE__)
|
data/bin/rails
ADDED
data/bin/rails-engine
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/solidus_acts_as_tenant/engine', __dir__)
|
7
|
+
|
8
|
+
# Set up gems listed in the Gemfile.
|
9
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
10
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
11
|
+
|
12
|
+
require 'rails/all'
|
13
|
+
require 'rails/engine/commands'
|
data/bin/rails-sandbox
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
app_root = 'sandbox'
|
4
|
+
|
5
|
+
unless File.exist? "#{app_root}/bin/rails"
|
6
|
+
warn 'Creating the sandbox app...'
|
7
|
+
Dir.chdir "#{__dir__}/.." do
|
8
|
+
system "#{__dir__}/sandbox" or begin
|
9
|
+
warn 'Automatic creation of the sandbox app failed'
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Dir.chdir app_root
|
16
|
+
exec 'bin/rails', *ARGV
|
data/bin/rake
ADDED
data/bin/sandbox
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
test -z "${DEBUG+empty_string}" || set -x
|
5
|
+
|
6
|
+
test "$DB" = "sqlite" && export DB="sqlite3"
|
7
|
+
|
8
|
+
if [ -z "$PAYMENT_METHOD" ]
|
9
|
+
then
|
10
|
+
PAYMENT_METHOD="none"
|
11
|
+
fi
|
12
|
+
|
13
|
+
if [ -z "$SOLIDUS_BRANCH" ]
|
14
|
+
then
|
15
|
+
echo "~~> Use 'export SOLIDUS_BRANCH=[main|v4.0|...]' to control the Solidus branch"
|
16
|
+
SOLIDUS_BRANCH="main"
|
17
|
+
fi
|
18
|
+
echo "~~> Using branch $SOLIDUS_BRANCH of solidus"
|
19
|
+
|
20
|
+
extension_name="solidus_acts_as_tenant"
|
21
|
+
|
22
|
+
# Stay away from the bundler env of the containing extension.
|
23
|
+
function unbundled {
|
24
|
+
ruby -rbundler -e'
|
25
|
+
Bundler.with_unbundled_env {system *ARGV}' -- \
|
26
|
+
env BUNDLE_SUPPRESS_INSTALL_USING_MESSAGES=true $@
|
27
|
+
}
|
28
|
+
|
29
|
+
echo "~~~> Removing the old sandbox"
|
30
|
+
rm -rf ./sandbox
|
31
|
+
|
32
|
+
echo "~~~> Creating a pristine Rails app"
|
33
|
+
rails_version=`bundle exec ruby -e'require "rails"; puts Rails.version'`
|
34
|
+
rails _${rails_version}_ new sandbox \
|
35
|
+
--database="${DB:-sqlite3}" \
|
36
|
+
--skip-git \
|
37
|
+
--skip-keeps \
|
38
|
+
--skip-rc \
|
39
|
+
--skip-bootsnap \
|
40
|
+
--skip-test
|
41
|
+
|
42
|
+
if [ ! -d "sandbox" ]; then
|
43
|
+
echo 'sandbox rails application failed'
|
44
|
+
exit 1
|
45
|
+
fi
|
46
|
+
|
47
|
+
echo "~~~> Adding solidus (with i18n) to the Gemfile"
|
48
|
+
cd ./sandbox
|
49
|
+
cat <<RUBY >> Gemfile
|
50
|
+
gem 'solidus', github: 'solidusio/solidus', branch: '$SOLIDUS_BRANCH'
|
51
|
+
gem 'rails-i18n'
|
52
|
+
gem 'solidus_i18n'
|
53
|
+
gem 'solidus_auth_devise'
|
54
|
+
|
55
|
+
gem '$extension_name', path: '..'
|
56
|
+
|
57
|
+
group :test, :development do
|
58
|
+
platforms :mri do
|
59
|
+
gem 'pry-byebug'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
RUBY
|
63
|
+
|
64
|
+
unbundled bundle install --gemfile Gemfile
|
65
|
+
|
66
|
+
unbundled bundle exec rake db:drop db:create
|
67
|
+
|
68
|
+
unbundled bundle exec rails generate solidus:install \
|
69
|
+
--auto-accept \
|
70
|
+
$@
|
71
|
+
|
72
|
+
unbundled bundle exec rails generate solidus:auth:install --auto-run-migrations
|
73
|
+
unbundled bundle exec rails generate ${extension_name}:install --auto-run-migrations
|
74
|
+
|
75
|
+
echo
|
76
|
+
echo "🚀 Sandbox app successfully created for $extension_name!"
|
77
|
+
echo "🧪 This app is intended for test purposes."
|
data/bin/setup
ADDED