ros-apartment 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/.travis.yml +8 -30
  4. data/Appraisals +4 -17
  5. data/Gemfile +1 -1
  6. data/Guardfile +3 -1
  7. data/README.md +15 -14
  8. data/Rakefile +34 -22
  9. data/apartment.gemspec +11 -3
  10. data/gemfiles/rails_5_0.gemfile +10 -11
  11. data/gemfiles/rails_5_1.gemfile +10 -11
  12. data/gemfiles/rails_5_2.gemfile +9 -10
  13. data/gemfiles/rails_6_0.gemfile +10 -11
  14. data/gemfiles/rails_master.gemfile +10 -11
  15. data/lib/apartment/active_record/connection_handling.rb +17 -0
  16. data/lib/apartment/active_record/internal_metadata.rb +11 -0
  17. data/lib/apartment/active_record/schema_migration.rb +13 -0
  18. data/lib/apartment/adapters/abstract_adapter.rb +3 -2
  19. data/lib/apartment/model.rb +27 -0
  20. data/lib/apartment/tenant.rb +3 -1
  21. data/lib/apartment/version.rb +1 -1
  22. data/lib/apartment.rb +22 -3
  23. metadata +11 -209
  24. data/spec/adapters/jdbc_mysql_adapter_spec.rb +0 -20
  25. data/spec/adapters/jdbc_postgresql_adapter_spec.rb +0 -39
  26. data/spec/adapters/mysql2_adapter_spec.rb +0 -61
  27. data/spec/adapters/postgresql_adapter_spec.rb +0 -63
  28. data/spec/adapters/sqlite3_adapter_spec.rb +0 -101
  29. data/spec/apartment_spec.rb +0 -13
  30. data/spec/config/database.yml.sample +0 -49
  31. data/spec/dummy/Rakefile +0 -7
  32. data/spec/dummy/app/controllers/application_controller.rb +0 -7
  33. data/spec/dummy/app/helpers/application_helper.rb +0 -4
  34. data/spec/dummy/app/models/application_record.rb +0 -6
  35. data/spec/dummy/app/models/company.rb +0 -5
  36. data/spec/dummy/app/models/user.rb +0 -5
  37. data/spec/dummy/app/views/application/index.html.erb +0 -1
  38. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  39. data/spec/dummy/config/application.rb +0 -51
  40. data/spec/dummy/config/boot.rb +0 -13
  41. data/spec/dummy/config/database.yml.sample +0 -44
  42. data/spec/dummy/config/environment.rb +0 -7
  43. data/spec/dummy/config/environments/development.rb +0 -29
  44. data/spec/dummy/config/environments/production.rb +0 -53
  45. data/spec/dummy/config/environments/test.rb +0 -36
  46. data/spec/dummy/config/initializers/apartment.rb +0 -6
  47. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -8
  48. data/spec/dummy/config/initializers/inflections.rb +0 -11
  49. data/spec/dummy/config/initializers/mime_types.rb +0 -6
  50. data/spec/dummy/config/initializers/secret_token.rb +0 -9
  51. data/spec/dummy/config/initializers/session_store.rb +0 -10
  52. data/spec/dummy/config/locales/en.yml +0 -5
  53. data/spec/dummy/config/routes.rb +0 -5
  54. data/spec/dummy/config.ru +0 -6
  55. data/spec/dummy/db/migrate/20110613152810_create_dummy_models.rb +0 -39
  56. data/spec/dummy/db/migrate/20111202022214_create_table_books.rb +0 -14
  57. data/spec/dummy/db/migrate/20180415260934_create_public_tokens.rb +0 -13
  58. data/spec/dummy/db/schema.rb +0 -55
  59. data/spec/dummy/db/seeds/import.rb +0 -7
  60. data/spec/dummy/db/seeds.rb +0 -5
  61. data/spec/dummy/db/test.sqlite3 +0 -0
  62. data/spec/dummy/public/404.html +0 -26
  63. data/spec/dummy/public/422.html +0 -26
  64. data/spec/dummy/public/500.html +0 -26
  65. data/spec/dummy/public/favicon.ico +0 -0
  66. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  67. data/spec/dummy/script/rails +0 -8
  68. data/spec/dummy_engine/.gitignore +0 -8
  69. data/spec/dummy_engine/Gemfile +0 -15
  70. data/spec/dummy_engine/Rakefile +0 -34
  71. data/spec/dummy_engine/bin/rails +0 -12
  72. data/spec/dummy_engine/config/initializers/apartment.rb +0 -52
  73. data/spec/dummy_engine/dummy_engine.gemspec +0 -24
  74. data/spec/dummy_engine/lib/dummy_engine/engine.rb +0 -6
  75. data/spec/dummy_engine/lib/dummy_engine/version.rb +0 -5
  76. data/spec/dummy_engine/lib/dummy_engine.rb +0 -6
  77. data/spec/dummy_engine/test/dummy/Rakefile +0 -6
  78. data/spec/dummy_engine/test/dummy/config/application.rb +0 -24
  79. data/spec/dummy_engine/test/dummy/config/boot.rb +0 -7
  80. data/spec/dummy_engine/test/dummy/config/database.yml +0 -25
  81. data/spec/dummy_engine/test/dummy/config/environment.rb +0 -7
  82. data/spec/dummy_engine/test/dummy/config/environments/development.rb +0 -39
  83. data/spec/dummy_engine/test/dummy/config/environments/production.rb +0 -80
  84. data/spec/dummy_engine/test/dummy/config/environments/test.rb +0 -41
  85. data/spec/dummy_engine/test/dummy/config/initializers/assets.rb +0 -10
  86. data/spec/dummy_engine/test/dummy/config/initializers/backtrace_silencers.rb +0 -8
  87. data/spec/dummy_engine/test/dummy/config/initializers/cookies_serializer.rb +0 -5
  88. data/spec/dummy_engine/test/dummy/config/initializers/filter_parameter_logging.rb +0 -6
  89. data/spec/dummy_engine/test/dummy/config/initializers/inflections.rb +0 -17
  90. data/spec/dummy_engine/test/dummy/config/initializers/mime_types.rb +0 -5
  91. data/spec/dummy_engine/test/dummy/config/initializers/session_store.rb +0 -5
  92. data/spec/dummy_engine/test/dummy/config/initializers/wrap_parameters.rb +0 -16
  93. data/spec/dummy_engine/test/dummy/config/locales/en.yml +0 -23
  94. data/spec/dummy_engine/test/dummy/config/routes.rb +0 -58
  95. data/spec/dummy_engine/test/dummy/config/secrets.yml +0 -22
  96. data/spec/dummy_engine/test/dummy/config.ru +0 -6
  97. data/spec/examples/connection_adapter_examples.rb +0 -44
  98. data/spec/examples/generic_adapter_custom_configuration_example.rb +0 -93
  99. data/spec/examples/generic_adapter_examples.rb +0 -164
  100. data/spec/examples/schema_adapter_examples.rb +0 -239
  101. data/spec/integration/apartment_rake_integration_spec.rb +0 -107
  102. data/spec/integration/query_caching_spec.rb +0 -83
  103. data/spec/integration/use_within_an_engine_spec.rb +0 -28
  104. data/spec/schemas/v1.rb +0 -15
  105. data/spec/schemas/v2.rb +0 -41
  106. data/spec/schemas/v3.rb +0 -47
  107. data/spec/spec_helper.rb +0 -63
  108. data/spec/support/apartment_helpers.rb +0 -47
  109. data/spec/support/capybara_sessions.rb +0 -15
  110. data/spec/support/config.rb +0 -13
  111. data/spec/support/contexts.rb +0 -54
  112. data/spec/support/requirements.rb +0 -48
  113. data/spec/support/setup.rb +0 -46
  114. data/spec/tasks/apartment_rake_spec.rb +0 -124
  115. data/spec/tenant_spec.rb +0 -194
  116. data/spec/unit/config_spec.rb +0 -111
  117. data/spec/unit/elevators/domain_spec.rb +0 -33
  118. data/spec/unit/elevators/first_subdomain_spec.rb +0 -26
  119. data/spec/unit/elevators/generic_spec.rb +0 -55
  120. data/spec/unit/elevators/host_hash_spec.rb +0 -33
  121. data/spec/unit/elevators/host_spec.rb +0 -89
  122. data/spec/unit/elevators/subdomain_spec.rb +0 -77
  123. data/spec/unit/migrator_spec.rb +0 -78
  124. data/spec/unit/reloader_spec.rb +0 -24
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Apartment
4
- VERSION = '2.4.0'
4
+ VERSION = '2.5.0'
5
5
  end
data/lib/apartment.rb CHANGED
@@ -6,6 +6,15 @@ require 'forwardable'
6
6
  require 'active_record'
7
7
  require 'apartment/tenant'
8
8
 
9
+ # require_relative 'apartment/arel/visitors/postgresql'
10
+
11
+ require_relative 'apartment/active_record/connection_handling' if ActiveRecord.version.release >= Gem::Version.new('6.0')
12
+
13
+ if ActiveRecord.version.release >= Gem::Version.new('6.1')
14
+ require_relative 'apartment/active_record/schema_migration'
15
+ require_relative 'apartment/active_record/internal_metadata'
16
+ end
17
+
9
18
  module Apartment
10
19
  class << self
11
20
  extend Forwardable
@@ -21,7 +30,15 @@ module Apartment
21
30
  attr_accessor(*ACCESSOR_METHODS)
22
31
  attr_writer(*WRITER_METHODS)
23
32
 
24
- def_delegators :connection_class, :connection, :connection_config, :establish_connection
33
+ if ActiveRecord.version.release >= Gem::Version.new('6.1')
34
+ def_delegators :connection_class, :connection, :connection_db_config, :establish_connection
35
+
36
+ def connection_config
37
+ connection_db_config.configuration_hash
38
+ end
39
+ else
40
+ def_delegators :connection_class, :connection, :connection_config, :establish_connection
41
+ end
25
42
 
26
43
  # configure apartment with available options
27
44
  def configure
@@ -37,7 +54,7 @@ module Apartment
37
54
  end
38
55
 
39
56
  def db_config_for(tenant)
40
- (tenants_with_config[tenant] || connection_config).with_indifferent_access
57
+ (tenants_with_config[tenant] || connection_config)
41
58
  end
42
59
 
43
60
  # Whether or not db:migrate should also migrate tenants
@@ -89,7 +106,9 @@ module Apartment
89
106
 
90
107
  # Reset all the config for Apartment
91
108
  def reset
92
- (ACCESSOR_METHODS + WRITER_METHODS).each { |method| remove_instance_variable(:"@#{method}") if instance_variable_defined?(:"@#{method}") }
109
+ (ACCESSOR_METHODS + WRITER_METHODS).each do |method|
110
+ remove_instance_variable(:"@#{method}") if instance_variable_defined?(:"@#{method}")
111
+ end
93
112
  end
94
113
 
95
114
  def extract_tenant_config
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ros-apartment
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brunner
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-04-01 00:00:00.000000000 Z
13
+ date: 2020-05-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 3.1.2
21
+ version: 5.0.0
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
24
  version: '6.1'
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: 3.1.2
31
+ version: 5.0.0
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '6.1'
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '1.3'
110
110
  - - "<"
111
111
  - !ruby/object:Gem::Version
112
- version: '2.0'
112
+ version: '3.0'
113
113
  type: :development
114
114
  prerelease: false
115
115
  version_requirements: !ruby/object:Gem::Requirement
@@ -119,7 +119,7 @@ dependencies:
119
119
  version: '1.3'
120
120
  - - "<"
121
121
  - !ruby/object:Gem::Version
122
- version: '2.0'
122
+ version: '3.0'
123
123
  - !ruby/object:Gem::Dependency
124
124
  name: capybara
125
125
  requirement: !ruby/object:Gem::Requirement
@@ -253,6 +253,9 @@ files:
253
253
  - gemfiles/rails_6_0.gemfile
254
254
  - gemfiles/rails_master.gemfile
255
255
  - lib/apartment.rb
256
+ - lib/apartment/active_record/connection_handling.rb
257
+ - lib/apartment/active_record/internal_metadata.rb
258
+ - lib/apartment/active_record/schema_migration.rb
256
259
  - lib/apartment/adapters/abstract_adapter.rb
257
260
  - lib/apartment/adapters/abstract_jdbc_adapter.rb
258
261
  - lib/apartment/adapters/jdbc_mysql_adapter.rb
@@ -271,6 +274,7 @@ files:
271
274
  - lib/apartment/elevators/host_hash.rb
272
275
  - lib/apartment/elevators/subdomain.rb
273
276
  - lib/apartment/migrator.rb
277
+ - lib/apartment/model.rb
274
278
  - lib/apartment/railtie.rb
275
279
  - lib/apartment/reloader.rb
276
280
  - lib/apartment/tasks/enhancements.rb
@@ -280,107 +284,6 @@ files:
280
284
  - lib/generators/apartment/install/install_generator.rb
281
285
  - lib/generators/apartment/install/templates/apartment.rb
282
286
  - lib/tasks/apartment.rake
283
- - spec/adapters/jdbc_mysql_adapter_spec.rb
284
- - spec/adapters/jdbc_postgresql_adapter_spec.rb
285
- - spec/adapters/mysql2_adapter_spec.rb
286
- - spec/adapters/postgresql_adapter_spec.rb
287
- - spec/adapters/sqlite3_adapter_spec.rb
288
- - spec/apartment_spec.rb
289
- - spec/config/database.yml.sample
290
- - spec/dummy/Rakefile
291
- - spec/dummy/app/controllers/application_controller.rb
292
- - spec/dummy/app/helpers/application_helper.rb
293
- - spec/dummy/app/models/application_record.rb
294
- - spec/dummy/app/models/company.rb
295
- - spec/dummy/app/models/user.rb
296
- - spec/dummy/app/views/application/index.html.erb
297
- - spec/dummy/app/views/layouts/application.html.erb
298
- - spec/dummy/config.ru
299
- - spec/dummy/config/application.rb
300
- - spec/dummy/config/boot.rb
301
- - spec/dummy/config/database.yml.sample
302
- - spec/dummy/config/environment.rb
303
- - spec/dummy/config/environments/development.rb
304
- - spec/dummy/config/environments/production.rb
305
- - spec/dummy/config/environments/test.rb
306
- - spec/dummy/config/initializers/apartment.rb
307
- - spec/dummy/config/initializers/backtrace_silencers.rb
308
- - spec/dummy/config/initializers/inflections.rb
309
- - spec/dummy/config/initializers/mime_types.rb
310
- - spec/dummy/config/initializers/secret_token.rb
311
- - spec/dummy/config/initializers/session_store.rb
312
- - spec/dummy/config/locales/en.yml
313
- - spec/dummy/config/routes.rb
314
- - spec/dummy/db/migrate/20110613152810_create_dummy_models.rb
315
- - spec/dummy/db/migrate/20111202022214_create_table_books.rb
316
- - spec/dummy/db/migrate/20180415260934_create_public_tokens.rb
317
- - spec/dummy/db/schema.rb
318
- - spec/dummy/db/seeds.rb
319
- - spec/dummy/db/seeds/import.rb
320
- - spec/dummy/db/test.sqlite3
321
- - spec/dummy/public/404.html
322
- - spec/dummy/public/422.html
323
- - spec/dummy/public/500.html
324
- - spec/dummy/public/favicon.ico
325
- - spec/dummy/public/stylesheets/.gitkeep
326
- - spec/dummy/script/rails
327
- - spec/dummy_engine/.gitignore
328
- - spec/dummy_engine/Gemfile
329
- - spec/dummy_engine/Rakefile
330
- - spec/dummy_engine/bin/rails
331
- - spec/dummy_engine/config/initializers/apartment.rb
332
- - spec/dummy_engine/dummy_engine.gemspec
333
- - spec/dummy_engine/lib/dummy_engine.rb
334
- - spec/dummy_engine/lib/dummy_engine/engine.rb
335
- - spec/dummy_engine/lib/dummy_engine/version.rb
336
- - spec/dummy_engine/test/dummy/Rakefile
337
- - spec/dummy_engine/test/dummy/config.ru
338
- - spec/dummy_engine/test/dummy/config/application.rb
339
- - spec/dummy_engine/test/dummy/config/boot.rb
340
- - spec/dummy_engine/test/dummy/config/database.yml
341
- - spec/dummy_engine/test/dummy/config/environment.rb
342
- - spec/dummy_engine/test/dummy/config/environments/development.rb
343
- - spec/dummy_engine/test/dummy/config/environments/production.rb
344
- - spec/dummy_engine/test/dummy/config/environments/test.rb
345
- - spec/dummy_engine/test/dummy/config/initializers/assets.rb
346
- - spec/dummy_engine/test/dummy/config/initializers/backtrace_silencers.rb
347
- - spec/dummy_engine/test/dummy/config/initializers/cookies_serializer.rb
348
- - spec/dummy_engine/test/dummy/config/initializers/filter_parameter_logging.rb
349
- - spec/dummy_engine/test/dummy/config/initializers/inflections.rb
350
- - spec/dummy_engine/test/dummy/config/initializers/mime_types.rb
351
- - spec/dummy_engine/test/dummy/config/initializers/session_store.rb
352
- - spec/dummy_engine/test/dummy/config/initializers/wrap_parameters.rb
353
- - spec/dummy_engine/test/dummy/config/locales/en.yml
354
- - spec/dummy_engine/test/dummy/config/routes.rb
355
- - spec/dummy_engine/test/dummy/config/secrets.yml
356
- - spec/examples/connection_adapter_examples.rb
357
- - spec/examples/generic_adapter_custom_configuration_example.rb
358
- - spec/examples/generic_adapter_examples.rb
359
- - spec/examples/schema_adapter_examples.rb
360
- - spec/integration/apartment_rake_integration_spec.rb
361
- - spec/integration/query_caching_spec.rb
362
- - spec/integration/use_within_an_engine_spec.rb
363
- - spec/schemas/v1.rb
364
- - spec/schemas/v2.rb
365
- - spec/schemas/v3.rb
366
- - spec/spec_helper.rb
367
- - spec/support/apartment_helpers.rb
368
- - spec/support/capybara_sessions.rb
369
- - spec/support/config.rb
370
- - spec/support/contexts.rb
371
- - spec/support/requirements.rb
372
- - spec/support/setup.rb
373
- - spec/tasks/apartment_rake_spec.rb
374
- - spec/tenant_spec.rb
375
- - spec/unit/config_spec.rb
376
- - spec/unit/elevators/domain_spec.rb
377
- - spec/unit/elevators/first_subdomain_spec.rb
378
- - spec/unit/elevators/generic_spec.rb
379
- - spec/unit/elevators/host_hash_spec.rb
380
- - spec/unit/elevators/host_spec.rb
381
- - spec/unit/elevators/subdomain_spec.rb
382
- - spec/unit/migrator_spec.rb
383
- - spec/unit/reloader_spec.rb
384
287
  homepage: https://github.com/rails-on-services/apartment
385
288
  licenses:
386
289
  - MIT
@@ -404,105 +307,4 @@ rubygems_version: 3.0.3
404
307
  signing_key:
405
308
  specification_version: 4
406
309
  summary: A Ruby gem for managing database multitenancy. Apartment Gem drop in replacement
407
- test_files:
408
- - spec/adapters/jdbc_mysql_adapter_spec.rb
409
- - spec/adapters/jdbc_postgresql_adapter_spec.rb
410
- - spec/adapters/mysql2_adapter_spec.rb
411
- - spec/adapters/postgresql_adapter_spec.rb
412
- - spec/adapters/sqlite3_adapter_spec.rb
413
- - spec/apartment_spec.rb
414
- - spec/config/database.yml.sample
415
- - spec/dummy/Rakefile
416
- - spec/dummy/app/controllers/application_controller.rb
417
- - spec/dummy/app/helpers/application_helper.rb
418
- - spec/dummy/app/models/application_record.rb
419
- - spec/dummy/app/models/company.rb
420
- - spec/dummy/app/models/user.rb
421
- - spec/dummy/app/views/application/index.html.erb
422
- - spec/dummy/app/views/layouts/application.html.erb
423
- - spec/dummy/config.ru
424
- - spec/dummy/config/application.rb
425
- - spec/dummy/config/boot.rb
426
- - spec/dummy/config/database.yml.sample
427
- - spec/dummy/config/environment.rb
428
- - spec/dummy/config/environments/development.rb
429
- - spec/dummy/config/environments/production.rb
430
- - spec/dummy/config/environments/test.rb
431
- - spec/dummy/config/initializers/apartment.rb
432
- - spec/dummy/config/initializers/backtrace_silencers.rb
433
- - spec/dummy/config/initializers/inflections.rb
434
- - spec/dummy/config/initializers/mime_types.rb
435
- - spec/dummy/config/initializers/secret_token.rb
436
- - spec/dummy/config/initializers/session_store.rb
437
- - spec/dummy/config/locales/en.yml
438
- - spec/dummy/config/routes.rb
439
- - spec/dummy/db/migrate/20110613152810_create_dummy_models.rb
440
- - spec/dummy/db/migrate/20111202022214_create_table_books.rb
441
- - spec/dummy/db/migrate/20180415260934_create_public_tokens.rb
442
- - spec/dummy/db/schema.rb
443
- - spec/dummy/db/seeds.rb
444
- - spec/dummy/db/seeds/import.rb
445
- - spec/dummy/db/test.sqlite3
446
- - spec/dummy/public/404.html
447
- - spec/dummy/public/422.html
448
- - spec/dummy/public/500.html
449
- - spec/dummy/public/favicon.ico
450
- - spec/dummy/public/stylesheets/.gitkeep
451
- - spec/dummy/script/rails
452
- - spec/dummy_engine/.gitignore
453
- - spec/dummy_engine/Gemfile
454
- - spec/dummy_engine/Rakefile
455
- - spec/dummy_engine/bin/rails
456
- - spec/dummy_engine/config/initializers/apartment.rb
457
- - spec/dummy_engine/dummy_engine.gemspec
458
- - spec/dummy_engine/lib/dummy_engine.rb
459
- - spec/dummy_engine/lib/dummy_engine/engine.rb
460
- - spec/dummy_engine/lib/dummy_engine/version.rb
461
- - spec/dummy_engine/test/dummy/Rakefile
462
- - spec/dummy_engine/test/dummy/config.ru
463
- - spec/dummy_engine/test/dummy/config/application.rb
464
- - spec/dummy_engine/test/dummy/config/boot.rb
465
- - spec/dummy_engine/test/dummy/config/database.yml
466
- - spec/dummy_engine/test/dummy/config/environment.rb
467
- - spec/dummy_engine/test/dummy/config/environments/development.rb
468
- - spec/dummy_engine/test/dummy/config/environments/production.rb
469
- - spec/dummy_engine/test/dummy/config/environments/test.rb
470
- - spec/dummy_engine/test/dummy/config/initializers/assets.rb
471
- - spec/dummy_engine/test/dummy/config/initializers/backtrace_silencers.rb
472
- - spec/dummy_engine/test/dummy/config/initializers/cookies_serializer.rb
473
- - spec/dummy_engine/test/dummy/config/initializers/filter_parameter_logging.rb
474
- - spec/dummy_engine/test/dummy/config/initializers/inflections.rb
475
- - spec/dummy_engine/test/dummy/config/initializers/mime_types.rb
476
- - spec/dummy_engine/test/dummy/config/initializers/session_store.rb
477
- - spec/dummy_engine/test/dummy/config/initializers/wrap_parameters.rb
478
- - spec/dummy_engine/test/dummy/config/locales/en.yml
479
- - spec/dummy_engine/test/dummy/config/routes.rb
480
- - spec/dummy_engine/test/dummy/config/secrets.yml
481
- - spec/examples/connection_adapter_examples.rb
482
- - spec/examples/generic_adapter_custom_configuration_example.rb
483
- - spec/examples/generic_adapter_examples.rb
484
- - spec/examples/schema_adapter_examples.rb
485
- - spec/integration/apartment_rake_integration_spec.rb
486
- - spec/integration/query_caching_spec.rb
487
- - spec/integration/use_within_an_engine_spec.rb
488
- - spec/schemas/v1.rb
489
- - spec/schemas/v2.rb
490
- - spec/schemas/v3.rb
491
- - spec/spec_helper.rb
492
- - spec/support/apartment_helpers.rb
493
- - spec/support/capybara_sessions.rb
494
- - spec/support/config.rb
495
- - spec/support/contexts.rb
496
- - spec/support/requirements.rb
497
- - spec/support/setup.rb
498
- - spec/tasks/apartment_rake_spec.rb
499
- - spec/tenant_spec.rb
500
- - spec/unit/config_spec.rb
501
- - spec/unit/elevators/domain_spec.rb
502
- - spec/unit/elevators/first_subdomain_spec.rb
503
- - spec/unit/elevators/generic_spec.rb
504
- - spec/unit/elevators/host_hash_spec.rb
505
- - spec/unit/elevators/host_spec.rb
506
- - spec/unit/elevators/subdomain_spec.rb
507
- - spec/unit/migrator_spec.rb
508
- - spec/unit/reloader_spec.rb
310
+ test_files: []
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if defined?(JRUBY_VERSION)
4
-
5
- require 'spec_helper'
6
- require 'apartment/adapters/jdbc_mysql_adapter'
7
-
8
- describe Apartment::Adapters::JDBCMysqlAdapter, database: :mysql do
9
- subject { Apartment::Tenant.jdbc_mysql_adapter config.symbolize_keys }
10
-
11
- def tenant_names
12
- ActiveRecord::Base.connection.execute('SELECT schema_name FROM information_schema.schemata').collect { |row| row['schema_name'] }
13
- end
14
-
15
- let(:default_tenant) { subject.switch { ActiveRecord::Base.connection.current_database } }
16
-
17
- it_should_behave_like 'a generic apartment adapter'
18
- it_should_behave_like 'a connection based apartment adapter'
19
- end
20
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if defined?(JRUBY_VERSION)
4
-
5
- require 'spec_helper'
6
- require 'apartment/adapters/jdbc_postgresql_adapter'
7
-
8
- describe Apartment::Adapters::JDBCPostgresqlAdapter, database: :postgresql do
9
- subject { Apartment::Tenant.jdbc_postgresql_adapter config.symbolize_keys }
10
-
11
- context 'using schemas' do
12
- before { Apartment.use_schemas = true }
13
-
14
- # Not sure why, but somehow using let(:tenant_names) memoizes for the whole example group, not just each test
15
- def tenant_names
16
- ActiveRecord::Base.connection.execute('SELECT nspname FROM pg_namespace;').collect { |row| row['nspname'] }
17
- end
18
-
19
- let(:default_tenant) { subject.switch { ActiveRecord::Base.connection.schema_search_path.gsub('"', '') } }
20
-
21
- it_should_behave_like 'a generic apartment adapter'
22
- it_should_behave_like 'a schema based apartment adapter'
23
- end
24
-
25
- context 'using databases' do
26
- before { Apartment.use_schemas = false }
27
-
28
- # Not sure why, but somehow using let(:tenant_names) memoizes for the whole example group, not just each test
29
- def tenant_names
30
- connection.execute('select datname from pg_database;').collect { |row| row['datname'] }
31
- end
32
-
33
- let(:default_tenant) { subject.switch { ActiveRecord::Base.connection.current_database } }
34
-
35
- it_should_behave_like 'a generic apartment adapter'
36
- it_should_behave_like 'a connection based apartment adapter'
37
- end
38
- end
39
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'apartment/adapters/mysql2_adapter'
5
-
6
- describe Apartment::Adapters::Mysql2Adapter, database: :mysql do
7
- unless defined?(JRUBY_VERSION)
8
-
9
- subject(:adapter) { Apartment::Tenant.mysql2_adapter config }
10
-
11
- def tenant_names
12
- ActiveRecord::Base.connection.execute('SELECT schema_name FROM information_schema.schemata').collect { |row| row[0] }
13
- end
14
-
15
- let(:default_tenant) { subject.switch { ActiveRecord::Base.connection.current_database } }
16
-
17
- context 'using - the equivalent of - schemas' do
18
- before { Apartment.use_schemas = true }
19
-
20
- it_should_behave_like 'a generic apartment adapter'
21
-
22
- describe '#default_tenant' do
23
- it 'is set to the original db from config' do
24
- expect(subject.default_tenant).to eq(config[:database])
25
- end
26
- end
27
-
28
- describe '#init' do
29
- include Apartment::Spec::AdapterRequirements
30
-
31
- before do
32
- Apartment.configure do |config|
33
- config.excluded_models = ['Company']
34
- end
35
- end
36
-
37
- after do
38
- # Apartment::Tenant.init creates per model connection.
39
- # Remove the connection after testing not to unintentionally keep the connection across tests.
40
- Apartment.excluded_models.each do |excluded_model|
41
- excluded_model.constantize.remove_connection
42
- end
43
- end
44
-
45
- it 'should process model exclusions' do
46
- Apartment::Tenant.init
47
-
48
- expect(Company.table_name).to eq("#{default_tenant}.companies")
49
- end
50
- end
51
- end
52
-
53
- context 'using connections' do
54
- before { Apartment.use_schemas = false }
55
-
56
- it_should_behave_like 'a generic apartment adapter'
57
- it_should_behave_like 'a generic apartment adapter able to handle custom configuration'
58
- it_should_behave_like 'a connection based apartment adapter'
59
- end
60
- end
61
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'apartment/adapters/postgresql_adapter'
5
-
6
- describe Apartment::Adapters::PostgresqlAdapter, database: :postgresql do
7
- unless defined?(JRUBY_VERSION)
8
-
9
- subject { Apartment::Tenant.postgresql_adapter config }
10
-
11
- context 'using schemas with schema.rb' do
12
- before { Apartment.use_schemas = true }
13
-
14
- # Not sure why, but somehow using let(:tenant_names) memoizes for the whole example group, not just each test
15
- def tenant_names
16
- ActiveRecord::Base.connection.execute('SELECT nspname FROM pg_namespace;').collect { |row| row['nspname'] }
17
- end
18
-
19
- let(:default_tenant) { subject.switch { ActiveRecord::Base.connection.schema_search_path.gsub('"', '') } }
20
-
21
- it_should_behave_like 'a generic apartment adapter'
22
- it_should_behave_like 'a schema based apartment adapter'
23
- end
24
-
25
- context 'using schemas with SQL dump' do
26
- before do
27
- Apartment.use_schemas = true
28
- Apartment.use_sql = true
29
- end
30
-
31
- # Not sure why, but somehow using let(:tenant_names) memoizes for the whole example group, not just each test
32
- def tenant_names
33
- ActiveRecord::Base.connection.execute('SELECT nspname FROM pg_namespace;').collect { |row| row['nspname'] }
34
- end
35
-
36
- let(:default_tenant) { subject.switch { ActiveRecord::Base.connection.schema_search_path.gsub('"', '') } }
37
-
38
- it_should_behave_like 'a generic apartment adapter'
39
- it_should_behave_like 'a schema based apartment adapter'
40
-
41
- it 'allows for dashes in the schema name' do
42
- expect { Apartment::Tenant.create('has-dashes') }.to_not raise_error
43
- end
44
-
45
- after { Apartment::Tenant.drop('has-dashes') if Apartment.connection.schema_exists? 'has-dashes' }
46
- end
47
-
48
- context 'using connections' do
49
- before { Apartment.use_schemas = false }
50
-
51
- # Not sure why, but somehow using let(:tenant_names) memoizes for the whole example group, not just each test
52
- def tenant_names
53
- connection.execute('select datname from pg_database;').collect { |row| row['datname'] }
54
- end
55
-
56
- let(:default_tenant) { subject.switch { ActiveRecord::Base.connection.current_database } }
57
-
58
- it_should_behave_like 'a generic apartment adapter'
59
- it_should_behave_like 'a generic apartment adapter able to handle custom configuration'
60
- it_should_behave_like 'a connection based apartment adapter'
61
- end
62
- end
63
- end
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'apartment/adapters/sqlite3_adapter'
5
-
6
- describe Apartment::Adapters::Sqlite3Adapter, database: :sqlite do
7
- unless defined?(JRUBY_VERSION)
8
-
9
- subject { Apartment::Tenant.sqlite3_adapter config }
10
-
11
- context 'using connections' do
12
- def tenant_names
13
- db_dir = File.expand_path('../dummy/db', __dir__)
14
- Dir.glob("#{db_dir}/*.sqlite3").map { |file| File.basename(file, '.sqlite3') }
15
- end
16
-
17
- let(:default_tenant) do
18
- subject.switch { File.basename(Apartment::Test.config['connections']['sqlite']['database'], '.sqlite3') }
19
- end
20
-
21
- it_should_behave_like 'a generic apartment adapter'
22
- it_should_behave_like 'a connection based apartment adapter'
23
-
24
- after(:all) do
25
- File.delete(Apartment::Test.config['connections']['sqlite']['database'])
26
- end
27
- end
28
-
29
- context 'with prepend and append' do
30
- let(:default_dir) { File.expand_path(File.dirname(config[:database])) }
31
- describe '#prepend' do
32
- let(:db_name) { 'db_with_prefix' }
33
- before do
34
- Apartment.configure do |config|
35
- config.prepend_environment = true
36
- config.append_environment = false
37
- end
38
- end
39
-
40
- after do
41
- begin
42
- subject.drop db_name
43
- rescue StandardError => _e
44
- nil
45
- end
46
- end
47
-
48
- it 'should create a new database' do
49
- subject.create db_name
50
-
51
- expect(File.exist?("#{default_dir}/#{Rails.env}_#{db_name}.sqlite3")).to eq true
52
- end
53
- end
54
-
55
- describe '#neither' do
56
- let(:db_name) { 'db_without_prefix_suffix' }
57
- before do
58
- Apartment.configure { |config| config.prepend_environment = config.append_environment = false }
59
- end
60
-
61
- after do
62
- begin
63
- subject.drop db_name
64
- rescue StandardError => _e
65
- nil
66
- end
67
- end
68
-
69
- it 'should create a new database' do
70
- subject.create db_name
71
-
72
- expect(File.exist?("#{default_dir}/#{db_name}.sqlite3")).to eq true
73
- end
74
- end
75
-
76
- describe '#append' do
77
- let(:db_name) { 'db_with_suffix' }
78
- before do
79
- Apartment.configure do |config|
80
- config.prepend_environment = false
81
- config.append_environment = true
82
- end
83
- end
84
-
85
- after do
86
- begin
87
- subject.drop db_name
88
- rescue StandardError => _e
89
- nil
90
- end
91
- end
92
-
93
- it 'should create a new database' do
94
- subject.create db_name
95
-
96
- expect(File.exist?("#{default_dir}/#{db_name}_#{Rails.env}.sqlite3")).to eq true
97
- end
98
- end
99
- end
100
- end
101
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Apartment do
6
- it 'should be valid' do
7
- expect(Apartment).to be_a(Module)
8
- end
9
-
10
- it 'should be a valid app' do
11
- expect(::Rails.application).to be_a(Dummy::Application)
12
- end
13
- end