acts_as_tenant 0.4.4 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_tenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Matthijssen
8
- autorequire:
8
+ - Chris Oliver
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2019-08-14 00:00:00.000000000 Z
12
+ date: 2022-09-06 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: request_store
@@ -30,14 +31,14 @@ dependencies:
30
31
  requirements:
31
32
  - - ">="
32
33
  - !ruby/object:Gem::Version
33
- version: '4.0'
34
+ version: '5.2'
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
39
  - - ">="
39
40
  - !ruby/object:Gem::Version
40
- version: '4.0'
41
+ version: '5.2'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: rspec
43
44
  requirement: !ruby/object:Gem::Requirement
@@ -67,21 +68,41 @@ dependencies:
67
68
  - !ruby/object:Gem::Version
68
69
  version: '0'
69
70
  - !ruby/object:Gem::Dependency
70
- name: database_cleaner
71
+ name: sqlite3
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: sidekiq
71
86
  requirement: !ruby/object:Gem::Requirement
72
87
  requirements:
73
88
  - - "~>"
74
89
  - !ruby/object:Gem::Version
75
- version: '1.7'
90
+ version: '6.1'
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 6.1.2
76
94
  type: :development
77
95
  prerelease: false
78
96
  version_requirements: !ruby/object:Gem::Requirement
79
97
  requirements:
80
98
  - - "~>"
81
99
  - !ruby/object:Gem::Version
82
- version: '1.7'
100
+ version: '6.1'
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 6.1.2
83
104
  - !ruby/object:Gem::Dependency
84
- name: sqlite3
105
+ name: standard
85
106
  requirement: !ruby/object:Gem::Requirement
86
107
  requirements:
87
108
  - - ">="
@@ -95,59 +116,47 @@ dependencies:
95
116
  - !ruby/object:Gem::Version
96
117
  version: '0'
97
118
  - !ruby/object:Gem::Dependency
98
- name: sidekiq
119
+ name: appraisal
99
120
  requirement: !ruby/object:Gem::Requirement
100
121
  requirements:
101
- - - '='
122
+ - - ">="
102
123
  - !ruby/object:Gem::Version
103
- version: 3.2.1
124
+ version: '0'
104
125
  type: :development
105
126
  prerelease: false
106
127
  version_requirements: !ruby/object:Gem::Requirement
107
128
  requirements:
108
- - - '='
129
+ - - ">="
109
130
  - !ruby/object:Gem::Version
110
- version: 3.2.1
131
+ version: '0'
111
132
  description: Integrates multi-tenancy into a Rails application in a convenient and
112
133
  out-of-your way manner
113
134
  email:
114
135
  - erwin.matthijssen@gmail.com
136
+ - excid3@gmail.com
115
137
  executables: []
116
138
  extensions: []
117
139
  extra_rdoc_files: []
118
140
  files:
119
- - ".gitignore"
120
- - ".travis.yml"
121
- - CHANGELOG.md
122
- - Gemfile
123
141
  - MIT-LICENSE
124
142
  - README.md
125
143
  - Rakefile
126
- - _config.yml
127
- - acts_as_tenant.gemspec
128
- - docs/blog_post.md
129
144
  - lib/acts_as_tenant.rb
130
145
  - lib/acts_as_tenant/configuration.rb
131
146
  - lib/acts_as_tenant/controller_extensions.rb
147
+ - lib/acts_as_tenant/controller_extensions/filter.rb
148
+ - lib/acts_as_tenant/controller_extensions/subdomain.rb
149
+ - lib/acts_as_tenant/controller_extensions/subdomain_or_domain.rb
132
150
  - lib/acts_as_tenant/errors.rb
133
151
  - lib/acts_as_tenant/model_extensions.rb
134
152
  - lib/acts_as_tenant/sidekiq.rb
153
+ - lib/acts_as_tenant/tenant_helper.rb
154
+ - lib/acts_as_tenant/test_tenant_middleware.rb
135
155
  - lib/acts_as_tenant/version.rb
136
- - rails/init.rb
137
- - spec/active_record_helper.rb
138
- - spec/active_record_models.rb
139
- - spec/acts_as_tenant/configuration_spec.rb
140
- - spec/acts_as_tenant/model_extensions_spec.rb
141
- - spec/acts_as_tenant/sidekiq_spec.rb
142
- - spec/acts_as_tenant/tenant_by_filter_spec.rb
143
- - spec/acts_as_tenant/tenant_by_subdomain_or_domain.rb
144
- - spec/acts_as_tenant/tenant_by_subdomain_spec.rb
145
- - spec/database.yml
146
- - spec/spec_helper.rb
147
- homepage: http://www.rollcallapp.com/blog
156
+ homepage: https://github.com/ErwinM/acts_as_tenant
148
157
  licenses: []
149
158
  metadata: {}
150
- post_install_message:
159
+ post_install_message:
151
160
  rdoc_options: []
152
161
  require_paths:
153
162
  - lib
@@ -162,19 +171,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
171
  - !ruby/object:Gem::Version
163
172
  version: '0'
164
173
  requirements: []
165
- rubyforge_project: acts_as_tenant
166
- rubygems_version: 2.6.11
167
- signing_key:
174
+ rubygems_version: 3.3.7
175
+ signing_key:
168
176
  specification_version: 4
169
177
  summary: Add multi-tenancy to Rails applications using a shared db strategy
170
- test_files:
171
- - spec/active_record_helper.rb
172
- - spec/active_record_models.rb
173
- - spec/acts_as_tenant/configuration_spec.rb
174
- - spec/acts_as_tenant/model_extensions_spec.rb
175
- - spec/acts_as_tenant/sidekiq_spec.rb
176
- - spec/acts_as_tenant/tenant_by_filter_spec.rb
177
- - spec/acts_as_tenant/tenant_by_subdomain_or_domain.rb
178
- - spec/acts_as_tenant/tenant_by_subdomain_spec.rb
179
- - spec/database.yml
180
- - spec/spec_helper.rb
178
+ test_files: []
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- .rvmrc
2
- *.gem
3
- .bundle
4
- Gemfile.lock
5
- pkg/*
6
- spec/*.sqlite3
7
- spec/*.log
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- before_install:
3
- - gem update bundler
4
- script: bundle exec rake spec
data/CHANGELOG.md DELETED
@@ -1,119 +0,0 @@
1
- 0.4.4
2
- -----
3
- * Implement support for polymorphic tenant
4
- * Ability to use acts_as_tenant with only ActiveRecord (no Rails)
5
- * Allow setting of custom primary key
6
- * Bug fixes
7
-
8
- 0.4.3
9
- -----
10
- * allow 'optional' relations
11
- * Sidekiq fixes
12
- * Replace all `before_filter` with `before_action` for Rails 5.1 compatibility
13
-
14
- 0.4.1
15
- ------
16
- * Removed (stale, no longer working) MongoDB support; moved code to separate branch
17
- * Added without_tenant option (see readme, thx duboff)
18
-
19
- 0.4.0
20
- ------
21
- * (Sub)domain lookup is no longer case insensitive
22
- * Added ability to use inverse_of (thx lowjoel)
23
- * Added ability to disable tenant checking for a block (thx duboff)
24
- * Allow for validation that associations belong to the tenant to reflect on associations which return an Array from `where` (thx ludamillion)
25
-
26
- 0.3.9
27
- -----
28
- * Added ability to configure a default tenant for testing purposes. (thx iangreenleaf)
29
- * AaT will now accept a string for a tenant_id (thx calebthompson)
30
- * Improvements to readme (thx stgeneral)
31
-
32
- 0.3.8
33
- -----
34
- * Added Mongoid compatibility [thx iangreenleaf]
35
-
36
- 0.3.7
37
- -----
38
- * Fix for proper handling of polymorphic associations (thx sol1dus)
39
- * Fix fefault scope to generate correct sql when using database prefix (thx IgorDobryn)
40
- * Added ability to specify a custom Primary Key (thx matiasdim)
41
- * Sidekiq 3.2.2+ no longer supports Ruby 1.9. Locking Sidekiq in gemspec at 3.2.1.
42
- * Update RSPEC to 3.0. Convert all specs (thx petergoldstein)
43
- * support sidekiq 3 interface (thx davekaro)
44
-
45
- 0.3.6
46
- -----
47
- * Added method `set_current_tenant_by_subdomain_or_domain` (thx preth00nker)
48
-
49
- 0.3.5
50
- -----
51
- * Fix to degredation introduced after 3.1 that prevented tenant_id from being set during initialization (thx jorgevaldivia)
52
-
53
- 0.3.4
54
- -----
55
- * Fix to a bug introduced in 0.3.2
56
-
57
- 0.3.3
58
- -----
59
- * Support user defined foreign keys on scoped models
60
-
61
- 0.3.2
62
- -----
63
- * correctly support nested models with has_many :through (thx dexion)
64
- * Support 'www.subdomain.example.com' (thx wtfiwtz)
65
- * Support setting `tenant_id` on scoped models if the `tenant_id` is nil (thx Matt Wilson)
66
-
67
- 0.3.1
68
- -----
69
- * Added support for Rails 4
70
-
71
- 0.3.0
72
- -----
73
- * You can now raise an exception if a query on a scope model is made without a tenant set. Adding an initializer that sets config.require_tenant to true will accomplish this. See readme for more details.
74
- * `ActsAsTenant.with_tenant` will now return the value of the block it evaluates instead of the original tenant. The original tenant is restored automatically.
75
- * acts_as_tenant now raises standard errors which can be caught individually.
76
- * `set_current_tenant_to`, which was deprecated some versions ago and could lead to weird errors, has been removed.
77
-
78
-
79
- 0.2.9
80
- -----
81
- * Added support for many-to-many associations (thx Nucleoid)
82
-
83
- 0.2.8
84
- -----
85
- * Added dependencies to gemspec (thx aaronrenner)
86
- * Added the `ActsAsTenant.with_tenant` block method (see readme) (thx aaronrenner)
87
- * Acts_as_Tenant is now thread safe (thx davide)
88
-
89
- 0.2.7
90
- -----
91
- * Changed the interface for passing in the current_tenant manually in the controller. `set_current_tenant_to` has been deprecated and replaced by `set_current_tenant_through_filter` declaration and the `set_current_tenant` method. See readme for details.
92
-
93
- 0.2.6
94
- -----
95
- * Fixed a bug with resolving the tenant model name (thx devton!)
96
- * Added support for using relations: User.create(:account => Account.first) now works, while it wouldn't before (thx bnmrrs)
97
-
98
- 0.2.5
99
- -----
100
- * Added Rails 3.2 compatibility (thx nickveys!)
101
-
102
- 0.2.4
103
- -----
104
- * Added correct handling of child models that do not have their parent set (foreign key == nil)
105
-
106
-
107
- 0.2.3
108
- -----
109
- * Added support for models that declare a has_one relationships, these would error out in the previous versions.
110
-
111
-
112
- 0.2.2
113
- -----
114
- * Enhancements
115
- * Added support for aliased associations ( belongs_to :something, :class_name => 'SomethingElse'). In previous version these would raise an 'uninitialized constant' error.
116
-
117
- 0.2.1
118
- -----
119
- * Initial release
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in acts_as_tenant.gemspec
4
- gemspec
data/_config.yml DELETED
@@ -1 +0,0 @@
1
- theme: jekyll-theme-tactile
@@ -1,32 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "acts_as_tenant/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "acts_as_tenant"
7
- s.version = ActsAsTenant::VERSION
8
- s.authors = ["Erwin Matthijssen"]
9
- s.email = ["erwin.matthijssen@gmail.com"]
10
- s.homepage = "http://www.rollcallapp.com/blog"
11
- s.summary = %q{Add multi-tenancy to Rails applications using a shared db strategy}
12
- s.description = %q{Integrates multi-tenancy into a Rails application in a convenient and out-of-your way manner}
13
-
14
- s.rubyforge_project = "acts_as_tenant"
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
-
21
- s.add_runtime_dependency('request_store', '>= 1.0.5')
22
- s.add_dependency('rails','>= 4.0')
23
- #s.add_dependency('request_store', '>= 1.0.5')
24
-
25
- s.add_development_dependency('rspec', '>=3.0')
26
- s.add_development_dependency('rspec-rails')
27
- s.add_development_dependency('database_cleaner', '~> 1.7')
28
- s.add_development_dependency('sqlite3')
29
- #s.add_development_dependency('mongoid', '~> 4.0')
30
-
31
- s.add_development_dependency('sidekiq', '3.2.1')
32
- end
data/docs/blog_post.md DELETED
@@ -1,67 +0,0 @@
1
- <h2> Adding multi-tenancy to your Rails app: acts_as_tenant </h2>
2
- Roll Call is implemented as a multi-tenant application: each user gets their own instance of the app, content is strictly scoped to a user&#8217;s instance. In Rails, this can be achieved in various ways. Guy Naor did a great job of diving into the pros and cons of each option in his <a href="http://confreaks.net/videos/111-aac2009-writing-multi-tenant-applications-in-rails">2009 Acts As Conference talk</a>. If you are doing multi-tenancy in Rails, you should watch his video.</p>
3
- <p>With a multi-db or multi-schema approach, you only deal with the multi-tenancy-aspect in a few specific spots in your app (Jerod Santo recently wrote an excellent post on implementing a <a href="http://blog.jerodsanto.net/2011/07/building-multi-tenant-rails-apps-with-postgresql-schemas/">multi-schema strategy</a>). Compared to the previous two strategies, a <strong>shared database</strong> strategy has the downside that the &#8216;multi-tenancy&#8217;-logic is something you need to actively be aware of and manage in almost every part of your app.</p>
4
- <h4>Using a Shared Database strategy is alot of work!</h4>
5
- <p>For various other reasons we opted for a <strong>shared database</strong> strategy. However, for us the prospect of dealing with the multi-tenancy-logic throughout our app, was not appealing. Worse, we run the risk of accidently exposing content of one tenant to another one, if we mismanage this logic. While researching this topic I noticed there are no real ready made solutions available that get you on your way, <a href="http://github.com/wireframe/multitenant">Ryan Sonnek</a> wrote his &#8216;multitenant&#8217; gem and <a href="http://github.com/mconnell/multi_tenant">Mark Connel</a> did the same. Neither of these solution seemed &#8220;finished&#8221; to us. So, we wrote our own implementation.</p>
6
- <h4>First, how does multi-tenancy with a shared database strategy work</h4>
7
- <p>A shared database strategy manages the multi-tenancy-logic through Rails associations. A tenant is represented by an object, for example an <code>Account</code>. All other objects are associated with a tenant: <code>belongs_to :account</code>. Each request starts with finding the <code>@current_account</code>. After that, each find is scoped through the tenant object: <code>current_account.projects.all</code>. This has to be remembered everywhere: in model method declarations and in controller actions. Otherwise, you&#8217;re exposing content of other tenants.</p>
8
- <p>In addition, you have to actively babysit other parts of your app: <code>validates_uniqueness_of</code> requires you to scope it to the current tenant. You also have to protect agaist all sorts of form-injections that could allow one tenant to gain access or temper with the content of another tenant (see <a href="http://www.slideshare.net/tardate/multitenancy-with-rails">Paul Gallaghers</a> presentation for more on these dangers).</p>
9
- <h4>Enter acts_as_tenant</h4>
10
- <p>I wanted to implement all the concerns above in an easy to manage, out of the way fashion. We should be able to add a single declaration to our model and that should implement:</p>
11
- <ol>
12
- <li>scoping all searches to the current <code>Account</code></li>
13
- <li>scoping the uniqueness validator to the current <code>Account</code></li>
14
- <li>protecting against various nastiness trying to circumvent the scoping.</li>
15
- </ol>
16
- <p>The result is <code>acts_as_tenant</code> (<a href="https://github.com/ErwinM/acts_as_tenant">github</a>), a rails gem that will add multi tenancy using a shared database to your rails app in an out-of-your way fashion.</p>
17
- <p>In the <span class="caps">README</span>, you will find more information on using <code>acts_as_tenant</code> in your projects, so we&#8217;ll give you a high-level overview here. Let&#8217;s suppose that you have an app to which you want to add multi tenancy, tenants are represented by the <code>Account</code> model and <code>Project</code> is one of the models that should be scoped by tenant:</p>
18
-
19
- ```ruby
20
- class Addaccounttoproject < ActiveRecord::Migration
21
- def change
22
- add_column :projects, :account_id, :integer
23
- end
24
- end
25
-
26
- class Project < ActiveRecord::Base
27
- acts_as_tenant(:account)
28
- validates_uniqueness_to_tenant :name
29
- end
30
- ```
31
- What does adding these two methods accomplish:
32
- <ol>
33
- <li>it ensures every search on the project model will be scoped to the current tenant,</li>
34
- <li>it adds validation for every association confirming the associated object does indeed belong to the current tenant,</li>
35
- <li>it validates the uniqueness of `:name` to the current tenant,</li>
36
- <li>it implements a bunch of safeguards preventing all kinds of nastiness from exposing other tenants data (mainly form-injection attacks).</li>
37
- </ol>
38
- <p>Ofcourse, all the above assumes `acts_as_tenant` actually knows who the current tenant is. Two strategies are implemented to help with this.</p>
39
- <p><strong>Using the subdomain to workout the current tenant</strong></p>
40
-
41
- ```ruby
42
- class ApplicationController < ActionController::Base
43
- set_current_tenant_by_subdomain(:account, :subdomain)
44
- end
45
- ```
46
- <p>Adding the above method to your `application_controller` tells `acts_as_tenant`:</p>
47
- <ol>
48
- <li>the current tenant should be found based on the subdomain (e.g. account1.myappdomain.com),</li>
49
- <li>tenants are represented by the `Account`-model and</li>
50
- <li>the `Account` model has a column named `subdomain` that should be used the lookup the current account, using the current subdomain.</li>
51
- </ol>
52
- <p><strong>Passing the current account to acts_as_tenant yourself</strong></p>
53
-
54
- ```ruby
55
- class ApplicationController < ActionController::Base
56
- current_account = Account.method_to_find_the_current_account
57
- set_current_tenant_to(current_account)
58
- end
59
- ```
60
- <p>`Acts_as_tenant` also adds a handy helper to your controllers `current_tenant`, containing the current tenant object.</p>
61
- <h4>Great! Anything else I should know? A few caveats:</h4>
62
- <ul>
63
- <li>scoping of models *only* works if `acts_as_tenant` has a current_tenant available. If you do not set one by one of the methods described above, *no scope* will be applied!</li>
64
- <li>for validating uniqueness within a tenant scope you must use the `validates_uniqueness_to_tenant`method. This method takes all the options the regular `validates_uniqueness_of` method takes.</li>
65
- <li>it is probably best to add the `acts_as_tenant` declaration after any other `default_scope` declarations you add to a model (I am not exactly sure how rails 3 handles the chaining. If someone can enlighten me, thanks!).</li>
66
- </ul>
67
- <p>We have been testing <a href="https://github.com/ErwinM/acts_as_tenant">acts_as_tenant</a> within Roll Call during recent weeks and it seems to be behaving well. Having said that, we welcome any feedback. This is my first real attempt at a plugin and the possibility of various improvements is almost a given.</p>
data/rails/init.rb DELETED
@@ -1,2 +0,0 @@
1
- ActiveRecord::Base.send(:include, ActsAsTenant::ModelExtensions)
2
- ActionController::Base.extend ActsAsTenant::ControllerExtensions
@@ -1,22 +0,0 @@
1
- require 'rails/all'
2
- require 'database_cleaner'
3
- require 'yaml'
4
-
5
- dbconfig = YAML::load(IO.read(File.join(File.dirname(__FILE__), 'database.yml')))
6
- ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
7
- ActiveRecord::Base.establish_connection(dbconfig[ENV['DB'] || 'sqlite'])
8
-
9
- RSpec.configure do |config|
10
- config.before(:suite) do
11
- DatabaseCleaner[:active_record].strategy = :transaction
12
- DatabaseCleaner[:active_record].clean_with(:truncation)
13
- end
14
-
15
- config.before(:each) do
16
- DatabaseCleaner[:active_record].start
17
- end
18
-
19
- config.after(:each) do
20
- DatabaseCleaner[:active_record].clean
21
- end
22
- end
@@ -1,143 +0,0 @@
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 :articles, :force => true do |t|
53
- t.column :title, :string
54
- end
55
-
56
- create_table :comments, :force => true do |t|
57
- t.column :commentable_id, :integer
58
- t.column :commentable_type, :string
59
- t.column :account_id, :integer
60
- end
61
-
62
- create_table :polymorphic_tenant_comments, :force => true do |t|
63
- t.column :polymorphic_tenant_commentable_id, :integer
64
- t.column :polymorphic_tenant_commentable_type, :string
65
- t.column :account_id, :integer
66
- end
67
-
68
- end
69
-
70
- class Account < ActiveRecord::Base
71
- has_many :projects
72
- end
73
-
74
- class Project < ActiveRecord::Base
75
- has_one :manager
76
- has_many :tasks
77
- has_many :polymorphic_tenant_comments, as: :polymorphic_tenant_commentable
78
- acts_as_tenant :account
79
-
80
- validates_uniqueness_to_tenant :name
81
- end
82
-
83
- class Manager < ActiveRecord::Base
84
- belongs_to :project
85
- acts_as_tenant :account
86
- end
87
-
88
- class Task < ActiveRecord::Base
89
- belongs_to :project
90
- default_scope -> { where(:completed => nil).order("name") }
91
-
92
- acts_as_tenant :account
93
- validates_uniqueness_of :name
94
- end
95
-
96
- class UnscopedModel < ActiveRecord::Base
97
- validates_uniqueness_of :name
98
- end
99
-
100
- class AliasedTask < ActiveRecord::Base
101
- acts_as_tenant(:account)
102
- belongs_to :project_alias, :class_name => "Project"
103
- end
104
-
105
- class UniqueTask < ActiveRecord::Base
106
- acts_as_tenant(:account)
107
- belongs_to :project
108
- validates_uniqueness_to_tenant :name, scope: :user_defined_scope
109
- end
110
-
111
- class CustomForeignKeyTask < ActiveRecord::Base
112
- acts_as_tenant(:account, :foreign_key => "accountID")
113
- validates_uniqueness_to_tenant :name
114
- end
115
-
116
- class CustomPrimaryKeyTask < ActiveRecord::Base
117
- self.table_name = 'projects'
118
- acts_as_tenant(:account, :foreign_key => "name", :primary_key => "name")
119
- validates_presence_of :name
120
- end
121
-
122
- class Comment < ActiveRecord::Base
123
- belongs_to :commentable, polymorphic: true
124
- belongs_to :task, -> { where(comments: { commentable_type: 'Task' }) }, foreign_key: 'commentable_id'
125
- acts_as_tenant :account
126
- end
127
-
128
- class Article < ActiveRecord::Base
129
- has_many :polymorphic_tenant_comments, as: :polymorphic_tenant_commentable
130
- end
131
-
132
- class PolymorphicTenantComment < ActiveRecord::Base
133
- belongs_to :polymorphic_tenant_commentable, polymorphic: true
134
- belongs_to :account
135
- acts_as_tenant :polymorphic_tenant_commentable, polymorphic: true
136
- end
137
-
138
- class GlobalProject < ActiveRecord::Base
139
- self.table_name = 'projects'
140
-
141
- acts_as_tenant :account, has_global_records: true
142
- validates_uniqueness_to_tenant :name
143
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActsAsTenant::Configuration do
4
- describe 'no configuration given' do
5
- before do
6
- ActsAsTenant.configure
7
- end
8
-
9
- it 'provides defaults' do
10
- expect(ActsAsTenant.configuration.require_tenant).not_to be_truthy
11
- end
12
- end
13
-
14
- describe 'with config block' do
15
- after do
16
- ActsAsTenant.configure
17
- end
18
-
19
- it 'stores config' do
20
- ActsAsTenant.configure do |config|
21
- config.require_tenant = true
22
- end
23
-
24
- expect(ActsAsTenant.configuration.require_tenant).to eq(true)
25
- end
26
-
27
- end
28
- end