shopping_mall 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -37
- data/Rakefile +3 -3
- data/app/models/spree/image_decorator.rb +10 -0
- data/app/models/spree/preferences/scoped_store_decorator.rb +11 -0
- data/app/models/spree/tenant.rb +5 -0
- data/config/initializers/apartment.rb +4 -0
- data/db/migrate/20150901171448_create_spree_tenants.rb +11 -0
- data/lib/generators/shopping_mall/install_generator.rb +13 -19
- data/lib/generators/templates/shopping_mall.rb +64 -20
- data/lib/shopping_mall.rb +4 -38
- data/lib/shopping_mall/engine.rb +4 -0
- data/lib/shopping_mall/version.rb +1 -1
- data/lib/tasks/tenant.rake +14 -8
- data/spec/fixtures/test_cat.jpg +0 -0
- data/spec/models/spree/image_decorator_spec.rb +52 -0
- data/spec/models/spree/preferences/scoped_store_decorator_spec.rb +24 -0
- data/spec/models/spree/tenant_spec.rb +5 -0
- data/spec/models/spree/user_decorator_spec.rb +0 -4
- data/spec/models/spree/zone_decorator_spec.rb +2 -5
- data/spec/shopping_mall/config_spec.rb +2 -62
- metadata +19 -12
- data/config/initializers/shopping_mall_initializer.rb +0 -3
- data/lib/shopping_mall/escalator.rb +0 -20
- data/spec/features/tenancy_spec.rb +0 -14
- data/spec/shopping_mall/escalator_spec.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0ad2598552cdb31ca7f85e6b31fa4b18a3d3b31
|
4
|
+
data.tar.gz: 72a0b2f17f213b8fa45032d2dea3e2db42f8def5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78714d6525a692a6fb6d639878144928cbcfe56ac1fbceebb8c3fc4c1e6371715b11fb3e6b741d102f5ba84972b526c6afc4e30b6cce3a74a29a84a1ad9302eb
|
7
|
+
data.tar.gz: 86aeab513d2a58c90128e4885ce5d47239aeceab3795da663852e2404badfad4fa6b96ef0fa8f8b8cd66f6b5f5dd1d3a16e30a04a9327760051d96a25798d13f
|
data/README.md
CHANGED
@@ -22,29 +22,21 @@ After installing ShoppingMall, run the generator:
|
|
22
22
|
|
23
23
|
rails generate shopping_mall:install
|
24
24
|
|
25
|
-
This will adds a `shopping_mall.rb` initializer to your app, and adds the following to your
|
25
|
+
This will adds a `shopping_mall.rb` initializer to your app, and adds the following to your production and development environment:
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
|
29
|
-
|
30
|
-
'ShoppingMall::
|
31
|
-
|
28
|
+
Rails.application.configure do |config|
|
29
|
+
...
|
30
|
+
'config.cache_store = :memory_store, { namespace: -> { ShoppingMall::Store.current } }'
|
31
|
+
...
|
32
|
+
end
|
32
33
|
```
|
33
34
|
|
34
|
-
|
35
|
+
## Configuration
|
35
36
|
|
37
|
+
Some sane defaults have been added for auto tracking of Tenants for migrations and seeds. `ShoppingMall.configure` is just a pass-thru so anything that is available to `Apartment` can be passed here
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
The following config options should be set up in the `shopping_mall.rb` initializer:
|
40
|
-
|
41
|
-
#### Escalators
|
42
|
-
|
43
|
-
Escalators are thinly wrapped Apartment::Elevators, the current escalators available are: `Subdomain`, `Domain`, and `FirstSubdomain`. The default escalator is `Subdomain`.
|
44
|
-
|
45
|
-
```ruby
|
46
|
-
config.escalator = 'Subdomain'
|
47
|
-
```
|
39
|
+
Check here: https://github.com/influitive/apartment for configuration options
|
48
40
|
|
49
41
|
#### Excluding Models
|
50
42
|
|
@@ -54,30 +46,14 @@ If you have some models that should always access the `public` (global) tenant,
|
|
54
46
|
config.excluded_models = ["Spree::User", ...] # these models will not be multi-tenanted, but remain in the global (public) namespace
|
55
47
|
```
|
56
48
|
|
57
|
-
Out of the box ShoppingMall has the following Spree
|
58
|
-
|
59
|
-
```ruby
|
60
|
-
[
|
61
|
-
'Spree::Country',
|
62
|
-
'Spree::Property',
|
63
|
-
'Spree::Prototype',
|
64
|
-
'Spree::Role',
|
65
|
-
'Spree::RolesUser',
|
66
|
-
'Spree::State',
|
67
|
-
'Spree::TaxRate',
|
68
|
-
'Spree::Tracker',
|
69
|
-
'Spree::User',
|
70
|
-
'Spree::Zone',
|
71
|
-
'Spree::ZoneMember'
|
72
|
-
]
|
73
|
-
```
|
49
|
+
Out of the box ShoppingMall has the following Spree model excluded: `Spree::Tenant`
|
74
50
|
|
75
|
-
> NOTE: Rails will always access the `public` tenant when accessing
|
51
|
+
> NOTE: Rails will always access the `public` tenant when accessing excluded models, but note that tables will be created in all schemas. This may not be ideal, but its done this way because otherwise rails wouldn't be able to properly generate the `schema.rb` file.
|
76
52
|
|
77
53
|
|
78
54
|
## Create Tenant (Rake Task)
|
79
55
|
|
80
|
-
The tenant name will change depending on the
|
56
|
+
The tenant name will change depending on the elevator you are using. See the [Apartment Elevators](https://github.com/influitive/apartment#switching-tenants-per-request) section for more information.
|
81
57
|
|
82
58
|
rake tenant:create['tenant_name_here']
|
83
59
|
|
@@ -85,7 +61,7 @@ If the tenant already exists, it will *not* be overwritten. It will need to be *
|
|
85
61
|
|
86
62
|
#### Subdomain
|
87
63
|
|
88
|
-
This
|
64
|
+
This elevator will use the entire subdomain, including nested subdomains. If your domain is `foo.example.com`, the rake task you would need to run is:
|
89
65
|
|
90
66
|
rake tenant:create['foo']
|
91
67
|
|
data/Rakefile
CHANGED
@@ -2,15 +2,15 @@ require 'bundler'
|
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
3
|
|
4
4
|
require 'rspec/core/rake_task'
|
5
|
-
require 'spree/testing_support/
|
5
|
+
require 'spree/testing_support/common_rake'
|
6
6
|
|
7
7
|
RSpec::Core::RakeTask.new
|
8
8
|
|
9
|
-
task :
|
9
|
+
task default: :spec
|
10
10
|
|
11
11
|
desc 'Generates a dummy app for testing'
|
12
12
|
task :test_app do
|
13
13
|
ENV['LIB_NAME'] = 'shopping_mall'
|
14
14
|
ENV['DB'] = 'postgres'
|
15
|
-
Rake::Task[
|
15
|
+
Rake::Task['common:test_app'].invoke
|
16
16
|
end
|
@@ -5,25 +5,6 @@ module ShoppingMall
|
|
5
5
|
|
6
6
|
source_root File.expand_path('../../templates', __FILE__)
|
7
7
|
|
8
|
-
desc 'Creates initializer and inserts middleware'
|
9
|
-
|
10
|
-
def copy_initializer
|
11
|
-
template 'shopping_mall.rb', 'config/initializers/shopping_mall.rb'
|
12
|
-
end
|
13
|
-
|
14
|
-
def copy_middleware
|
15
|
-
application do
|
16
|
-
<<-STR
|
17
|
-
|
18
|
-
# Inserted with shopping_mall:install
|
19
|
-
config.middleware.insert_before(
|
20
|
-
'ActiveRecord::ConnectionAdapters::ConnectionManagement',
|
21
|
-
'ShoppingMall::Escalator'
|
22
|
-
)
|
23
|
-
STR
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
8
|
def add_migrations
|
28
9
|
run 'bundle exec rake railties:install:migrations FROM=shopping_mall'
|
29
10
|
end
|
@@ -31,6 +12,19 @@ module ShoppingMall
|
|
31
12
|
def run_migrations
|
32
13
|
run 'bundle exec rake db:migrate'
|
33
14
|
end
|
15
|
+
|
16
|
+
desc 'Creates initializer and inserts middleware'
|
17
|
+
def copy_initializer
|
18
|
+
template 'shopping_mall.rb', 'config/initializers/shopping_mall.rb'
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_namespacing_to_cache
|
22
|
+
%w{development production}.each do |env|
|
23
|
+
application(nil, env: env) do
|
24
|
+
'config.cache_store = :memory_store, { namespace: -> { Apartment::Tenant.current } }'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
34
28
|
end
|
35
29
|
end
|
36
30
|
end
|
@@ -1,22 +1,66 @@
|
|
1
1
|
ShoppingMall.configure do |config|
|
2
|
-
#
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
#
|
2
|
+
# Add any models that you do not want to be multi-tenanted, but remain in the global (public) namespace.
|
3
|
+
# A typical example would be a Customer or Tenant model that stores each Tenant's information.
|
4
|
+
#
|
5
|
+
# config.excluded_models = %w{ Tenant }
|
6
|
+
#
|
7
|
+
config.excluded_models = [
|
8
|
+
'Spree::Tenant', # Shared to allow proper migrations and seeding to tenants
|
9
|
+
]
|
10
|
+
|
11
|
+
# In order to migrate all of your Tenants you need to provide a list of Tenant names to Apartment.
|
12
|
+
# You can make this dynamic by providing a Proc object to be called on migrations.
|
13
|
+
# This object should yield an array of strings representing each Tenant name.
|
14
|
+
#
|
15
|
+
# config.tenant_names = lambda{ Customer.pluck(:tenant_name) }
|
16
|
+
# config.tenant_names = ['tenant1', 'tenant2']
|
17
|
+
#
|
18
|
+
# Currently setup to allow auto-magical seeds and migrations, feel free to change.
|
19
|
+
config.tenant_names = -> { Spree::Tenant.pluck(:name) }
|
20
|
+
|
21
|
+
#
|
22
|
+
# ==> PostgreSQL only options
|
23
|
+
|
24
|
+
# Specifies whether to use PostgreSQL schemas or create a new database per Tenant.
|
25
|
+
# The default behaviour is true.
|
26
|
+
#
|
27
|
+
# config.use_schemas = true
|
28
|
+
|
29
|
+
# Apartment can be forced to use raw SQL dumps instead of schema.rb for creating new schemas.
|
30
|
+
# Use this when you are using some extra features in PostgreSQL that can't be respresented in
|
31
|
+
# schema.rb, like materialized views etc. (only applies with use_schemas set to true).
|
32
|
+
# (Note: this option doesn't use db/structure.sql, it creates SQL dump by executing pg_dump)
|
33
|
+
#
|
34
|
+
# config.use_sql = false
|
35
|
+
|
36
|
+
# There are cases where you might want some schemas to always be in your search_path
|
37
|
+
# e.g when using a PostgreSQL extension like hstore.
|
38
|
+
# Any schemas added here will be available along with your selected Tenant.
|
39
|
+
#
|
40
|
+
# config.persistent_schemas = %w{ hstore }
|
41
|
+
|
42
|
+
# <== PostgreSQL only options
|
43
|
+
#
|
44
|
+
|
45
|
+
# By default, and only when not using PostgreSQL schemas, Apartment will prepend the environment
|
46
|
+
# to the tenant name to ensure there is no conflict between your environments.
|
47
|
+
# This is mainly for the benefit of your development and test environments.
|
48
|
+
# Uncomment the line below if you want to disable this behaviour in production.
|
49
|
+
#
|
50
|
+
# config.prepend_environment = !Rails.env.production?
|
51
|
+
end
|
52
|
+
|
53
|
+
# Allows Paperclip to place assets within a tenants scope
|
54
|
+
Paperclip.interpolates :tenant do |attachment, _style|
|
55
|
+
attachment.instance.tenant
|
22
56
|
end
|
57
|
+
|
58
|
+
# Namespace attachments by tenant
|
59
|
+
Spree::Image.attachment_definitions[:attachment][:url] = '/spree/products/:tenant/:id/:style/:basename.:extension'
|
60
|
+
Spree::Image.attachment_definitions[:attachment][:path] = ':rails_root/public/spree/products/:tenant/:id/:style/:basename.:extension'
|
61
|
+
|
62
|
+
# https://github.com/influitive/apartment/issues/134 for more information on this insert_before hack.
|
63
|
+
Rails.application.config.middleware.insert_before(
|
64
|
+
'ActiveRecord::ConnectionAdapters::ConnectionManagement',
|
65
|
+
'Apartment::Elevators::Subdomain'
|
66
|
+
)
|
data/lib/shopping_mall.rb
CHANGED
@@ -1,49 +1,15 @@
|
|
1
1
|
require 'spree_core'
|
2
2
|
require 'apartment'
|
3
|
+
require 'apartment/elevators/generic'
|
3
4
|
require 'apartment/elevators/domain'
|
4
5
|
require 'apartment/elevators/first_subdomain'
|
5
6
|
require 'apartment/elevators/subdomain'
|
6
7
|
require 'shopping_mall/engine'
|
7
|
-
require 'shopping_mall/escalator'
|
8
8
|
|
9
9
|
module ShoppingMall
|
10
|
-
DEFAULT_SPREE_EXCLUSIONS = [
|
11
|
-
'Spree::Country',
|
12
|
-
'Spree::Property',
|
13
|
-
'Spree::Prototype',
|
14
|
-
'Spree::Role',
|
15
|
-
'Spree::RolesUser',
|
16
|
-
'Spree::State',
|
17
|
-
'Spree::TaxRate',
|
18
|
-
'Spree::Tracker',
|
19
|
-
'Spree::User',
|
20
|
-
'Spree::Zone',
|
21
|
-
'Spree::ZoneMember'
|
22
|
-
]
|
23
|
-
|
24
|
-
ESCALATORS = %w(Domain FirstSubdomain Subdomain)
|
25
|
-
|
26
10
|
def self.configure
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
def self.excluded_models
|
31
|
-
Apartment.excluded_models
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.excluded_models=(models)
|
35
|
-
Apartment.configure { |config| config.excluded_models = models }
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.escalator
|
39
|
-
@escalator ||= 'Subdomain'
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.escalator=(escalator)
|
43
|
-
@escalator = escalator
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.escalator_class
|
47
|
-
"Apartment::Elevators::#{escalator}".constantize
|
11
|
+
Apartment.configure do |config|
|
12
|
+
yield config
|
13
|
+
end
|
48
14
|
end
|
49
15
|
end
|
data/lib/shopping_mall/engine.rb
CHANGED
@@ -8,6 +8,10 @@ module ShoppingMall
|
|
8
8
|
config.generators { |gen| gen.test_framework :rspec }
|
9
9
|
|
10
10
|
def self.activate
|
11
|
+
unless defined? Spree::Preferences::StoreInstance
|
12
|
+
Spree::Core::Engine.instance.eager_load!
|
13
|
+
end
|
14
|
+
|
11
15
|
Dir[File.join(__dir__, '../../app/**/*_decorator*.rb')].each do |klass|
|
12
16
|
Rails.application.config.cache_classes ? require(klass) : load(klass)
|
13
17
|
end
|
data/lib/tasks/tenant.rake
CHANGED
@@ -15,12 +15,13 @@ namespace :tenant do
|
|
15
15
|
raise "Tenant `#{tenant}` already exists. Will not overwrite."
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
Spree::Tenant.create name: tenant
|
19
|
+
Apartment::Tenant.create tenant
|
19
20
|
|
20
|
-
puts '
|
21
|
+
puts 'Store created successfully'
|
21
22
|
ENV['RAILS_CACHE_ID'] = tenant
|
22
23
|
|
23
|
-
Apartment::Tenant.
|
24
|
+
Apartment::Tenant.switch(tenant) do
|
24
25
|
# Hack the current method so we're able to return a gateway
|
25
26
|
# without a RAILS_ENV
|
26
27
|
Spree::Gateway.class_eval do
|
@@ -28,6 +29,8 @@ namespace :tenant do
|
|
28
29
|
Spree::Gateway::Bogus.new
|
29
30
|
end
|
30
31
|
end
|
32
|
+
|
33
|
+
Rake::Task['db:seed'].invoke
|
31
34
|
end
|
32
35
|
end
|
33
36
|
|
@@ -44,7 +47,10 @@ namespace :tenant do
|
|
44
47
|
data in the future unless backups are available. Are you sure you
|
45
48
|
wish to continue? [Y/n]', true)
|
46
49
|
begin
|
47
|
-
|
50
|
+
spree_tenant = Spree::Tenant.find_by name: tenant
|
51
|
+
spree_tenant.destroy if spree_tenant
|
52
|
+
|
53
|
+
Apartment::Tenant.drop(tenant)
|
48
54
|
puts "Tenant `#{tenant}` has been dropped. It is no longer available."
|
49
55
|
rescue => err
|
50
56
|
raise err
|
@@ -56,10 +62,10 @@ namespace :tenant do
|
|
56
62
|
|
57
63
|
# Check is schema is currently in use
|
58
64
|
def schema_in_use?(tenant)
|
59
|
-
schema = ActiveRecord::Base.connection
|
60
|
-
|
61
|
-
|
62
|
-
|
65
|
+
schema = ActiveRecord::Base.connection.
|
66
|
+
execute("SELECT schema_name
|
67
|
+
FROM information_schema.schemata
|
68
|
+
WHERE schema_name = '#{tenant}'")
|
63
69
|
schema.ntuples > 0
|
64
70
|
end
|
65
71
|
end
|
Binary file
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Image do
|
4
|
+
describe '.tenant_proc' do
|
5
|
+
it 'returns ShoppingMall::Store#current' do
|
6
|
+
expect(described_class.tenant_proc.call).to eq Apartment::Tenant.current
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#tenant' do
|
11
|
+
before do
|
12
|
+
%w(tenant1 tenant2).each do |name|
|
13
|
+
Apartment::Tenant.create name
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with different tenants' do
|
18
|
+
it 'returns ShoppingMall::Store#current' do
|
19
|
+
Apartment::Tenant.switch! 'tenant1'
|
20
|
+
expect(subject.tenant).to eq 'tenant1'
|
21
|
+
|
22
|
+
Apartment::Tenant.switch! 'tenant2'
|
23
|
+
expect(subject.tenant).to eq 'tenant2'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'tenant directory within image path' do
|
29
|
+
before do
|
30
|
+
Apartment::Tenant.create 'tenant1'
|
31
|
+
|
32
|
+
Paperclip.interpolates :tenant do |attachment, _style|
|
33
|
+
attachment.instance.tenant
|
34
|
+
end
|
35
|
+
Spree::Image.attachment_definitions[:attachment][:url] =
|
36
|
+
'/spree/products/:tenant/:id/:style/:basename.:extension'
|
37
|
+
Spree::Image.attachment_definitions[:attachment][:path] =
|
38
|
+
':rails_root/public/spree/products/:tenant/:id/:style/:basename.:extension'
|
39
|
+
|
40
|
+
Apartment::Tenant.switch! 'tenant1'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'uses current tenant' do
|
44
|
+
subject.attachment = Rack::Test::UploadedFile.new(
|
45
|
+
'spec/fixtures/test_cat.jpg'
|
46
|
+
)
|
47
|
+
|
48
|
+
expect(subject.attachment.url(:original)).
|
49
|
+
to start_with "/spree/products/tenant1//original/test_cat.jpg"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Preferences::ScopedStore do
|
4
|
+
before do
|
5
|
+
Apartment::Tenant.create('tenant_name1')
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#fetch' do
|
9
|
+
it 'appends current tenant to RAILS_CACHE_ID' do
|
10
|
+
ENV['RAILS_CACHE_ID'] = 'cache_id'
|
11
|
+
fake_instance = double('FakeStoreInstance', fetch: true)
|
12
|
+
allow(Spree::Preferences::Store).to receive(:instance) { fake_instance }
|
13
|
+
|
14
|
+
Apartment::Tenant.switch!('tenant_name1')
|
15
|
+
|
16
|
+
scoped_store = described_class.new('prefix')
|
17
|
+
|
18
|
+
scoped_store.fetch('neat')
|
19
|
+
|
20
|
+
expect(fake_instance).to have_received(:fetch).
|
21
|
+
with 'cache_idtenant_name1/prefix/neat'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -3,10 +3,6 @@ require 'spec_helper'
|
|
3
3
|
describe Spree::User do
|
4
4
|
it { should have_many(:roles).through(:roles_users) }
|
5
5
|
|
6
|
-
it 'is on default_schema' do
|
7
|
-
expect(Spree::User.table_name).to eq 'public.spree_users'
|
8
|
-
end
|
9
|
-
|
10
6
|
context 'has_many through sanity check' do
|
11
7
|
it 'associates correctly' do
|
12
8
|
user = create :user, roles: [create(:role)]
|
@@ -10,13 +10,10 @@ describe Spree::Zone do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
describe '#match' do
|
14
14
|
let(:country_zone) { create(:zone, name: 'CountryZone') }
|
15
15
|
let(:country) do
|
16
|
-
country
|
17
|
-
# Create at least one state for this country
|
18
|
-
state = create(:state, country: country)
|
19
|
-
country
|
16
|
+
create(:country, states: [create(:state)])
|
20
17
|
end
|
21
18
|
|
22
19
|
before { country_zone.members.create(zoneable: country) }
|
@@ -1,71 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ShoppingMall do
|
4
|
-
let(:exclusions) { ['Spree::User'] }
|
5
|
-
|
6
4
|
context '#configure' do
|
7
|
-
it '
|
8
|
-
expect(ShoppingMall.excluded_models).to eq(
|
9
|
-
ShoppingMall::DEFAULT_SPREE_EXCLUSIONS
|
10
|
-
)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'excluded_models is a pass-through to Apartment' do
|
14
|
-
ShoppingMall.excluded_models = exclusions
|
15
|
-
expect(Apartment.excluded_models).to eq exclusions
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'has default escalator of `Subdomain` on initialize' do
|
19
|
-
expect(ShoppingMall.escalator).to eq 'Subdomain'
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'has default escalator_class of `"Apartment::Elevators::Subdomain`' do
|
23
|
-
expect(ShoppingMall.escalator_class).to eq Apartment::Elevators::Subdomain
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'sets values correctly' do
|
5
|
+
it 'is a pass-through to Apartment' do
|
27
6
|
ShoppingMall.configure do |config|
|
28
|
-
config.
|
29
|
-
config.escalator = 'Domain'
|
30
|
-
end
|
31
|
-
|
32
|
-
expect(ShoppingMall.excluded_models).to eq exclusions
|
33
|
-
expect(ShoppingMall.escalator).to eq 'Domain'
|
34
|
-
expect(ShoppingMall.escalator_class).to eq Apartment::Elevators::Domain
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context '#excluded_models' do
|
39
|
-
it 'sets a custom value for `excluded_models`' do
|
40
|
-
ShoppingMall.excluded_models = exclusions
|
41
|
-
expect(ShoppingMall.excluded_models).to eq exclusions
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context '#escalator' do
|
46
|
-
ShoppingMall::ESCALATORS.each do |escalator|
|
47
|
-
it "sets and returns `#{escalator}` as the escalator" do
|
48
|
-
ShoppingMall.escalator = escalator
|
49
|
-
expect(ShoppingMall.escalator).to eq escalator
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context '#escalator_class' do
|
55
|
-
ShoppingMall::ESCALATORS.each do |escalator|
|
56
|
-
it "returns `#{escalator}` as the escalator_class" do
|
57
|
-
ShoppingMall.escalator = escalator
|
58
|
-
expect(ShoppingMall.escalator_class).to eq(
|
59
|
-
"Apartment::Elevators::#{escalator}".constantize
|
60
|
-
)
|
7
|
+
expect(config.to_s).to eq 'Apartment'
|
61
8
|
end
|
62
9
|
end
|
63
10
|
end
|
64
|
-
|
65
|
-
after do
|
66
|
-
ShoppingMall.configure do |config|
|
67
|
-
config.escalator = 'Subdomain'
|
68
|
-
config.excluded_models = ShoppingMall::DEFAULT_SPREE_EXCLUSIONS
|
69
|
-
end
|
70
|
-
end
|
71
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopping_mall
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent Franco
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-09-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: apartment
|
@@ -17,28 +17,28 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '0
|
20
|
+
version: '1.0'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '0
|
27
|
+
version: '1.0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: spree
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 3.0
|
34
|
+
version: '3.0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 3.0
|
41
|
+
version: '3.0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: ffaker
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -243,12 +243,14 @@ extra_rdoc_files: []
|
|
243
243
|
files:
|
244
244
|
- README.md
|
245
245
|
- Rakefile
|
246
|
+
- app/models/spree/image_decorator.rb
|
246
247
|
- app/models/spree/option_type_decorator.rb
|
247
248
|
- app/models/spree/option_types_prototype.rb
|
248
249
|
- app/models/spree/option_value_decorator.rb
|
249
250
|
- app/models/spree/option_values_variant.rb
|
250
251
|
- app/models/spree/order_decorator.rb
|
251
252
|
- app/models/spree/orders_promotion.rb
|
253
|
+
- app/models/spree/preferences/scoped_store_decorator.rb
|
252
254
|
- app/models/spree/product_decorator.rb
|
253
255
|
- app/models/spree/products_promotion_rule.rb
|
254
256
|
- app/models/spree/promotion_decorator.rb
|
@@ -260,33 +262,36 @@ files:
|
|
260
262
|
- app/models/spree/roles_user.rb
|
261
263
|
- app/models/spree/shipping_method_decorator.rb
|
262
264
|
- app/models/spree/shipping_methods_zone.rb
|
265
|
+
- app/models/spree/tenant.rb
|
263
266
|
- app/models/spree/user_decorator.rb
|
264
267
|
- app/models/spree/variant_decorator.rb
|
265
268
|
- app/models/spree/zone_decorator.rb
|
266
|
-
- config/initializers/
|
269
|
+
- config/initializers/apartment.rb
|
267
270
|
- db/migrate/20140611225105_hatbm_to_hmt.rb
|
271
|
+
- db/migrate/20150901171448_create_spree_tenants.rb
|
268
272
|
- lib/generators/shopping_mall/install_generator.rb
|
269
273
|
- lib/generators/templates/shopping_mall.rb
|
270
274
|
- lib/shopping_mall.rb
|
271
275
|
- lib/shopping_mall/engine.rb
|
272
|
-
- lib/shopping_mall/escalator.rb
|
273
276
|
- lib/shopping_mall/version.rb
|
274
277
|
- lib/tasks/tenant.rake
|
275
|
-
- spec/
|
278
|
+
- spec/fixtures/test_cat.jpg
|
279
|
+
- spec/models/spree/image_decorator_spec.rb
|
276
280
|
- spec/models/spree/option_type_decorator_spec.rb
|
277
281
|
- spec/models/spree/option_value_decorator_spec.rb
|
278
282
|
- spec/models/spree/order_decorator_spec.rb
|
283
|
+
- spec/models/spree/preferences/scoped_store_decorator_spec.rb
|
279
284
|
- spec/models/spree/product_decorator_spec.rb
|
280
285
|
- spec/models/spree/promotion_decorator_spec.rb
|
281
286
|
- spec/models/spree/property_decorator_spec.rb
|
282
287
|
- spec/models/spree/prototype_decorator_spec.rb
|
283
288
|
- spec/models/spree/role_decorator_spec.rb
|
284
289
|
- spec/models/spree/shipping_method_decorator_spec.rb
|
290
|
+
- spec/models/spree/tenant_spec.rb
|
285
291
|
- spec/models/spree/user_decorator_spec.rb
|
286
292
|
- spec/models/spree/variant_decorator_spec.rb
|
287
293
|
- spec/models/spree/zone_decorator_spec.rb
|
288
294
|
- spec/shopping_mall/config_spec.rb
|
289
|
-
- spec/shopping_mall/escalator_spec.rb
|
290
295
|
- spec/spec_helper.rb
|
291
296
|
homepage: http://github.com/groundctrl/shopping_mall
|
292
297
|
licenses:
|
@@ -314,19 +319,21 @@ signing_key:
|
|
314
319
|
specification_version: 4
|
315
320
|
summary: Multi-tenancy for Spree 3.x.x
|
316
321
|
test_files:
|
317
|
-
- spec/
|
322
|
+
- spec/fixtures/test_cat.jpg
|
323
|
+
- spec/models/spree/image_decorator_spec.rb
|
318
324
|
- spec/models/spree/option_type_decorator_spec.rb
|
319
325
|
- spec/models/spree/option_value_decorator_spec.rb
|
320
326
|
- spec/models/spree/order_decorator_spec.rb
|
327
|
+
- spec/models/spree/preferences/scoped_store_decorator_spec.rb
|
321
328
|
- spec/models/spree/product_decorator_spec.rb
|
322
329
|
- spec/models/spree/promotion_decorator_spec.rb
|
323
330
|
- spec/models/spree/property_decorator_spec.rb
|
324
331
|
- spec/models/spree/prototype_decorator_spec.rb
|
325
332
|
- spec/models/spree/role_decorator_spec.rb
|
326
333
|
- spec/models/spree/shipping_method_decorator_spec.rb
|
334
|
+
- spec/models/spree/tenant_spec.rb
|
327
335
|
- spec/models/spree/user_decorator_spec.rb
|
328
336
|
- spec/models/spree/variant_decorator_spec.rb
|
329
337
|
- spec/models/spree/zone_decorator_spec.rb
|
330
338
|
- spec/shopping_mall/config_spec.rb
|
331
|
-
- spec/shopping_mall/escalator_spec.rb
|
332
339
|
- spec/spec_helper.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module ShoppingMall
|
2
|
-
class Escalator
|
3
|
-
attr_reader :app, :escalator
|
4
|
-
|
5
|
-
def initialize(app)
|
6
|
-
@app = app
|
7
|
-
@escalator = _escalator_factory app
|
8
|
-
end
|
9
|
-
|
10
|
-
def call(env)
|
11
|
-
escalator.call env
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def _escalator_factory(app)
|
17
|
-
ShoppingMall.escalator_class.new app
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
feature 'Tenancy', js: true do
|
4
|
-
context 'index' do
|
5
|
-
background do
|
6
|
-
visit 'http://tenant-name.example.dev:3000'
|
7
|
-
end
|
8
|
-
|
9
|
-
xscenario 'homepage' do
|
10
|
-
expect(page).to have_text 'welcome'
|
11
|
-
expect(response).to have_http_status(:ok)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ShoppingMall::Escalator do
|
4
|
-
context 'delegation' do
|
5
|
-
%w[Subdomain Domain FirstSubdomain].each do |domain_type|
|
6
|
-
context "with config as #{domain_type}" do
|
7
|
-
it "sets delegator as Apartment::Elevator::#{domain_type}" do
|
8
|
-
ShoppingMall.configure { |config| config.escalator = domain_type }
|
9
|
-
test = ShoppingMall::Escalator.new double(foo: 'bar')
|
10
|
-
expect(test.escalator.class.to_s).to(
|
11
|
-
eq "Apartment::Elevators::#{domain_type}"
|
12
|
-
)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it '.call is passed to escalator' do
|
18
|
-
test = ShoppingMall::Escalator.new double(foo: 'bar')
|
19
|
-
env = Rack::MockRequest.env_for('foo')
|
20
|
-
expect(test.escalator).to receive(:call).with(env)
|
21
|
-
test.call env
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
after do
|
26
|
-
ShoppingMall.configure do |config|
|
27
|
-
config.escalator = 'Subdomain'
|
28
|
-
config.excluded_models = ShoppingMall::DEFAULT_SPREE_EXCLUSIONS
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|