acts_as_tenant 0.3.7 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +4 -0
- data/CHANGELOG.md +4 -0
- data/Rakefile +11 -0
- data/acts_as_tenant.gemspec +2 -1
- data/lib/acts_as_tenant.rb +3 -5
- data/lib/acts_as_tenant/model_extensions.rb +30 -19
- data/lib/acts_as_tenant/sidekiq.rb +1 -1
- data/lib/acts_as_tenant/version.rb +1 -1
- data/spec/active_record_helper.rb +21 -0
- data/spec/active_record_models.rb +109 -0
- data/spec/acts_as_tenant/model_extensions_spec.rb +9 -118
- data/spec/mongoid.yml +6 -0
- data/spec/mongoid_helper.rb +23 -0
- data/spec/mongoid_models.rb +81 -0
- data/spec/spec_helper.rb +5 -18
- metadata +31 -6
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmFmMDEwY2Y3YTYwOGY4MzRmYTRmYTQ3ZDYwNTFlMTE5YTRmN2U5Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjNmNmNhNDBiNjE3NjQxNTI2MjM0NTNkZWFhZTRjYTBhMjBkZjhlMw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWZhZGE3MDA5OTczZDNmNmY1MDllZDIwYjgwYWMwNGUyMjQ3ZTdmNWRkNTgz
|
10
|
+
Y2Q3YTU1YTVkNGJjYzI4YjBlMGQwMWNhN2Q4OWU4YTBhZTkyMzYxZjgyOTMw
|
11
|
+
ZGY3ODFjMzVjNmUyZTBmNjE0MjA5YzMwZTllODc4ZGUyMjdjMTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTgzOTVhMzZiMzFhZjQ1MjNjMmUzZWNlZjRlOWFkYTY1YzhmNWRhMzViMzI2
|
14
|
+
ZTI1OTZiODRiMTY2NjY2NjBjYTRhYTNlNjljMmU2MDllNDU3Mzg5OTYyZTZm
|
15
|
+
MWRjYWM2ZDY3YmRiOGQ2YzYyNjA2MGE5MGI1YzhiMjk1NzliZjI=
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
@@ -3,3 +3,14 @@ require 'bundler/gem_tasks'
|
|
3
3
|
require 'rspec/core/rake_task'
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
task :default => :spec
|
6
|
+
|
7
|
+
desc 'Run the test suite for all supported ORMs.'
|
8
|
+
namespace :spec do
|
9
|
+
task :all do
|
10
|
+
%w[active_record mongoid].each do |orm|
|
11
|
+
ENV["ORM"] = orm
|
12
|
+
Rake::Task["spec"].reenable
|
13
|
+
Rake::Task["spec"].invoke
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/acts_as_tenant.gemspec
CHANGED
@@ -25,8 +25,9 @@ Gem::Specification.new do |s|
|
|
25
25
|
|
26
26
|
s.add_development_dependency('rspec', '>=3.0')
|
27
27
|
s.add_development_dependency('rspec-rails')
|
28
|
-
s.add_development_dependency('database_cleaner')
|
28
|
+
s.add_development_dependency('database_cleaner', '~> 1.3.0')
|
29
29
|
s.add_development_dependency('sqlite3')
|
30
|
+
s.add_development_dependency('mongoid', '~> 4.0')
|
30
31
|
|
31
32
|
s.add_development_dependency('sidekiq', '3.2.1')
|
32
33
|
end
|
data/lib/acts_as_tenant.rb
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
#RAILS_3 = ::ActiveRecord::VERSION::MAJOR >= 3
|
2
|
-
|
3
|
-
require "active_record"
|
4
|
-
require "action_controller"
|
5
|
-
require "active_model"
|
6
1
|
require "request_store"
|
7
2
|
|
8
3
|
#$LOAD_PATH.unshift(File.dirname(__FILE__))
|
@@ -17,6 +12,9 @@ require "acts_as_tenant/model_extensions"
|
|
17
12
|
|
18
13
|
if defined?(ActiveRecord::Base)
|
19
14
|
ActiveRecord::Base.send(:include, ActsAsTenant::ModelExtensions)
|
15
|
+
end
|
16
|
+
|
17
|
+
if defined?(ActionController::Base)
|
20
18
|
ActionController::Base.extend ActsAsTenant::ControllerExtensions
|
21
19
|
end
|
22
20
|
|
@@ -53,7 +53,11 @@ module ActsAsTenant
|
|
53
53
|
if ActsAsTenant.configuration.require_tenant && ActsAsTenant.current_tenant.nil?
|
54
54
|
raise ActsAsTenant::Errors::NoTenantSet
|
55
55
|
end
|
56
|
-
|
56
|
+
if ActsAsTenant.current_tenant
|
57
|
+
where(fkey.to_sym => ActsAsTenant.current_tenant.id)
|
58
|
+
else
|
59
|
+
all
|
60
|
+
end
|
57
61
|
}
|
58
62
|
|
59
63
|
# Add the following validations to the receiving model:
|
@@ -66,15 +70,20 @@ module ActsAsTenant
|
|
66
70
|
end
|
67
71
|
}, :on => :create
|
68
72
|
|
69
|
-
polymorphic_foreign_keys = reflect_on_all_associations.select do |a|
|
73
|
+
polymorphic_foreign_keys = reflect_on_all_associations(:belongs_to).select do |a|
|
70
74
|
a.options[:polymorphic]
|
71
75
|
end.map { |a| a.foreign_key }
|
72
76
|
|
73
|
-
reflect_on_all_associations.each do |a|
|
74
|
-
unless a == reflect_on_association(tenant) ||
|
77
|
+
reflect_on_all_associations(:belongs_to).each do |a|
|
78
|
+
unless a == reflect_on_association(tenant) || polymorphic_foreign_keys.include?(a.foreign_key)
|
75
79
|
association_class = a.options[:class_name].nil? ? a.name.to_s.classify.constantize : a.options[:class_name].constantize
|
76
80
|
validates_each a.foreign_key.to_sym do |record, attr, value|
|
77
|
-
|
81
|
+
primary_key = if association_class.respond_to?(:primary_key)
|
82
|
+
association_class.primary_key
|
83
|
+
else
|
84
|
+
a.primary_key
|
85
|
+
end.to_sym
|
86
|
+
record.errors.add attr, "association is invalid [ActsAsTenant]" unless value.nil? || association_class.where(primary_key => value).exists?
|
78
87
|
end
|
79
88
|
end
|
80
89
|
end
|
@@ -83,24 +92,26 @@ module ActsAsTenant
|
|
83
92
|
# - Rewrite the accessors to make tenant immutable
|
84
93
|
# - Add an override to prevent unnecessary db hits
|
85
94
|
# - Add a helper method to verify if a model has been scoped by AaT
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
95
|
+
to_include = Module.new do
|
96
|
+
define_method "#{fkey}=" do |integer|
|
97
|
+
raise ActsAsTenant::Errors::TenantIsImmutable unless new_record? || send(fkey).nil? || send(fkey) == integer
|
98
|
+
write_attribute("#{fkey}", integer)
|
99
|
+
end
|
91
100
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
101
|
+
define_method "#{ActsAsTenant.tenant_klass.to_s}=" do |model|
|
102
|
+
raise ActsAsTenant::Errors::TenantIsImmutable unless new_record? || send(fkey).nil? || send(fkey) == integer
|
103
|
+
super(model)
|
104
|
+
end
|
96
105
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
106
|
+
define_method "#{ActsAsTenant.tenant_klass.to_s}" do
|
107
|
+
if !ActsAsTenant.current_tenant.nil? && send(fkey) == ActsAsTenant.current_tenant.id
|
108
|
+
return ActsAsTenant.current_tenant
|
109
|
+
else
|
110
|
+
super()
|
111
|
+
end
|
102
112
|
end
|
103
113
|
end
|
114
|
+
include to_include
|
104
115
|
|
105
116
|
class << self
|
106
117
|
def scoped_by_tenant?
|
@@ -38,6 +38,6 @@ Sidekiq.configure_server do |config|
|
|
38
38
|
chain.add ActsAsTenant::Sidekiq::Client
|
39
39
|
end
|
40
40
|
config.server_middleware do |chain|
|
41
|
-
chain.
|
41
|
+
chain.insert_before Sidekiq::Middleware::Server::RetryJobs, ActsAsTenant::Sidekiq::Server
|
42
42
|
end
|
43
43
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails/all'
|
2
|
+
require 'database_cleaner'
|
3
|
+
|
4
|
+
dbconfig = YAML::load(IO.read(File.join(File.dirname(__FILE__), 'database.yml')))
|
5
|
+
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
6
|
+
ActiveRecord::Base.establish_connection(dbconfig[ENV['DB'] || 'sqlite'])
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.before(:suite) do
|
10
|
+
DatabaseCleaner[:active_record].strategy = :transaction
|
11
|
+
DatabaseCleaner[:active_record].clean_with(:truncation)
|
12
|
+
end
|
13
|
+
|
14
|
+
config.before(:each) do
|
15
|
+
DatabaseCleaner[:active_record].start
|
16
|
+
end
|
17
|
+
|
18
|
+
config.after(:each) do
|
19
|
+
DatabaseCleaner[:active_record].clean
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
ActiveRecord::Schema.define(:version => 1) do
|
2
|
+
create_table :accounts, :force => true do |t|
|
3
|
+
t.column :name, :string
|
4
|
+
t.column :subdomain, :string
|
5
|
+
t.column :domain, :string
|
6
|
+
end
|
7
|
+
|
8
|
+
create_table :projects, :force => true do |t|
|
9
|
+
t.column :name, :string
|
10
|
+
t.column :account_id, :integer
|
11
|
+
end
|
12
|
+
|
13
|
+
create_table :managers, :force => true do |t|
|
14
|
+
t.column :name, :string
|
15
|
+
t.column :project_id, :integer
|
16
|
+
t.column :account_id, :integer
|
17
|
+
end
|
18
|
+
|
19
|
+
create_table :tasks, :force => true do |t|
|
20
|
+
t.column :name, :string
|
21
|
+
t.column :account_id, :integer
|
22
|
+
t.column :project_id, :integer
|
23
|
+
t.column :completed, :boolean
|
24
|
+
end
|
25
|
+
|
26
|
+
create_table :countries, :force => true do |t|
|
27
|
+
t.column :name, :string
|
28
|
+
end
|
29
|
+
|
30
|
+
create_table :unscoped_models, :force => true do |t|
|
31
|
+
t.column :name, :string
|
32
|
+
end
|
33
|
+
|
34
|
+
create_table :aliased_tasks, :force => true do |t|
|
35
|
+
t.column :name, :string
|
36
|
+
t.column :project_alias_id, :integer
|
37
|
+
t.column :account_id, :integer
|
38
|
+
end
|
39
|
+
|
40
|
+
create_table :unique_tasks, :force => true do |t|
|
41
|
+
t.column :name, :string
|
42
|
+
t.column :user_defined_scope, :string
|
43
|
+
t.column :project_id, :integer
|
44
|
+
t.column :account_id, :integer
|
45
|
+
end
|
46
|
+
|
47
|
+
create_table :custom_foreign_key_tasks, :force => true do |t|
|
48
|
+
t.column :name, :string
|
49
|
+
t.column :accountID, :integer
|
50
|
+
end
|
51
|
+
|
52
|
+
create_table :comments, :force => true do |t|
|
53
|
+
t.column :commentable_id, :integer
|
54
|
+
t.column :commentable_type, :string
|
55
|
+
t.column :account_id, :integer
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
class Account < ActiveRecord::Base
|
61
|
+
has_many :projects
|
62
|
+
end
|
63
|
+
|
64
|
+
class Project < ActiveRecord::Base
|
65
|
+
has_one :manager
|
66
|
+
has_many :tasks
|
67
|
+
acts_as_tenant :account
|
68
|
+
|
69
|
+
validates_uniqueness_to_tenant :name
|
70
|
+
end
|
71
|
+
|
72
|
+
class Manager < ActiveRecord::Base
|
73
|
+
belongs_to :project
|
74
|
+
acts_as_tenant :account
|
75
|
+
end
|
76
|
+
|
77
|
+
class Task < ActiveRecord::Base
|
78
|
+
belongs_to :project
|
79
|
+
default_scope -> { where(:completed => nil).order("name") }
|
80
|
+
|
81
|
+
acts_as_tenant :account
|
82
|
+
validates_uniqueness_of :name
|
83
|
+
end
|
84
|
+
|
85
|
+
class UnscopedModel < ActiveRecord::Base
|
86
|
+
validates_uniqueness_of :name
|
87
|
+
end
|
88
|
+
|
89
|
+
class AliasedTask < ActiveRecord::Base
|
90
|
+
acts_as_tenant(:account)
|
91
|
+
belongs_to :project_alias, :class_name => "Project"
|
92
|
+
end
|
93
|
+
|
94
|
+
class UniqueTask < ActiveRecord::Base
|
95
|
+
acts_as_tenant(:account)
|
96
|
+
belongs_to :project
|
97
|
+
validates_uniqueness_to_tenant :name, scope: :user_defined_scope
|
98
|
+
end
|
99
|
+
|
100
|
+
class CustomForeignKeyTask < ActiveRecord::Base
|
101
|
+
acts_as_tenant(:account, :foreign_key => "accountID")
|
102
|
+
validates_uniqueness_to_tenant :name
|
103
|
+
end
|
104
|
+
|
105
|
+
class Comment < ActiveRecord::Base
|
106
|
+
belongs_to :commentable, polymorphic: true
|
107
|
+
belongs_to :task, -> { where(comments: { commentable_type: 'Task' }) }, foreign_key: 'commentable_id'
|
108
|
+
acts_as_tenant :account
|
109
|
+
end
|
@@ -1,118 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require "#{$orm}_models"
|
2
3
|
|
3
|
-
# Setup the db
|
4
|
-
ActiveRecord::Schema.define(:version => 1) do
|
5
|
-
create_table :accounts, :force => true do |t|
|
6
|
-
t.column :name, :string
|
7
|
-
t.column :subdomain, :string
|
8
|
-
t.column :domain, :string
|
9
|
-
end
|
10
|
-
|
11
|
-
create_table :projects, :force => true do |t|
|
12
|
-
t.column :name, :string
|
13
|
-
t.column :account_id, :integer
|
14
|
-
end
|
15
|
-
|
16
|
-
create_table :managers, :force => true do |t|
|
17
|
-
t.column :name, :string
|
18
|
-
t.column :project_id, :integer
|
19
|
-
t.column :account_id, :integer
|
20
|
-
end
|
21
|
-
|
22
|
-
create_table :tasks, :force => true do |t|
|
23
|
-
t.column :name, :string
|
24
|
-
t.column :account_id, :integer
|
25
|
-
t.column :project_id, :integer
|
26
|
-
t.column :completed, :boolean
|
27
|
-
end
|
28
|
-
|
29
|
-
create_table :countries, :force => true do |t|
|
30
|
-
t.column :name, :string
|
31
|
-
end
|
32
|
-
|
33
|
-
create_table :unscoped_models, :force => true do |t|
|
34
|
-
t.column :name, :string
|
35
|
-
end
|
36
|
-
|
37
|
-
create_table :aliased_tasks, :force => true do |t|
|
38
|
-
t.column :name, :string
|
39
|
-
t.column :project_alias_id, :integer
|
40
|
-
t.column :account_id, :integer
|
41
|
-
end
|
42
|
-
|
43
|
-
create_table :unique_tasks, :force => true do |t|
|
44
|
-
t.column :name, :string
|
45
|
-
t.column :user_defined_scope, :string
|
46
|
-
t.column :project_id, :integer
|
47
|
-
t.column :account_id, :integer
|
48
|
-
end
|
49
|
-
|
50
|
-
create_table :custom_foreign_key_tasks, :force => true do |t|
|
51
|
-
t.column :name, :string
|
52
|
-
t.column :accountID, :integer
|
53
|
-
end
|
54
|
-
|
55
|
-
create_table :comments, :force => true do |t|
|
56
|
-
t.column :commentable_id, :integer
|
57
|
-
t.column :commentable_type, :string
|
58
|
-
t.column :account_id, :integer
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
# Setup the models
|
64
|
-
class Account < ActiveRecord::Base
|
65
|
-
has_many :projects
|
66
|
-
end
|
67
|
-
|
68
|
-
class Project < ActiveRecord::Base
|
69
|
-
has_one :manager
|
70
|
-
has_many :tasks
|
71
|
-
acts_as_tenant :account
|
72
|
-
|
73
|
-
validates_uniqueness_to_tenant :name
|
74
|
-
end
|
75
|
-
|
76
|
-
class Manager < ActiveRecord::Base
|
77
|
-
belongs_to :project
|
78
|
-
acts_as_tenant :account
|
79
|
-
end
|
80
|
-
|
81
|
-
class Task < ActiveRecord::Base
|
82
|
-
belongs_to :project
|
83
|
-
default_scope -> { where(:completed => nil).order("name") }
|
84
|
-
|
85
|
-
acts_as_tenant :account
|
86
|
-
validates_uniqueness_of :name
|
87
|
-
end
|
88
|
-
|
89
|
-
class UnscopedModel < ActiveRecord::Base
|
90
|
-
validates_uniqueness_of :name
|
91
|
-
end
|
92
|
-
|
93
|
-
class AliasedTask < ActiveRecord::Base
|
94
|
-
acts_as_tenant(:account)
|
95
|
-
belongs_to :project_alias, :class_name => "Project"
|
96
|
-
end
|
97
|
-
|
98
|
-
class UniqueTask < ActiveRecord::Base
|
99
|
-
acts_as_tenant(:account)
|
100
|
-
belongs_to :project
|
101
|
-
validates_uniqueness_to_tenant :name, scope: :user_defined_scope
|
102
|
-
end
|
103
|
-
|
104
|
-
class CustomForeignKeyTask < ActiveRecord::Base
|
105
|
-
acts_as_tenant(:account, :foreign_key => "accountID")
|
106
|
-
validates_uniqueness_to_tenant :name
|
107
|
-
end
|
108
|
-
|
109
|
-
class Comment < ActiveRecord::Base
|
110
|
-
belongs_to :commentable, polymorphic: true
|
111
|
-
belongs_to :task, -> { where(comments: { commentable_type: 'Task' }) }, foreign_key: 'commentable_id'
|
112
|
-
acts_as_tenant :account
|
113
|
-
end
|
114
|
-
|
115
|
-
# Start testing!
|
116
4
|
describe ActsAsTenant do
|
117
5
|
after { ActsAsTenant.current_tenant = nil }
|
118
6
|
|
@@ -228,7 +116,8 @@ describe ActsAsTenant do
|
|
228
116
|
|
229
117
|
ActsAsTenant.current_tenant = @account
|
230
118
|
@task2 = @project.tasks.create!(:name => 'baz')
|
231
|
-
|
119
|
+
|
120
|
+
@project.reload
|
232
121
|
end
|
233
122
|
|
234
123
|
it 'should correctly set the tenant on the task created with current_tenant set' do
|
@@ -236,16 +125,16 @@ describe ActsAsTenant do
|
|
236
125
|
end
|
237
126
|
|
238
127
|
it 'should filter out the non-tenant task from the project' do
|
239
|
-
expect(@tasks.length).to eq(1)
|
128
|
+
expect(@project.tasks.length).to eq(1)
|
240
129
|
end
|
241
130
|
end
|
242
131
|
|
243
132
|
describe 'Associations can only be made with in-scope objects' do
|
244
133
|
before do
|
245
134
|
@account = Account.create!(:name => 'foo')
|
246
|
-
@project1 = Project.create!(:name => 'inaccessible_project', :
|
247
|
-
|
135
|
+
@project1 = Project.create!(:name => 'inaccessible_project', :account => Account.create!)
|
248
136
|
ActsAsTenant.current_tenant = @account
|
137
|
+
|
249
138
|
@project2 = Project.create!(:name => 'accessible_project')
|
250
139
|
@task = @project2.tasks.create!(:name => 'bar')
|
251
140
|
end
|
@@ -254,9 +143,11 @@ describe ActsAsTenant do
|
|
254
143
|
end
|
255
144
|
|
256
145
|
describe "Create and save an AaT-enabled child without it having a parent" do
|
146
|
+
before do
|
257
147
|
@account = Account.create!(:name => 'baz')
|
258
148
|
ActsAsTenant.current_tenant = @account
|
259
|
-
|
149
|
+
end
|
150
|
+
it { expect(Task.create(:name => 'bar').valid?).to eq(true) }
|
260
151
|
end
|
261
152
|
|
262
153
|
describe "It should be possible to use aliased associations" do
|
data/spec/mongoid.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "action_controller/railtie"
|
2
|
+
require "action_mailer/railtie"
|
3
|
+
require 'mongoid'
|
4
|
+
require 'database_cleaner'
|
5
|
+
|
6
|
+
Mongoid.logger = Moped.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
7
|
+
Mongoid.logger.level = Moped.logger.level = Logger::DEBUG
|
8
|
+
Mongoid.load!(File.join(File.dirname(__FILE__), "/mongoid.yml"), :test)
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.before(:suite) do
|
12
|
+
DatabaseCleaner[:mongoid].strategy = :truncation
|
13
|
+
DatabaseCleaner[:mongoid].clean_with(:truncation)
|
14
|
+
end
|
15
|
+
|
16
|
+
config.before(:each) do
|
17
|
+
DatabaseCleaner[:mongoid].start
|
18
|
+
end
|
19
|
+
|
20
|
+
config.after(:each) do
|
21
|
+
DatabaseCleaner[:mongoid].clean
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
class Account
|
2
|
+
include Mongoid::Document
|
3
|
+
include ActsAsTenant::ModelExtensions
|
4
|
+
field :name, type: String
|
5
|
+
field :subdomain, type: String
|
6
|
+
field :domain, type: String
|
7
|
+
has_many :projects
|
8
|
+
end
|
9
|
+
|
10
|
+
class Project
|
11
|
+
include Mongoid::Document
|
12
|
+
include ActsAsTenant::ModelExtensions
|
13
|
+
field :name, type: String
|
14
|
+
has_one :manager
|
15
|
+
has_many :tasks
|
16
|
+
acts_as_tenant :account
|
17
|
+
|
18
|
+
validates_uniqueness_to_tenant :name
|
19
|
+
end
|
20
|
+
|
21
|
+
class Manager
|
22
|
+
include Mongoid::Document
|
23
|
+
include ActsAsTenant::ModelExtensions
|
24
|
+
field :name, type: String
|
25
|
+
belongs_to :project
|
26
|
+
acts_as_tenant :account
|
27
|
+
end
|
28
|
+
|
29
|
+
class Task
|
30
|
+
include Mongoid::Document
|
31
|
+
include ActsAsTenant::ModelExtensions
|
32
|
+
field :name, type: String
|
33
|
+
field :completed, type: Boolean
|
34
|
+
belongs_to :project
|
35
|
+
default_scope -> { where(:completed => nil).order("name" => :asc) }
|
36
|
+
|
37
|
+
acts_as_tenant :account
|
38
|
+
validates_uniqueness_of :name
|
39
|
+
end
|
40
|
+
|
41
|
+
class UnscopedModel
|
42
|
+
include Mongoid::Document
|
43
|
+
include ActsAsTenant::ModelExtensions
|
44
|
+
field :name, type: String
|
45
|
+
validates_uniqueness_of :name
|
46
|
+
end
|
47
|
+
|
48
|
+
class AliasedTask
|
49
|
+
include Mongoid::Document
|
50
|
+
include ActsAsTenant::ModelExtensions
|
51
|
+
field :name, type: String
|
52
|
+
acts_as_tenant(:account)
|
53
|
+
belongs_to :project_alias, :class_name => "Project"
|
54
|
+
end
|
55
|
+
|
56
|
+
class UniqueTask
|
57
|
+
include Mongoid::Document
|
58
|
+
include ActsAsTenant::ModelExtensions
|
59
|
+
field :name, type: String
|
60
|
+
field :user_defined_scope, type: String
|
61
|
+
acts_as_tenant(:account)
|
62
|
+
belongs_to :project
|
63
|
+
validates_uniqueness_to_tenant :name, scope: :user_defined_scope
|
64
|
+
end
|
65
|
+
|
66
|
+
class CustomForeignKeyTask
|
67
|
+
include Mongoid::Document
|
68
|
+
include ActsAsTenant::ModelExtensions
|
69
|
+
field :name, type: String
|
70
|
+
field :accountID, type: Integer
|
71
|
+
acts_as_tenant(:account, :foreign_key => "accountID")
|
72
|
+
validates_uniqueness_to_tenant :name
|
73
|
+
end
|
74
|
+
|
75
|
+
class Comment
|
76
|
+
include Mongoid::Document
|
77
|
+
include ActsAsTenant::ModelExtensions
|
78
|
+
belongs_to :commentable, polymorphic: true
|
79
|
+
belongs_to :task, foreign_key: 'commentable_id'
|
80
|
+
acts_as_tenant :account
|
81
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,27 +1,14 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
3
|
|
4
|
-
|
5
|
-
require
|
6
|
-
require 'rspec/rails'
|
7
|
-
require 'rails'
|
4
|
+
$orm = ENV["ORM"] || "active_record"
|
5
|
+
require "#{$orm}_helper"
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite'])
|
7
|
+
require 'rspec/rails'
|
8
|
+
require 'acts_as_tenant'
|
12
9
|
|
13
10
|
RSpec.configure do |config|
|
14
|
-
config.before(:suite) do
|
15
|
-
DatabaseCleaner.strategy = :transaction
|
16
|
-
DatabaseCleaner.clean_with(:truncation)
|
17
|
-
end
|
18
|
-
|
19
|
-
config.before(:each) do
|
20
|
-
DatabaseCleaner.start
|
21
|
-
end
|
22
|
-
|
23
11
|
config.after(:each) do
|
24
|
-
DatabaseCleaner.clean
|
25
12
|
ActsAsTenant.current_tenant = nil
|
26
13
|
end
|
27
14
|
|
@@ -34,4 +21,4 @@ module Rollcall
|
|
34
21
|
end
|
35
22
|
|
36
23
|
Rollcall::Application.config.secret_token = '1234567890123456789012345678901234567890'
|
37
|
-
Rollcall::Application.config.secret_key_base = '1234567890123456789012345678901234567890'
|
24
|
+
Rollcall::Application.config.secret_key_base = '1234567890123456789012345678901234567890'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_tenant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erwin Matthijssen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: request_store
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: database_cleaner
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.3.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.3.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: sqlite3
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ! '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mongoid
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '4.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '4.0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: sidekiq
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,6 +131,7 @@ extensions: []
|
|
117
131
|
extra_rdoc_files: []
|
118
132
|
files:
|
119
133
|
- .gitignore
|
134
|
+
- .travis.yml
|
120
135
|
- CHANGELOG.md
|
121
136
|
- Gemfile
|
122
137
|
- MIT-LICENSE
|
@@ -131,6 +146,8 @@ files:
|
|
131
146
|
- lib/acts_as_tenant/sidekiq.rb
|
132
147
|
- lib/acts_as_tenant/version.rb
|
133
148
|
- rails/init.rb
|
149
|
+
- spec/active_record_helper.rb
|
150
|
+
- spec/active_record_models.rb
|
134
151
|
- spec/acts_as_tenant/configuration_spec.rb
|
135
152
|
- spec/acts_as_tenant/model_extensions_spec.rb
|
136
153
|
- spec/acts_as_tenant/sidekiq_spec.rb
|
@@ -138,6 +155,9 @@ files:
|
|
138
155
|
- spec/acts_as_tenant/tenant_by_subdomain_or_domain.rb
|
139
156
|
- spec/acts_as_tenant/tenant_by_subdomain_spec.rb
|
140
157
|
- spec/database.yml
|
158
|
+
- spec/mongoid.yml
|
159
|
+
- spec/mongoid_helper.rb
|
160
|
+
- spec/mongoid_models.rb
|
141
161
|
- spec/spec_helper.rb
|
142
162
|
homepage: http://www.rollcallapp.com/blog
|
143
163
|
licenses: []
|
@@ -163,6 +183,8 @@ signing_key:
|
|
163
183
|
specification_version: 4
|
164
184
|
summary: Add multi-tenancy to Rails applications using a shared db strategy
|
165
185
|
test_files:
|
186
|
+
- spec/active_record_helper.rb
|
187
|
+
- spec/active_record_models.rb
|
166
188
|
- spec/acts_as_tenant/configuration_spec.rb
|
167
189
|
- spec/acts_as_tenant/model_extensions_spec.rb
|
168
190
|
- spec/acts_as_tenant/sidekiq_spec.rb
|
@@ -170,4 +192,7 @@ test_files:
|
|
170
192
|
- spec/acts_as_tenant/tenant_by_subdomain_or_domain.rb
|
171
193
|
- spec/acts_as_tenant/tenant_by_subdomain_spec.rb
|
172
194
|
- spec/database.yml
|
195
|
+
- spec/mongoid.yml
|
196
|
+
- spec/mongoid_helper.rb
|
197
|
+
- spec/mongoid_models.rb
|
173
198
|
- spec/spec_helper.rb
|