acts_as_tenant 0.4.3 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +124 -25
  3. data/Rakefile +5 -3
  4. data/lib/acts_as_tenant/configuration.rb +6 -19
  5. data/lib/acts_as_tenant/controller_extensions/filter.rb +13 -0
  6. data/lib/acts_as_tenant/controller_extensions/subdomain.rb +20 -0
  7. data/lib/acts_as_tenant/controller_extensions/subdomain_or_domain.rb +20 -0
  8. data/lib/acts_as_tenant/controller_extensions.rb +10 -59
  9. data/lib/acts_as_tenant/errors.rb +3 -4
  10. data/lib/acts_as_tenant/model_extensions.rb +59 -136
  11. data/lib/acts_as_tenant/sidekiq.rb +11 -7
  12. data/lib/acts_as_tenant/tenant_helper.rb +7 -0
  13. data/lib/acts_as_tenant/test_tenant_middleware.rb +15 -0
  14. data/lib/acts_as_tenant/version.rb +1 -1
  15. data/lib/acts_as_tenant.rb +112 -14
  16. data/spec/acts_as_tenant/configuration_spec.rb +8 -19
  17. data/spec/acts_as_tenant/sidekiq_spec.rb +14 -19
  18. data/spec/{acts_as_tenant/tenant_by_filter_spec.rb → controllers/filter_spec.rb} +7 -12
  19. data/spec/controllers/subdomain_or_domain_spec.rb +55 -0
  20. data/spec/controllers/subdomain_spec.rb +49 -0
  21. data/spec/dummy/.ruby-version +1 -0
  22. data/spec/dummy/Rakefile +6 -0
  23. data/spec/dummy/app/assets/config/manifest.js +2 -0
  24. data/spec/dummy/app/assets/images/.keep +0 -0
  25. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  26. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  27. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  29. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  30. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  31. data/spec/dummy/app/javascript/packs/application.js +15 -0
  32. data/spec/dummy/app/jobs/application_job.rb +7 -0
  33. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  34. data/spec/dummy/app/mailers/user_mailer.rb +5 -0
  35. data/spec/dummy/app/models/account.rb +4 -0
  36. data/spec/dummy/app/models/aliased_task.rb +4 -0
  37. data/spec/dummy/app/models/article.rb +3 -0
  38. data/spec/dummy/app/models/comment.rb +5 -0
  39. data/spec/dummy/app/models/concerns/.keep +0 -0
  40. data/spec/dummy/app/models/custom_counter_cache_task.rb +4 -0
  41. data/spec/dummy/app/models/custom_foreign_key_task.rb +4 -0
  42. data/spec/dummy/app/models/custom_primary_key_task.rb +4 -0
  43. data/spec/dummy/app/models/global_project.rb +6 -0
  44. data/spec/dummy/app/models/global_project_with_conditions.rb +6 -0
  45. data/spec/dummy/app/models/global_project_with_if.rb +6 -0
  46. data/spec/dummy/app/models/manager.rb +4 -0
  47. data/spec/dummy/app/models/polymorphic_tenant_comment.rb +5 -0
  48. data/spec/dummy/app/models/project.rb +8 -0
  49. data/spec/dummy/app/models/task.rb +7 -0
  50. data/spec/dummy/app/models/unique_task.rb +5 -0
  51. data/spec/dummy/app/models/unscoped_model.rb +3 -0
  52. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  53. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  54. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  55. data/spec/dummy/bin/rails +4 -0
  56. data/spec/dummy/bin/rake +4 -0
  57. data/spec/dummy/bin/setup +33 -0
  58. data/spec/dummy/config/application.rb +19 -0
  59. data/spec/dummy/config/boot.rb +5 -0
  60. data/spec/dummy/config/cable.yml +10 -0
  61. data/spec/dummy/config/database.yml +19 -0
  62. data/spec/dummy/config/environment.rb +5 -0
  63. data/spec/dummy/config/environments/development.rb +62 -0
  64. data/spec/dummy/config/environments/production.rb +112 -0
  65. data/spec/dummy/config/environments/test.rb +49 -0
  66. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  67. data/spec/dummy/config/initializers/assets.rb +12 -0
  68. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  69. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  70. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  71. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  72. data/spec/dummy/config/initializers/inflections.rb +16 -0
  73. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  74. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  75. data/spec/dummy/config/locales/en.yml +40 -0
  76. data/spec/dummy/config/puma.rb +38 -0
  77. data/spec/dummy/config/routes.rb +4 -0
  78. data/spec/dummy/config/spring.rb +6 -0
  79. data/spec/dummy/config/storage.yml +34 -0
  80. data/spec/dummy/config.ru +5 -0
  81. data/spec/dummy/db/schema.rb +84 -0
  82. data/spec/dummy/lib/assets/.keep +0 -0
  83. data/spec/dummy/log/.keep +0 -0
  84. data/spec/dummy/public/404.html +67 -0
  85. data/spec/dummy/public/422.html +67 -0
  86. data/spec/dummy/public/500.html +66 -0
  87. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  88. data/spec/dummy/public/apple-touch-icon.png +0 -0
  89. data/spec/dummy/public/favicon.ico +0 -0
  90. data/spec/dummy/tmp/development_secret.txt +1 -0
  91. data/spec/fixtures/accounts.yml +10 -0
  92. data/spec/fixtures/custom_primary_key_tasks.yml +2 -0
  93. data/spec/fixtures/global_projects.yml +13 -0
  94. data/spec/fixtures/projects.yml +10 -0
  95. data/spec/helpers/tenant_helper_spec.rb +16 -0
  96. data/spec/middlewares/test_tenant_middleware_spec.rb +86 -0
  97. data/spec/models/model_extensions_spec.rb +413 -0
  98. data/spec/spec_helper.rb +9 -13
  99. metadata +205 -41
  100. data/.gitignore +0 -7
  101. data/.travis.yml +0 -4
  102. data/CHANGELOG.md +0 -112
  103. data/Gemfile +0 -4
  104. data/_config.yml +0 -1
  105. data/acts_as_tenant.gemspec +0 -32
  106. data/docs/blog_post.md +0 -67
  107. data/rails/init.rb +0 -2
  108. data/spec/active_record_helper.rb +0 -22
  109. data/spec/active_record_models.rb +0 -116
  110. data/spec/acts_as_tenant/model_extensions_spec.rb +0 -420
  111. data/spec/acts_as_tenant/tenant_by_subdomain_or_domain.rb +0 -46
  112. data/spec/acts_as_tenant/tenant_by_subdomain_spec.rb +0 -32
  113. data/spec/database.yml +0 -3
@@ -0,0 +1,413 @@
1
+ require "spec_helper"
2
+
3
+ describe ActsAsTenant do
4
+ let(:account) { accounts(:foo) }
5
+
6
+ it "can set the current tenant" do
7
+ ActsAsTenant.current_tenant = :foo
8
+ expect(ActsAsTenant.current_tenant).to eq(:foo)
9
+ end
10
+
11
+ it "is_scoped_as_tenant should return the correct value when true" do
12
+ expect(Project.respond_to?(:scoped_by_tenant?)).to eq(true)
13
+ end
14
+
15
+ it "is_scoped_as_tenant should return the correct value when false" do
16
+ expect(UnscopedModel.respond_to?(:scoped_by_tenant?)).to eq(false)
17
+ end
18
+
19
+ it "tenant_id should be immutable, if already set" do
20
+ project = account.projects.create!(name: "bar")
21
+ expect { project.account_id = account.id + 1 }.to raise_error(ActsAsTenant::Errors::TenantIsImmutable)
22
+ end
23
+
24
+ it "setting tenant_id to the same value should not error" do
25
+ project = account.projects.create!(name: "bar")
26
+ expect { project.account_id = account.id }.not_to raise_error
27
+ end
28
+
29
+ it "setting tenant_id to a string with same to_i value should not error" do
30
+ project = account.projects.create!(name: "bar")
31
+ expect { project.account_id = account.id.to_s }.not_to raise_error
32
+ end
33
+
34
+ it "tenant_id should be mutable, if not already set" do
35
+ project = projects(:without_account)
36
+ expect(project.account_id).to be_nil
37
+ expect { project.account = account }.not_to raise_error
38
+ end
39
+
40
+ it "tenant_id should auto populate after initialization" do
41
+ ActsAsTenant.current_tenant = account
42
+ expect(Project.new.account_id).to eq(account.id)
43
+ end
44
+
45
+ it "handles custom foreign_key on tenant model" do
46
+ ActsAsTenant.current_tenant = account
47
+ custom_foreign_key_task = CustomForeignKeyTask.create!(name: "foo")
48
+ expect(custom_foreign_key_task.account).to eq(account)
49
+ end
50
+
51
+ it "handles custom primary_key on tenant model" do
52
+ ActsAsTenant.current_tenant = account
53
+ custom_primary_key_task = CustomPrimaryKeyTask.create!
54
+ expect(custom_primary_key_task.account).to eq(account)
55
+ expect(CustomPrimaryKeyTask.count).to eq(1)
56
+ end
57
+
58
+ it "should correctly increment and decrement the tenants counter_cache column" do
59
+ ActsAsTenant.current_tenant = account
60
+ project = CustomCounterCacheTask.create!(name: "bar")
61
+ expect(account.reload.projects_count).to eq(1)
62
+ project.destroy
63
+ expect(account.reload.projects_count).to eq(0)
64
+ end
65
+
66
+ it "does not cache account association" do
67
+ project = account.projects.first
68
+ ActsAsTenant.current_tenant = account
69
+ expect(project.account.name).to eq(account.name)
70
+ account.update!(name: "Acme")
71
+ expect(project.account.name).to eq("Acme")
72
+ end
73
+
74
+ it "Querying the tenant from a scoped model without a tenant set" do
75
+ expect(projects(:foo).account).to_not be_nil
76
+ end
77
+
78
+ it "Querying the tenant from a scoped model with a tenant set" do
79
+ ActsAsTenant.current_tenant = account
80
+ expect(projects(:foo).account).to eq(accounts(:foo))
81
+ expect(projects(:bar).account).to eq(accounts(:bar))
82
+ end
83
+
84
+ describe "scoping models" do
85
+ it "should scope Project.all to the current tenant if set" do
86
+ ActsAsTenant.current_tenant = account
87
+ expect(Project.count).to eq(account.projects.count)
88
+ expect(Project.all).to eq(account.projects)
89
+ end
90
+
91
+ it "should allow unscoping" do
92
+ ActsAsTenant.current_tenant = account
93
+ expect(Project.unscoped.count).to be > account.projects.count
94
+ end
95
+
96
+ it "returns nothing with unsaved tenant" do
97
+ ActsAsTenant.current_tenant = Account.new
98
+ expect(Project.all.count).to eq(0)
99
+ end
100
+ end
101
+
102
+ describe "A tenant model with global records" do
103
+ before do
104
+ ActsAsTenant.current_tenant = account
105
+ end
106
+
107
+ it "should return global and tenant projects" do
108
+ expect(GlobalProject.count).to eq(GlobalProject.unscoped.where(account: [nil, account]).count)
109
+ end
110
+
111
+ it "returns global records with unsaved tenant" do
112
+ ActsAsTenant.current_tenant = Account.new
113
+ expect(GlobalProject.all.count).to eq(GlobalProject.unscoped.where(account: [nil]).count)
114
+ end
115
+
116
+ it "should add the model to ActsAsTenant.models_with_global_records" do
117
+ expect(ActsAsTenant.models_with_global_records.include?(GlobalProject)).to be_truthy
118
+ expect(ActsAsTenant.models_with_global_records.include?(Project)).to be_falsy
119
+ end
120
+
121
+ context "should validate tenant records against global & tenant records" do
122
+ it "global records are valid" do
123
+ expect(global_projects(:global).valid?).to be(true)
124
+ end
125
+
126
+ it "allows separate global and tenant records" do
127
+ expect(GlobalProject.new(name: "foo new").valid?).to be(true)
128
+ end
129
+
130
+ it "is valid if tenant is different" do
131
+ ActsAsTenant.current_tenant = accounts(:bar)
132
+
133
+ expect(GlobalProject.new(name: "global foo").valid?).to be(true)
134
+ end
135
+
136
+ it "is invalid with duplicate tenant records" do
137
+ expect(GlobalProject.new(name: "global foo").valid?).to be(false)
138
+ end
139
+
140
+ it "is invalid if tenant record conflicts with global record" do
141
+ expect(GlobalProject.new(name: "global").valid?).to be(false)
142
+ end
143
+ end
144
+
145
+ context "should validate global records against global & tenant records" do
146
+ before do
147
+ ActsAsTenant.current_tenant = nil
148
+ end
149
+
150
+ it "is invalid if global record conflicts with tenant record" do
151
+ expect(GlobalProject.new(name: "global foo").valid?).to be(false)
152
+ end
153
+ end
154
+
155
+ context "with conditions in args" do
156
+ it "respects conditions" do
157
+ expect(GlobalProjectWithConditions.new(name: "foo").valid?).to be(false)
158
+ expect(GlobalProjectWithConditions.new(name: "global foo").valid?).to be(true)
159
+ end
160
+ end
161
+
162
+ context "with if in args" do
163
+ it "respects if" do
164
+ expect(GlobalProjectWithIf.new(name: "foo").valid?).to be(false)
165
+ expect(GlobalProjectWithIf.new(name: "global foo").valid?).to be(true)
166
+ end
167
+ end
168
+ end
169
+
170
+ # Associations
171
+ context "Associations should be correctly scoped by current tenant" do
172
+ before do
173
+ @project = account.projects.create!(name: "foobar")
174
+
175
+ # the next line should normally be (nearly) impossible: a task assigned to a tenant project,
176
+ # but the task has no tenant assigned
177
+ @task1 = Task.create!(name: "no_tenant", project: @project)
178
+
179
+ ActsAsTenant.current_tenant = account
180
+ @task2 = @project.tasks.create!(name: "baz")
181
+
182
+ @project.reload
183
+ end
184
+
185
+ it "should correctly set the tenant on the task created with current_tenant set" do
186
+ expect(@task2.account).to eq(account)
187
+ end
188
+
189
+ it "should filter out the non-tenant task from the project" do
190
+ expect(@project.tasks.length).to eq(1)
191
+ end
192
+ end
193
+
194
+ it "associations can only be made with in-scope objects" do
195
+ project1 = accounts(:bar).projects.create!(name: "inaccessible_project")
196
+ ActsAsTenant.current_tenant = account
197
+
198
+ project2 = Project.create!(name: "accessible_project")
199
+ task = project2.tasks.create!(name: "bar")
200
+
201
+ expect(task.update(project_id: project1.id)).to eq(false)
202
+ end
203
+
204
+ it "can create and save an AaT-enabled child without it having a parent" do
205
+ ActsAsTenant.current_tenant = account
206
+ expect(Task.new(name: "bar").valid?).to eq(true)
207
+ end
208
+
209
+ it "should be possible to use aliased associations" do
210
+ expect(AliasedTask.create(name: "foo", project_alias: @project2).valid?).to eq(true)
211
+ end
212
+
213
+ describe "It should be possible to use associations with foreign_key from polymorphic" do
214
+ it "tenanted objects have a polymorphic association" do
215
+ ActsAsTenant.current_tenant = account
216
+ expect { Comment.create!(commentable: account.projects.first) }.not_to raise_error
217
+ end
218
+
219
+ context "tenant is polymorphic" do
220
+ before do
221
+ @project = Project.create!(name: "polymorphic project")
222
+ ActsAsTenant.current_tenant = @project
223
+ @comment = PolymorphicTenantComment.new(account: account)
224
+ end
225
+
226
+ it "populates commentable_type with the current tenant" do
227
+ expect(@comment.polymorphic_tenant_commentable_id).to eql(@project.id)
228
+ expect(@comment.polymorphic_tenant_commentable_type).to eql(@project.class.to_s)
229
+ end
230
+
231
+ context "with another type of tenant, same id" do
232
+ before do
233
+ @comment.save!
234
+ @article = Article.create!(id: @project.id, title: "article title")
235
+ @comment_on_article = @article.polymorphic_tenant_comments.create!
236
+ end
237
+
238
+ it "correctly scopes to the current tenant type" do
239
+ expect(@comment_on_article).to be_persisted
240
+ expect(@comment).to be_persisted
241
+ expect(PolymorphicTenantComment.count).to eql(1)
242
+ expect(PolymorphicTenantComment.all.first.attributes).to eql(@comment.attributes)
243
+ end
244
+ end
245
+ end
246
+ end
247
+
248
+ # Additional default_scopes
249
+ it "should apply both the tenant scope and the user defined default_scope, including :order" do
250
+ project1 = Project.create!(name: "inaccessible")
251
+ Task.create!(name: "no_tenant", project: project1)
252
+
253
+ ActsAsTenant.current_tenant = account
254
+ project2 = Project.create!(name: "accessible")
255
+ task2 = project2.tasks.create!(name: "bar")
256
+ task3 = project2.tasks.create!(name: "baz")
257
+ task4 = project2.tasks.create!(name: "foo")
258
+ project2.tasks.create!(name: "foobar", completed: true)
259
+
260
+ tasks = Task.all
261
+
262
+ expect(tasks.length).to eq(3)
263
+ expect(tasks).to eq([task2, task3, task4])
264
+ end
265
+
266
+ # Validates_uniqueness
267
+ context "When using validates_uniqueness_to_tenant in a aat model" do
268
+ before do
269
+ @name = "existing_name"
270
+ ActsAsTenant.current_tenant = account
271
+ Project.create!(name: @name)
272
+ end
273
+
274
+ it "should not be possible to create a duplicate within the same tenant" do
275
+ expect(Project.new(name: @name).valid?).to eq(false)
276
+ end
277
+
278
+ it "should be possible to create a duplicate in another tenant" do
279
+ ActsAsTenant.current_tenant = accounts(:bar)
280
+ expect(Project.create(name: @name).valid?).to eq(true)
281
+ end
282
+ end
283
+
284
+ it "handles user defined scopes" do
285
+ UniqueTask.create!(name: "foo", user_defined_scope: "unique_scope")
286
+ expect(UniqueTask.create(name: "foo", user_defined_scope: "another_scope")).to be_valid
287
+ expect(UniqueTask.create(name: "foo", user_defined_scope: "unique_scope")).not_to be_valid
288
+ end
289
+
290
+ context "When using validates_uniqueness_of in a NON-aat model" do
291
+ it "should not be possible to create duplicates" do
292
+ UnscopedModel.create!(name: "foo")
293
+ expect(UnscopedModel.create(name: "foo").valid?).to eq(false)
294
+ end
295
+ end
296
+
297
+ # ::with_tenant
298
+ describe "::with_tenant" do
299
+ it "should set current_tenant to the specified tenant inside the block" do
300
+ ActsAsTenant.with_tenant(account) do
301
+ expect(ActsAsTenant.current_tenant).to eq(account)
302
+ end
303
+ end
304
+
305
+ it "should reset current_tenant to the previous tenant once exiting the block" do
306
+ ActsAsTenant.current_tenant = account
307
+ ActsAsTenant.with_tenant(accounts(:bar)) {}
308
+ expect(ActsAsTenant.current_tenant).to eq(account)
309
+ end
310
+
311
+ it "should return the value of the block" do
312
+ ActsAsTenant.current_tenant = account
313
+ value = ActsAsTenant.with_tenant(accounts(:bar)) { "something" }
314
+ expect(value).to eq "something"
315
+ end
316
+
317
+ it "should raise an error when no block is provided" do
318
+ expect { ActsAsTenant.with_tenant(nil) }.to raise_error(ArgumentError, /block required/)
319
+ end
320
+ end
321
+
322
+ describe "::without_tenant" do
323
+ it "should set current_tenant to nil inside the block" do
324
+ ActsAsTenant.without_tenant do
325
+ expect(ActsAsTenant.current_tenant).to be_nil
326
+ end
327
+ end
328
+
329
+ it "should set current_tenant to nil even if default_tenant is set" do
330
+ old_default_tenant = ActsAsTenant.default_tenant
331
+ ActsAsTenant.default_tenant = Account.create!(name: "foo")
332
+ ActsAsTenant.without_tenant do
333
+ expect(ActsAsTenant.current_tenant).to be_nil
334
+ end
335
+ ensure
336
+ ActsAsTenant.default_tenant = old_default_tenant
337
+ end
338
+
339
+ it "should reset current_tenant to the previous tenant once exiting the block" do
340
+ ActsAsTenant.current_tenant = account
341
+ ActsAsTenant.without_tenant {}
342
+ expect(ActsAsTenant.current_tenant).to eq(account)
343
+ end
344
+
345
+ it "should return the value of the block" do
346
+ value = ActsAsTenant.without_tenant { "something" }
347
+ expect(value).to eq "something"
348
+ end
349
+
350
+ it "should raise an error when no block is provided" do
351
+ expect { ActsAsTenant.without_tenant }.to raise_error(ArgumentError, /block required/)
352
+ end
353
+ end
354
+
355
+ # Tenant required
356
+ context "tenant required" do
357
+ before do
358
+ account.projects.create!(name: "foobar")
359
+ allow(ActsAsTenant.configuration).to receive_messages(require_tenant: true)
360
+ end
361
+
362
+ it "should raise an error when no tenant is provided" do
363
+ expect { Project.all }.to raise_error(ActsAsTenant::Errors::NoTenantSet)
364
+ end
365
+
366
+ it "should not raise an error when no tenant is provided" do
367
+ expect { ActsAsTenant.without_tenant { Project.all } }.to_not raise_error
368
+ end
369
+ end
370
+
371
+ context "no tenant required" do
372
+ it "should not raise an error when no tenant is provided" do
373
+ expect { Project.all }.to_not raise_error
374
+ end
375
+ end
376
+
377
+ describe "ActsAsTenant.default_tenant=" do
378
+ after(:each) do
379
+ ActsAsTenant.default_tenant = nil
380
+ end
381
+
382
+ it "provides current_tenant" do
383
+ ActsAsTenant.default_tenant = account
384
+ expect(ActsAsTenant.current_tenant).to eq(account)
385
+ end
386
+
387
+ it "can be overridden by assignment" do
388
+ ActsAsTenant.default_tenant = account
389
+ ActsAsTenant.current_tenant = accounts(:bar)
390
+ expect(ActsAsTenant.current_tenant).to eq(accounts(:bar))
391
+ end
392
+
393
+ it "can be overridden by with_tenant" do
394
+ ActsAsTenant.default_tenant = account
395
+ ActsAsTenant.with_tenant accounts(:bar) do
396
+ expect(ActsAsTenant.current_tenant).to eq(accounts(:bar))
397
+ end
398
+ expect(ActsAsTenant.current_tenant).to eq(account)
399
+ end
400
+
401
+ it "doesn't override existing current_tenant" do
402
+ ActsAsTenant.current_tenant = accounts(:bar)
403
+ ActsAsTenant.default_tenant = account
404
+ expect(ActsAsTenant.current_tenant).to eq(accounts(:bar))
405
+ end
406
+
407
+ it "survives request resets" do
408
+ ActsAsTenant.default_tenant = account
409
+ RequestStore.clear!
410
+ expect(ActsAsTenant.current_tenant).to eq(account)
411
+ end
412
+ end
413
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,23 +1,19 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
3
 
4
- require "active_record_helper"
4
+ require_relative "../spec/dummy/config/environment"
5
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path("../spec/dummy/db/migrate", __dir__)]
6
+ ActiveRecord::Migration.maintain_test_schema!
5
7
 
6
- require 'rspec/rails'
7
- require 'acts_as_tenant'
8
+ require "rspec/rails"
8
9
 
9
10
  RSpec.configure do |config|
10
11
  config.after(:each) do
11
12
  ActsAsTenant.current_tenant = nil
12
13
  end
13
14
 
15
+ config.fixture_path = "spec/fixtures"
16
+ config.global_fixtures = :all
17
+ config.use_transactional_fixtures = true
14
18
  config.infer_base_class_for_anonymous_controllers = true
15
19
  end
16
-
17
- # Setup a test app
18
- module Rollcall
19
- class Application < Rails::Application; end
20
- end
21
-
22
- Rollcall::Application.config.secret_token = '1234567890123456789012345678901234567890'
23
- Rollcall::Application.config.secret_key_base = '1234567890123456789012345678901234567890'