acts_as_tenant 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +40 -4
  3. data/lib/acts_as_tenant/errors.rb +0 -3
  4. data/lib/acts_as_tenant/model_extensions.rb +16 -6
  5. data/lib/acts_as_tenant/version.rb +1 -1
  6. data/lib/acts_as_tenant.rb +19 -1
  7. metadata +4 -170
  8. data/spec/acts_as_tenant/configuration_spec.rb +0 -17
  9. data/spec/acts_as_tenant/sidekiq_spec.rb +0 -58
  10. data/spec/controllers/filter_spec.rb +0 -28
  11. data/spec/controllers/subdomain_or_domain_spec.rb +0 -55
  12. data/spec/controllers/subdomain_spec.rb +0 -49
  13. data/spec/dummy/.ruby-version +0 -1
  14. data/spec/dummy/Rakefile +0 -6
  15. data/spec/dummy/app/assets/config/manifest.js +0 -2
  16. data/spec/dummy/app/assets/images/.keep +0 -0
  17. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  18. data/spec/dummy/app/channels/application_cable/channel.rb +0 -4
  19. data/spec/dummy/app/channels/application_cable/connection.rb +0 -4
  20. data/spec/dummy/app/controllers/application_controller.rb +0 -2
  21. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  22. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  23. data/spec/dummy/app/javascript/packs/application.js +0 -15
  24. data/spec/dummy/app/jobs/application_job.rb +0 -7
  25. data/spec/dummy/app/mailers/application_mailer.rb +0 -4
  26. data/spec/dummy/app/mailers/user_mailer.rb +0 -5
  27. data/spec/dummy/app/models/account.rb +0 -4
  28. data/spec/dummy/app/models/aliased_task.rb +0 -4
  29. data/spec/dummy/app/models/article.rb +0 -3
  30. data/spec/dummy/app/models/comment.rb +0 -5
  31. data/spec/dummy/app/models/concerns/.keep +0 -0
  32. data/spec/dummy/app/models/custom_counter_cache_task.rb +0 -4
  33. data/spec/dummy/app/models/custom_foreign_key_task.rb +0 -4
  34. data/spec/dummy/app/models/custom_primary_key_task.rb +0 -4
  35. data/spec/dummy/app/models/global_project.rb +0 -6
  36. data/spec/dummy/app/models/global_project_with_conditions.rb +0 -6
  37. data/spec/dummy/app/models/global_project_with_if.rb +0 -6
  38. data/spec/dummy/app/models/manager.rb +0 -4
  39. data/spec/dummy/app/models/polymorphic_tenant_comment.rb +0 -5
  40. data/spec/dummy/app/models/project.rb +0 -8
  41. data/spec/dummy/app/models/task.rb +0 -7
  42. data/spec/dummy/app/models/unique_task.rb +0 -5
  43. data/spec/dummy/app/models/unscoped_model.rb +0 -3
  44. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  45. data/spec/dummy/app/views/layouts/mailer.html.erb +0 -13
  46. data/spec/dummy/app/views/layouts/mailer.text.erb +0 -1
  47. data/spec/dummy/bin/rails +0 -4
  48. data/spec/dummy/bin/rake +0 -4
  49. data/spec/dummy/bin/setup +0 -33
  50. data/spec/dummy/config/application.rb +0 -19
  51. data/spec/dummy/config/boot.rb +0 -5
  52. data/spec/dummy/config/cable.yml +0 -10
  53. data/spec/dummy/config/database.yml +0 -19
  54. data/spec/dummy/config/environment.rb +0 -5
  55. data/spec/dummy/config/environments/development.rb +0 -62
  56. data/spec/dummy/config/environments/production.rb +0 -112
  57. data/spec/dummy/config/environments/test.rb +0 -49
  58. data/spec/dummy/config/initializers/application_controller_renderer.rb +0 -8
  59. data/spec/dummy/config/initializers/assets.rb +0 -12
  60. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  61. data/spec/dummy/config/initializers/content_security_policy.rb +0 -28
  62. data/spec/dummy/config/initializers/cookies_serializer.rb +0 -5
  63. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  64. data/spec/dummy/config/initializers/inflections.rb +0 -16
  65. data/spec/dummy/config/initializers/mime_types.rb +0 -4
  66. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  67. data/spec/dummy/config/locales/en.yml +0 -40
  68. data/spec/dummy/config/puma.rb +0 -38
  69. data/spec/dummy/config/routes.rb +0 -4
  70. data/spec/dummy/config/spring.rb +0 -6
  71. data/spec/dummy/config/storage.yml +0 -34
  72. data/spec/dummy/config.ru +0 -5
  73. data/spec/dummy/db/schema.rb +0 -84
  74. data/spec/dummy/lib/assets/.keep +0 -0
  75. data/spec/dummy/log/.keep +0 -0
  76. data/spec/dummy/public/404.html +0 -67
  77. data/spec/dummy/public/422.html +0 -67
  78. data/spec/dummy/public/500.html +0 -66
  79. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  80. data/spec/dummy/public/apple-touch-icon.png +0 -0
  81. data/spec/dummy/public/favicon.ico +0 -0
  82. data/spec/dummy/tmp/development_secret.txt +0 -1
  83. data/spec/fixtures/accounts.yml +0 -10
  84. data/spec/fixtures/custom_primary_key_tasks.yml +0 -2
  85. data/spec/fixtures/global_projects.yml +0 -13
  86. data/spec/fixtures/projects.yml +0 -10
  87. data/spec/helpers/tenant_helper_spec.rb +0 -16
  88. data/spec/middlewares/test_tenant_middleware_spec.rb +0 -86
  89. data/spec/models/model_extensions_spec.rb +0 -413
  90. data/spec/spec_helper.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9dbb40015b39583a44c37496f0687641e1a66f9b70357260b1fcabe7f3c542d
4
- data.tar.gz: 88d1ce36220fd3c8e8264b95d76afb7f883cc77da0ac9f12538cde682fa9dacf
3
+ metadata.gz: 82765cfa1d00a63aa012f3ab5de9ddd60ae2c8041df405e08ae70ef20382d7ee
4
+ data.tar.gz: ba1920a299f84a4e6424304539c05ca69515e3b17e73ffb1b6635fbce79ae77c
5
5
  SHA512:
6
- metadata.gz: 7d76fbf4cc3381afdfa2c02627ad6de56ff9e4cdaa636da4103e11e38ee48a6f6ecf3f432f296bfd3b8ae5cfc690d8fc52cbc7e025953e39cf3b3dab4439d3f1
7
- data.tar.gz: ba09cb46b06f2399de2ac2e4d6efa3369d22e287a6741bfd0fcfc483836b64ac96851dd671dd4a97bace409c7aa72f6e7fc03394250f853c55a54159e720118a
6
+ metadata.gz: 62854b28ba5293d5437f5614032e992d914bc0741be3e8b925231116802d85b19d9631fc2e0ff2a7775e3259a998e4239f0b38c7ddf97c6817a0db96fbf488c5
7
+ data.tar.gz: 2e6c875895dd15882ffc4454f0c0bfae4fc3e77df17deae58710835e92bf32761247ab3b60cdfe9a83b81f72e2ea698c59f0155c046dfe2af5c62450a4bd65ca
data/README.md CHANGED
@@ -25,7 +25,7 @@ Row-level multitenancy each model must have a tenant ID column on it. This make
25
25
 
26
26
  Schema multitenancy uses database schemas to handle multitenancy. For this approach, your database has multiple schemas and each schema contains your database tables. Schemas require migrations to be run against each tenant and generally makes it harder to scale as you add more tenants. The Apartment gem uses schema multitenancy.
27
27
 
28
- #### 🎬 Walkthrough
28
+ #### 🎬 Walkthrough
29
29
 
30
30
  Want to see how it works? Check out [the ActsAsTenant walkthrough video](https://www.youtube.com/watch?v=BIyxM9f8Jus):
31
31
 
@@ -101,7 +101,7 @@ Setting the `current_tenant` yourself, requires you to declare `set_current_tena
101
101
 
102
102
  If you are setting the tenant in a specific controller (except `application_controller`), it should to be included **AT THE TOP** of the file.
103
103
 
104
- ```
104
+ ```ruby
105
105
  class MembersController < ActionController::Base
106
106
  set_current_tenant_through_filter
107
107
  before_action :set_tenant
@@ -210,6 +210,28 @@ You can also explicitly specifiy a primary_key for AaT to use should the key dif
210
210
  acts_as_tenant(:account, :primary_key => 'primaryID') # by default AaT expects id
211
211
  ```
212
212
 
213
+
214
+ ### Has and belongs to many ###
215
+
216
+ You can scope a model that is part of a HABTM relationship by using the `through` option.
217
+
218
+ ```ruby
219
+ class Organisation < ActiveRecord::Base
220
+ has_many :organisations_users
221
+ has_many :users, through: :organisations_users
222
+ end
223
+
224
+ class User < ActiveRecord::Base
225
+ has_many :organisations_users
226
+ acts_as_tenant :organisation, through: :organisations_users
227
+ end
228
+
229
+ class OrganisationsUser < ActiveRecord::Base
230
+ belongs_to :user
231
+ acts_as_tenant :organisation
232
+ end
233
+ ```
234
+
213
235
  Configuration options
214
236
  ---------------------
215
237
  An initializer can be created to control (currently one) option in ActsAsTenant. Defaults
@@ -223,12 +245,26 @@ end
223
245
 
224
246
  * `config.require_tenant` when set to true will raise an ActsAsTenant::NoTenant error whenever a query is made without a tenant set.
225
247
 
248
+ `config.require_tenant` can also be assigned a lambda that is evaluated at run time. For example:
249
+
250
+ ```ruby
251
+ ActsAsTenant.configure do |config|
252
+ config.require_tenant = lambda do
253
+ if $request_env.present?
254
+ return false if $request_env["REQUEST_PATH"].start_with?("/admin/")
255
+ end
256
+ end
257
+ end
258
+ ```
259
+
260
+ `ActsAsTenant.should_require_tenant?` is used to determine if a tenant is required in the current context, either by evaluating the lambda provided, or by returning the boolean value assigned to `config.require_tenant`.
261
+
226
262
  belongs_to options
227
263
  ---------------------
228
- `acts_as_tenant :account` includes the belongs_to relationship.
264
+ `acts_as_tenant :account` includes the belongs_to relationship.
229
265
  So when using acts_as_tenant on a model, do not add `belongs_to :account` alongside `acts_as_tenant :account`:
230
266
 
231
- ```
267
+ ```ruby
232
268
  class User < ActiveRecord::Base
233
269
  acts_as_tenant(:account) # YES
234
270
  belongs_to :account # REDUNDANT
@@ -9,9 +9,6 @@ module ActsAsTenant
9
9
  class NoTenantSet < ActsAsTenant::Error
10
10
  end
11
11
 
12
- class ModelNotScopedByTenant < ActsAsTenant::Error
13
- end
14
-
15
12
  class TenantIsImmutable < ActsAsTenant::Error
16
13
  end
17
14
  end
@@ -16,7 +16,7 @@ module ActsAsTenant
16
16
  belongs_to tenant, **valid_options
17
17
 
18
18
  default_scope lambda {
19
- if ActsAsTenant.configuration.require_tenant && ActsAsTenant.current_tenant.nil? && !ActsAsTenant.unscoped?
19
+ if ActsAsTenant.should_require_tenant? && ActsAsTenant.current_tenant.nil? && !ActsAsTenant.unscoped?
20
20
  raise ActsAsTenant::Errors::NoTenantSet
21
21
  end
22
22
 
@@ -24,9 +24,15 @@ module ActsAsTenant
24
24
  keys = [ActsAsTenant.current_tenant.send(pkey)].compact
25
25
  keys.push(nil) if options[:has_global_records]
26
26
 
27
- query_criteria = {fkey.to_sym => keys}
28
- query_criteria[polymorphic_type.to_sym] = ActsAsTenant.current_tenant.class.to_s if options[:polymorphic]
29
- where(query_criteria)
27
+ if options[:through]
28
+ query_criteria = {options[:through] => {fkey.to_sym => keys}}
29
+ query_criteria[polymorphic_type.to_sym] = ActsAsTenant.current_tenant.class.to_s if options[:polymorphic]
30
+ joins(options[:through]).where(query_criteria)
31
+ else
32
+ query_criteria = {fkey.to_sym => keys}
33
+ query_criteria[polymorphic_type.to_sym] = ActsAsTenant.current_tenant.class.to_s if options[:polymorphic]
34
+ where(query_criteria)
35
+ end
30
36
  else
31
37
  all
32
38
  end
@@ -71,15 +77,19 @@ module ActsAsTenant
71
77
  to_include = Module.new {
72
78
  define_method "#{fkey}=" do |integer|
73
79
  write_attribute(fkey.to_s, integer)
74
- raise ActsAsTenant::Errors::TenantIsImmutable if send("#{fkey}_changed?") && persisted? && !send("#{fkey}_was").nil?
80
+ raise ActsAsTenant::Errors::TenantIsImmutable if tenant_modified?
75
81
  integer
76
82
  end
77
83
 
78
84
  define_method "#{ActsAsTenant.tenant_klass}=" do |model|
79
85
  super(model)
80
- raise ActsAsTenant::Errors::TenantIsImmutable if send("#{fkey}_changed?") && persisted? && !send("#{fkey}_was").nil?
86
+ raise ActsAsTenant::Errors::TenantIsImmutable if tenant_modified?
81
87
  model
82
88
  end
89
+
90
+ define_method :tenant_modified? do
91
+ will_save_change_to_attribute?(fkey) && persisted? && attribute_in_database(fkey).present?
92
+ end
83
93
  }
84
94
  include to_include
85
95
 
@@ -1,3 +1,3 @@
1
1
  module ActsAsTenant
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -14,7 +14,6 @@ module ActsAsTenant
14
14
  @@models_with_global_records = []
15
15
 
16
16
  class << self
17
- attr_accessor :test_tenant
18
17
  attr_writer :default_tenant
19
18
  end
20
19
 
@@ -64,6 +63,14 @@ module ActsAsTenant
64
63
  RequestStore.store[:current_tenant] || test_tenant || default_tenant
65
64
  end
66
65
 
66
+ def self.test_tenant=(tenant)
67
+ Thread.current[:test_tenant] = tenant
68
+ end
69
+
70
+ def self.test_tenant
71
+ Thread.current[:test_tenant]
72
+ end
73
+
67
74
  def self.unscoped=(unscoped)
68
75
  RequestStore.store[:acts_as_tenant_unscoped] = unscoped
69
76
  end
@@ -99,16 +106,27 @@ module ActsAsTenant
99
106
  end
100
107
 
101
108
  old_tenant = current_tenant
109
+ old_test_tenant = test_tenant
102
110
  old_unscoped = unscoped
103
111
 
104
112
  self.current_tenant = nil
113
+ self.test_tenant = nil
105
114
  self.unscoped = true
106
115
  value = block.call
107
116
  value
108
117
  ensure
109
118
  self.current_tenant = old_tenant
119
+ self.test_tenant = old_test_tenant
110
120
  self.unscoped = old_unscoped
111
121
  end
122
+
123
+ def self.should_require_tenant?
124
+ if configuration.require_tenant.respond_to?(:call)
125
+ !!configuration.require_tenant.call
126
+ else
127
+ !!configuration.require_tenant
128
+ end
129
+ end
112
130
  end
113
131
 
114
132
  ActiveSupport.on_load(:active_record) do |base|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_tenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Matthijssen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-09-09 00:00:00.000000000 Z
12
+ date: 2022-09-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: request_store
@@ -153,89 +153,6 @@ files:
153
153
  - lib/acts_as_tenant/tenant_helper.rb
154
154
  - lib/acts_as_tenant/test_tenant_middleware.rb
155
155
  - lib/acts_as_tenant/version.rb
156
- - spec/acts_as_tenant/configuration_spec.rb
157
- - spec/acts_as_tenant/sidekiq_spec.rb
158
- - spec/controllers/filter_spec.rb
159
- - spec/controllers/subdomain_or_domain_spec.rb
160
- - spec/controllers/subdomain_spec.rb
161
- - spec/dummy/.ruby-version
162
- - spec/dummy/Rakefile
163
- - spec/dummy/app/assets/config/manifest.js
164
- - spec/dummy/app/assets/images/.keep
165
- - spec/dummy/app/assets/stylesheets/application.css
166
- - spec/dummy/app/channels/application_cable/channel.rb
167
- - spec/dummy/app/channels/application_cable/connection.rb
168
- - spec/dummy/app/controllers/application_controller.rb
169
- - spec/dummy/app/controllers/concerns/.keep
170
- - spec/dummy/app/helpers/application_helper.rb
171
- - spec/dummy/app/javascript/packs/application.js
172
- - spec/dummy/app/jobs/application_job.rb
173
- - spec/dummy/app/mailers/application_mailer.rb
174
- - spec/dummy/app/mailers/user_mailer.rb
175
- - spec/dummy/app/models/account.rb
176
- - spec/dummy/app/models/aliased_task.rb
177
- - spec/dummy/app/models/article.rb
178
- - spec/dummy/app/models/comment.rb
179
- - spec/dummy/app/models/concerns/.keep
180
- - spec/dummy/app/models/custom_counter_cache_task.rb
181
- - spec/dummy/app/models/custom_foreign_key_task.rb
182
- - spec/dummy/app/models/custom_primary_key_task.rb
183
- - spec/dummy/app/models/global_project.rb
184
- - spec/dummy/app/models/global_project_with_conditions.rb
185
- - spec/dummy/app/models/global_project_with_if.rb
186
- - spec/dummy/app/models/manager.rb
187
- - spec/dummy/app/models/polymorphic_tenant_comment.rb
188
- - spec/dummy/app/models/project.rb
189
- - spec/dummy/app/models/task.rb
190
- - spec/dummy/app/models/unique_task.rb
191
- - spec/dummy/app/models/unscoped_model.rb
192
- - spec/dummy/app/views/layouts/application.html.erb
193
- - spec/dummy/app/views/layouts/mailer.html.erb
194
- - spec/dummy/app/views/layouts/mailer.text.erb
195
- - spec/dummy/bin/rails
196
- - spec/dummy/bin/rake
197
- - spec/dummy/bin/setup
198
- - spec/dummy/config.ru
199
- - spec/dummy/config/application.rb
200
- - spec/dummy/config/boot.rb
201
- - spec/dummy/config/cable.yml
202
- - spec/dummy/config/database.yml
203
- - spec/dummy/config/environment.rb
204
- - spec/dummy/config/environments/development.rb
205
- - spec/dummy/config/environments/production.rb
206
- - spec/dummy/config/environments/test.rb
207
- - spec/dummy/config/initializers/application_controller_renderer.rb
208
- - spec/dummy/config/initializers/assets.rb
209
- - spec/dummy/config/initializers/backtrace_silencers.rb
210
- - spec/dummy/config/initializers/content_security_policy.rb
211
- - spec/dummy/config/initializers/cookies_serializer.rb
212
- - spec/dummy/config/initializers/filter_parameter_logging.rb
213
- - spec/dummy/config/initializers/inflections.rb
214
- - spec/dummy/config/initializers/mime_types.rb
215
- - spec/dummy/config/initializers/wrap_parameters.rb
216
- - spec/dummy/config/locales/en.yml
217
- - spec/dummy/config/puma.rb
218
- - spec/dummy/config/routes.rb
219
- - spec/dummy/config/spring.rb
220
- - spec/dummy/config/storage.yml
221
- - spec/dummy/db/schema.rb
222
- - spec/dummy/lib/assets/.keep
223
- - spec/dummy/log/.keep
224
- - spec/dummy/public/404.html
225
- - spec/dummy/public/422.html
226
- - spec/dummy/public/500.html
227
- - spec/dummy/public/apple-touch-icon-precomposed.png
228
- - spec/dummy/public/apple-touch-icon.png
229
- - spec/dummy/public/favicon.ico
230
- - spec/dummy/tmp/development_secret.txt
231
- - spec/fixtures/accounts.yml
232
- - spec/fixtures/custom_primary_key_tasks.yml
233
- - spec/fixtures/global_projects.yml
234
- - spec/fixtures/projects.yml
235
- - spec/helpers/tenant_helper_spec.rb
236
- - spec/middlewares/test_tenant_middleware_spec.rb
237
- - spec/models/model_extensions_spec.rb
238
- - spec/spec_helper.rb
239
156
  homepage: https://github.com/ErwinM/acts_as_tenant
240
157
  licenses: []
241
158
  metadata: {}
@@ -254,91 +171,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
171
  - !ruby/object:Gem::Version
255
172
  version: '0'
256
173
  requirements: []
257
- rubygems_version: 3.2.22
174
+ rubygems_version: 3.3.7
258
175
  signing_key:
259
176
  specification_version: 4
260
177
  summary: Add multi-tenancy to Rails applications using a shared db strategy
261
- test_files:
262
- - spec/acts_as_tenant/configuration_spec.rb
263
- - spec/acts_as_tenant/sidekiq_spec.rb
264
- - spec/controllers/filter_spec.rb
265
- - spec/controllers/subdomain_or_domain_spec.rb
266
- - spec/controllers/subdomain_spec.rb
267
- - spec/dummy/.ruby-version
268
- - spec/dummy/Rakefile
269
- - spec/dummy/app/assets/config/manifest.js
270
- - spec/dummy/app/assets/images/.keep
271
- - spec/dummy/app/assets/stylesheets/application.css
272
- - spec/dummy/app/channels/application_cable/channel.rb
273
- - spec/dummy/app/channels/application_cable/connection.rb
274
- - spec/dummy/app/controllers/application_controller.rb
275
- - spec/dummy/app/controllers/concerns/.keep
276
- - spec/dummy/app/helpers/application_helper.rb
277
- - spec/dummy/app/javascript/packs/application.js
278
- - spec/dummy/app/jobs/application_job.rb
279
- - spec/dummy/app/mailers/application_mailer.rb
280
- - spec/dummy/app/mailers/user_mailer.rb
281
- - spec/dummy/app/models/account.rb
282
- - spec/dummy/app/models/aliased_task.rb
283
- - spec/dummy/app/models/article.rb
284
- - spec/dummy/app/models/comment.rb
285
- - spec/dummy/app/models/concerns/.keep
286
- - spec/dummy/app/models/custom_counter_cache_task.rb
287
- - spec/dummy/app/models/custom_foreign_key_task.rb
288
- - spec/dummy/app/models/custom_primary_key_task.rb
289
- - spec/dummy/app/models/global_project.rb
290
- - spec/dummy/app/models/global_project_with_conditions.rb
291
- - spec/dummy/app/models/global_project_with_if.rb
292
- - spec/dummy/app/models/manager.rb
293
- - spec/dummy/app/models/polymorphic_tenant_comment.rb
294
- - spec/dummy/app/models/project.rb
295
- - spec/dummy/app/models/task.rb
296
- - spec/dummy/app/models/unique_task.rb
297
- - spec/dummy/app/models/unscoped_model.rb
298
- - spec/dummy/app/views/layouts/application.html.erb
299
- - spec/dummy/app/views/layouts/mailer.html.erb
300
- - spec/dummy/app/views/layouts/mailer.text.erb
301
- - spec/dummy/bin/rails
302
- - spec/dummy/bin/rake
303
- - spec/dummy/bin/setup
304
- - spec/dummy/config.ru
305
- - spec/dummy/config/application.rb
306
- - spec/dummy/config/boot.rb
307
- - spec/dummy/config/cable.yml
308
- - spec/dummy/config/database.yml
309
- - spec/dummy/config/environment.rb
310
- - spec/dummy/config/environments/development.rb
311
- - spec/dummy/config/environments/production.rb
312
- - spec/dummy/config/environments/test.rb
313
- - spec/dummy/config/initializers/application_controller_renderer.rb
314
- - spec/dummy/config/initializers/assets.rb
315
- - spec/dummy/config/initializers/backtrace_silencers.rb
316
- - spec/dummy/config/initializers/content_security_policy.rb
317
- - spec/dummy/config/initializers/cookies_serializer.rb
318
- - spec/dummy/config/initializers/filter_parameter_logging.rb
319
- - spec/dummy/config/initializers/inflections.rb
320
- - spec/dummy/config/initializers/mime_types.rb
321
- - spec/dummy/config/initializers/wrap_parameters.rb
322
- - spec/dummy/config/locales/en.yml
323
- - spec/dummy/config/puma.rb
324
- - spec/dummy/config/routes.rb
325
- - spec/dummy/config/spring.rb
326
- - spec/dummy/config/storage.yml
327
- - spec/dummy/db/schema.rb
328
- - spec/dummy/lib/assets/.keep
329
- - spec/dummy/log/.keep
330
- - spec/dummy/public/404.html
331
- - spec/dummy/public/422.html
332
- - spec/dummy/public/500.html
333
- - spec/dummy/public/apple-touch-icon-precomposed.png
334
- - spec/dummy/public/apple-touch-icon.png
335
- - spec/dummy/public/favicon.ico
336
- - spec/dummy/tmp/development_secret.txt
337
- - spec/fixtures/accounts.yml
338
- - spec/fixtures/custom_primary_key_tasks.yml
339
- - spec/fixtures/global_projects.yml
340
- - spec/fixtures/projects.yml
341
- - spec/helpers/tenant_helper_spec.rb
342
- - spec/middlewares/test_tenant_middleware_spec.rb
343
- - spec/models/model_extensions_spec.rb
344
- - spec/spec_helper.rb
178
+ test_files: []
@@ -1,17 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ActsAsTenant::Configuration do
4
- after { ActsAsTenant.configure }
5
-
6
- it "provides defaults" do
7
- expect(ActsAsTenant.configuration.require_tenant).not_to be_truthy
8
- end
9
-
10
- it "stores config" do
11
- ActsAsTenant.configure do |config|
12
- config.require_tenant = true
13
- end
14
-
15
- expect(ActsAsTenant.configuration.require_tenant).to eq(true)
16
- end
17
- end
@@ -1,58 +0,0 @@
1
- require "spec_helper"
2
- require "sidekiq"
3
- require "acts_as_tenant/sidekiq"
4
-
5
- describe ActsAsTenant::Sidekiq do
6
- let(:account) { Account.new(id: 1234) }
7
- let(:message) { {"acts_as_tenant" => {"class" => "Account", "id" => 1234}} }
8
-
9
- describe ActsAsTenant::Sidekiq::Client do
10
- subject { ActsAsTenant::Sidekiq::Client.new }
11
-
12
- it "saves tenant if present" do
13
- ActsAsTenant.current_tenant = account
14
-
15
- msg = {}
16
- subject.call(nil, msg, nil, nil) {}
17
- expect(msg).to eq message
18
- end
19
-
20
- it "does not set tenant if not present" do
21
- expect(ActsAsTenant.current_tenant).to be_nil
22
-
23
- msg = {}
24
- subject.call(nil, msg, nil, nil) {}
25
- expect(msg).not_to eq message
26
- end
27
- end
28
-
29
- describe ActsAsTenant::Sidekiq::Server do
30
- subject { ActsAsTenant::Sidekiq::Server.new }
31
-
32
- it "restores tenant if tenant saved" do
33
- expect(Account).to receive(:find).with(1234).once { account }
34
-
35
- msg = message
36
- subject.call(nil, msg, nil) do
37
- expect(ActsAsTenant.current_tenant).to be_a_kind_of Account
38
- end
39
- expect(ActsAsTenant.current_tenant).to be_nil
40
- end
41
-
42
- it "runs without tenant if no tenant saved" do
43
- expect(Account).not_to receive(:find)
44
-
45
- msg = {}
46
- subject.call(nil, msg, nil) do
47
- expect(ActsAsTenant.current_tenant).to be_nil
48
- end
49
- expect(ActsAsTenant.current_tenant).to be_nil
50
- end
51
- end
52
-
53
- it "includes ActsAsTenant client middleware" do
54
- expect(Sidekiq.client_middleware.exists?(ActsAsTenant::Sidekiq::Client)).to eq(true)
55
- end
56
-
57
- # unable to test server configuration
58
- end
@@ -1,28 +0,0 @@
1
- require "spec_helper"
2
-
3
- class ApplicationController2 < ActionController::Base
4
- include Rails.application.routes.url_helpers
5
- set_current_tenant_through_filter
6
- before_action :your_method_that_finds_the_current_tenant
7
-
8
- def your_method_that_finds_the_current_tenant
9
- current_account = Account.new(name: "account1")
10
- set_current_tenant(current_account)
11
- end
12
- end
13
-
14
- # Start testing
15
- describe ApplicationController2, type: :controller do
16
- controller do
17
- def index
18
- # Exercise current_tenant helper method
19
- render plain: current_tenant.name
20
- end
21
- end
22
-
23
- it "Finds the correct tenant using the filter command" do
24
- get :index
25
- expect(ActsAsTenant.current_tenant.name).to eq "account1"
26
- expect(response.body).to eq "account1"
27
- end
28
- end
@@ -1,55 +0,0 @@
1
- require "spec_helper"
2
-
3
- class DomainController < ActionController::Base
4
- include Rails.application.routes.url_helpers
5
- set_current_tenant_by_subdomain_or_domain
6
- end
7
-
8
- describe DomainController, type: :controller do
9
- let(:account) { accounts(:with_domain) }
10
-
11
- controller do
12
- def index
13
- # Exercise current_tenant helper method
14
- render plain: current_tenant.name
15
- end
16
- end
17
-
18
- it "finds the correct tenant with a example1.com" do
19
- @request.host = account.domain
20
- get :index
21
- expect(ActsAsTenant.current_tenant).to eq account
22
- expect(response.body).to eq account.name
23
- end
24
-
25
- it "finds the correct tenant with a subdomain.example.com" do
26
- @request.host = "#{account.subdomain}.example.com"
27
- get :index
28
- expect(ActsAsTenant.current_tenant).to eq account
29
- expect(response.body).to eq account.name
30
- end
31
-
32
- it "finds the correct tenant with a www.subdomain.example.com" do
33
- @request.host = "www.#{account.subdomain}.example.com"
34
- get :index
35
- expect(ActsAsTenant.current_tenant).to eq account
36
- end
37
-
38
- it "ignores case when finding tenant by subdomain" do
39
- @request.host = "#{account.subdomain.upcase}.example.com"
40
- get :index
41
- expect(ActsAsTenant.current_tenant).to eq account
42
- end
43
-
44
- context "overriding subdomain lookup" do
45
- after { controller.subdomain_lookup = :last }
46
-
47
- it "allows overriding the subdomain lookup" do
48
- controller.subdomain_lookup = :first
49
- @request.host = "#{account.subdomain}.another.example.com"
50
- get :index
51
- expect(ActsAsTenant.current_tenant).to eq account
52
- expect(response.body).to eq(account.subdomain)
53
- end
54
- end
55
- end
@@ -1,49 +0,0 @@
1
- require "spec_helper"
2
-
3
- class SubdomainController < ActionController::Base
4
- include Rails.application.routes.url_helpers
5
- set_current_tenant_by_subdomain
6
- end
7
-
8
- describe SubdomainController, type: :controller do
9
- let(:account) { accounts(:with_domain) }
10
-
11
- controller(SubdomainController) do
12
- def index
13
- # Exercise current_tenant helper method
14
- render plain: current_tenant.name
15
- end
16
- end
17
-
18
- it "finds the correct tenant with a subdomain.example.com" do
19
- @request.host = "#{account.subdomain}.example.com"
20
- get :index
21
- expect(ActsAsTenant.current_tenant).to eq account
22
- expect(response.body).to eq(account.subdomain)
23
- end
24
-
25
- it "finds the correct tenant with a www.subdomain.example.com" do
26
- @request.host = "www.#{account.subdomain}.example.com"
27
- get :index
28
- expect(ActsAsTenant.current_tenant).to eq account
29
- expect(response.body).to eq(account.subdomain)
30
- end
31
-
32
- it "ignores case when finding tenant by subdomain" do
33
- @request.host = "#{account.subdomain.upcase}.example.com"
34
- get :index
35
- expect(ActsAsTenant.current_tenant).to eq account
36
- end
37
-
38
- context "overriding subdomain lookup" do
39
- after { controller.subdomain_lookup = :last }
40
-
41
- it "allows overriding the subdomain lookup" do
42
- controller.subdomain_lookup = :first
43
- @request.host = "#{account.subdomain}.another.example.com"
44
- get :index
45
- expect(ActsAsTenant.current_tenant).to eq account
46
- expect(response.body).to eq(account.subdomain)
47
- end
48
- end
49
- end
@@ -1 +0,0 @@
1
- ruby-2.7.1
data/spec/dummy/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
- require_relative "config/application"
5
-
6
- Rails.application.load_tasks
@@ -1,2 +0,0 @@
1
- //= link_tree ../images
2
- //= link_directory ../stylesheets .css
File without changes
@@ -1,15 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
- * files in this directory. Styles in this file should be added after the last require_* statement.
11
- * It is generally better to create a new file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
@@ -1,4 +0,0 @@
1
- module ApplicationCable
2
- class Channel < ActionCable::Channel::Base
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module ApplicationCable
2
- class Connection < ActionCable::Connection::Base
3
- end
4
- end
@@ -1,2 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- end
File without changes
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end