ros-apartment 2.4.0 → 2.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/.rubocop_todo.yml +1 -1
  4. data/.story_branch.yml +1 -0
  5. data/.travis.yml +13 -30
  6. data/Appraisals +4 -17
  7. data/Gemfile +2 -2
  8. data/Guardfile +3 -1
  9. data/HISTORY.md +90 -0
  10. data/README.md +31 -16
  11. data/Rakefile +34 -22
  12. data/TODO.md +0 -1
  13. data/gemfiles/rails_5_0.gemfile +10 -11
  14. data/gemfiles/rails_5_1.gemfile +10 -11
  15. data/gemfiles/rails_5_2.gemfile +9 -10
  16. data/gemfiles/rails_6_0.gemfile +10 -11
  17. data/gemfiles/rails_master.gemfile +10 -11
  18. data/lib/apartment.rb +31 -13
  19. data/lib/apartment/active_record/connection_handling.rb +17 -0
  20. data/lib/apartment/active_record/internal_metadata.rb +11 -0
  21. data/lib/apartment/active_record/log_subscriber.rb +41 -0
  22. data/lib/apartment/active_record/schema_migration.rb +13 -0
  23. data/lib/apartment/adapters/abstract_adapter.rb +17 -13
  24. data/lib/apartment/adapters/jdbc_postgresql_adapter.rb +9 -4
  25. data/lib/apartment/adapters/mysql2_adapter.rb +2 -0
  26. data/lib/apartment/adapters/postgresql_adapter.rb +33 -4
  27. data/lib/apartment/adapters/sqlite3_adapter.rb +2 -0
  28. data/lib/apartment/console.rb +7 -0
  29. data/lib/apartment/custom_console.rb +23 -7
  30. data/lib/apartment/model.rb +27 -0
  31. data/lib/apartment/railtie.rb +19 -15
  32. data/lib/apartment/tasks/task_helper.rb +35 -0
  33. data/lib/apartment/tenant.rb +16 -5
  34. data/lib/apartment/version.rb +1 -1
  35. data/lib/generators/apartment/install/templates/apartment.rb +5 -0
  36. data/lib/tasks/apartment.rake +16 -37
  37. data/{apartment.gemspec → ros-apartment.gemspec} +12 -6
  38. metadata +16 -213
  39. data/.github/workflows/.rubocop-linter.yml +0 -22
  40. data/spec/adapters/jdbc_mysql_adapter_spec.rb +0 -20
  41. data/spec/adapters/jdbc_postgresql_adapter_spec.rb +0 -39
  42. data/spec/adapters/mysql2_adapter_spec.rb +0 -61
  43. data/spec/adapters/postgresql_adapter_spec.rb +0 -63
  44. data/spec/adapters/sqlite3_adapter_spec.rb +0 -101
  45. data/spec/apartment_spec.rb +0 -13
  46. data/spec/config/database.yml.sample +0 -49
  47. data/spec/dummy/Rakefile +0 -7
  48. data/spec/dummy/app/controllers/application_controller.rb +0 -7
  49. data/spec/dummy/app/helpers/application_helper.rb +0 -4
  50. data/spec/dummy/app/models/application_record.rb +0 -6
  51. data/spec/dummy/app/models/company.rb +0 -5
  52. data/spec/dummy/app/models/user.rb +0 -5
  53. data/spec/dummy/app/views/application/index.html.erb +0 -1
  54. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  55. data/spec/dummy/config.ru +0 -6
  56. data/spec/dummy/config/application.rb +0 -51
  57. data/spec/dummy/config/boot.rb +0 -13
  58. data/spec/dummy/config/database.yml.sample +0 -44
  59. data/spec/dummy/config/environment.rb +0 -7
  60. data/spec/dummy/config/environments/development.rb +0 -29
  61. data/spec/dummy/config/environments/production.rb +0 -53
  62. data/spec/dummy/config/environments/test.rb +0 -36
  63. data/spec/dummy/config/initializers/apartment.rb +0 -6
  64. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -8
  65. data/spec/dummy/config/initializers/inflections.rb +0 -11
  66. data/spec/dummy/config/initializers/mime_types.rb +0 -6
  67. data/spec/dummy/config/initializers/secret_token.rb +0 -9
  68. data/spec/dummy/config/initializers/session_store.rb +0 -10
  69. data/spec/dummy/config/locales/en.yml +0 -5
  70. data/spec/dummy/config/routes.rb +0 -5
  71. data/spec/dummy/db/migrate/20110613152810_create_dummy_models.rb +0 -39
  72. data/spec/dummy/db/migrate/20111202022214_create_table_books.rb +0 -14
  73. data/spec/dummy/db/migrate/20180415260934_create_public_tokens.rb +0 -13
  74. data/spec/dummy/db/schema.rb +0 -55
  75. data/spec/dummy/db/seeds.rb +0 -5
  76. data/spec/dummy/db/seeds/import.rb +0 -7
  77. data/spec/dummy/public/404.html +0 -26
  78. data/spec/dummy/public/422.html +0 -26
  79. data/spec/dummy/public/500.html +0 -26
  80. data/spec/dummy/public/favicon.ico +0 -0
  81. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  82. data/spec/dummy/script/rails +0 -8
  83. data/spec/dummy_engine/.gitignore +0 -8
  84. data/spec/dummy_engine/Gemfile +0 -15
  85. data/spec/dummy_engine/Rakefile +0 -34
  86. data/spec/dummy_engine/bin/rails +0 -12
  87. data/spec/dummy_engine/config/initializers/apartment.rb +0 -52
  88. data/spec/dummy_engine/dummy_engine.gemspec +0 -24
  89. data/spec/dummy_engine/lib/dummy_engine.rb +0 -6
  90. data/spec/dummy_engine/lib/dummy_engine/engine.rb +0 -6
  91. data/spec/dummy_engine/lib/dummy_engine/version.rb +0 -5
  92. data/spec/dummy_engine/test/dummy/Rakefile +0 -6
  93. data/spec/dummy_engine/test/dummy/config.ru +0 -6
  94. data/spec/dummy_engine/test/dummy/config/application.rb +0 -24
  95. data/spec/dummy_engine/test/dummy/config/boot.rb +0 -7
  96. data/spec/dummy_engine/test/dummy/config/database.yml +0 -25
  97. data/spec/dummy_engine/test/dummy/config/environment.rb +0 -7
  98. data/spec/dummy_engine/test/dummy/config/environments/development.rb +0 -39
  99. data/spec/dummy_engine/test/dummy/config/environments/production.rb +0 -80
  100. data/spec/dummy_engine/test/dummy/config/environments/test.rb +0 -41
  101. data/spec/dummy_engine/test/dummy/config/initializers/assets.rb +0 -10
  102. data/spec/dummy_engine/test/dummy/config/initializers/backtrace_silencers.rb +0 -8
  103. data/spec/dummy_engine/test/dummy/config/initializers/cookies_serializer.rb +0 -5
  104. data/spec/dummy_engine/test/dummy/config/initializers/filter_parameter_logging.rb +0 -6
  105. data/spec/dummy_engine/test/dummy/config/initializers/inflections.rb +0 -17
  106. data/spec/dummy_engine/test/dummy/config/initializers/mime_types.rb +0 -5
  107. data/spec/dummy_engine/test/dummy/config/initializers/session_store.rb +0 -5
  108. data/spec/dummy_engine/test/dummy/config/initializers/wrap_parameters.rb +0 -16
  109. data/spec/dummy_engine/test/dummy/config/locales/en.yml +0 -23
  110. data/spec/dummy_engine/test/dummy/config/routes.rb +0 -58
  111. data/spec/dummy_engine/test/dummy/config/secrets.yml +0 -22
  112. data/spec/examples/connection_adapter_examples.rb +0 -44
  113. data/spec/examples/generic_adapter_custom_configuration_example.rb +0 -93
  114. data/spec/examples/generic_adapter_examples.rb +0 -164
  115. data/spec/examples/schema_adapter_examples.rb +0 -239
  116. data/spec/integration/apartment_rake_integration_spec.rb +0 -107
  117. data/spec/integration/query_caching_spec.rb +0 -83
  118. data/spec/integration/use_within_an_engine_spec.rb +0 -28
  119. data/spec/schemas/v1.rb +0 -15
  120. data/spec/schemas/v2.rb +0 -41
  121. data/spec/schemas/v3.rb +0 -47
  122. data/spec/spec_helper.rb +0 -63
  123. data/spec/support/apartment_helpers.rb +0 -47
  124. data/spec/support/capybara_sessions.rb +0 -15
  125. data/spec/support/config.rb +0 -13
  126. data/spec/support/contexts.rb +0 -54
  127. data/spec/support/requirements.rb +0 -48
  128. data/spec/support/setup.rb +0 -46
  129. data/spec/tasks/apartment_rake_spec.rb +0 -124
  130. data/spec/tenant_spec.rb +0 -194
  131. data/spec/unit/config_spec.rb +0 -111
  132. data/spec/unit/elevators/domain_spec.rb +0 -33
  133. data/spec/unit/elevators/first_subdomain_spec.rb +0 -26
  134. data/spec/unit/elevators/generic_spec.rb +0 -55
  135. data/spec/unit/elevators/host_hash_spec.rb +0 -33
  136. data/spec/unit/elevators/host_spec.rb +0 -89
  137. data/spec/unit/elevators/subdomain_spec.rb +0 -77
  138. data/spec/unit/migrator_spec.rb +0 -78
  139. data/spec/unit/reloader_spec.rb +0 -24
@@ -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
@@ -1,49 +0,0 @@
1
- <% if defined?(JRUBY_VERSION) %>
2
- connections:
3
- postgresql:
4
- adapter: postgresql
5
- database: apartment_postgresql_test
6
- username: postgres
7
- min_messages: WARNING
8
- driver: org.postgresql.Driver
9
- url: jdbc:postgresql://localhost:5432/apartment_postgresql_test
10
- timeout: 5000
11
- pool: 5
12
- host: localhost
13
- port: 5432
14
-
15
- mysql:
16
- adapter: mysql
17
- database: apartment_mysql_test
18
- username: root
19
- min_messages: WARNING
20
- driver: com.mysql.jdbc.Driver
21
- url: jdbc:mysql://localhost:3306/apartment_mysql_test
22
- timeout: 5000
23
- pool: 5
24
- host: 127.0.0.1
25
- port: 3306
26
- <% else %>
27
- connections:
28
- postgresql:
29
- adapter: postgresql
30
- database: apartment_postgresql_test
31
- min_messages: WARNING
32
- username: postgres
33
- schema_search_path: public
34
- password:
35
- host: localhost
36
- port: 5432
37
-
38
- mysql:
39
- adapter: mysql2
40
- database: apartment_mysql_test
41
- username: root
42
- password:
43
- host: 127.0.0.1
44
- port: 3306
45
-
46
- sqlite:
47
- adapter: sqlite3
48
- database: <%= File.expand_path('../spec/dummy/db', __FILE__) %>/default.sqlite3
49
- <% end %>
@@ -1,7 +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 File.expand_path('../config/application', __FILE__)
5
- require 'rake'
6
-
7
- Dummy::Application.load_tasks
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ApplicationController < ActionController::Base
4
- protect_from_forgery
5
-
6
- def index; end
7
- end
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ApplicationHelper
4
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # NOTE: Dummy model base
4
- class ApplicationRecord < ActiveRecord::Base
5
- self.abstract_class = true
6
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Company < ApplicationRecord
4
- # Dummy models
5
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class User < ApplicationRecord
4
- # Dummy models
5
- end
@@ -1 +0,0 @@
1
- <h1>Index!!</h1>
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag :all %>
6
- <%= javascript_include_tag :defaults %>
7
- <%= csrf_meta_tag %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # This file is used by Rack-based servers to start the application.
4
-
5
- require ::File.expand_path('../config/environment', __FILE__)
6
- run Dummy::Application
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path('boot', __dir__)
4
-
5
- require 'active_model/railtie'
6
- require 'active_record/railtie'
7
- require 'action_controller/railtie'
8
- require 'action_view/railtie'
9
- require 'action_mailer/railtie'
10
-
11
- Bundler.require
12
- require 'apartment'
13
-
14
- module Dummy
15
- class Application < Rails::Application
16
- # Settings in config/environments/* take precedence over those specified here.
17
- # Application configuration should go into files in config/initializers
18
- # -- all .rb files in that directory are automatically loaded.
19
- require 'apartment/elevators/subdomain'
20
- require 'apartment/elevators/domain'
21
-
22
- config.middleware.use Apartment::Elevators::Subdomain
23
-
24
- # Custom directories with classes and modules you want to be autoloadable.
25
- config.autoload_paths += %W[#{config.root}/lib]
26
-
27
- # Only load the plugins named here, in the order given (default is alphabetical).
28
- # :all can be used as a placeholder for all plugins not explicitly named.
29
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
30
-
31
- # Activate observers that should always be running.
32
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
33
-
34
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
35
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
36
- # config.time_zone = 'Central Time (US & Canada)'
37
-
38
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
40
- # config.i18n.default_locale = :de
41
-
42
- # JavaScript files you want as :defaults (application.js is always included).
43
- # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
44
-
45
- # Configure the default encoding used in templates for Ruby 1.9.
46
- config.encoding = 'utf-8'
47
-
48
- # Configure sensitive parameters which will be filtered from the log file.
49
- config.filter_parameters += [:password]
50
- end
51
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubygems'
4
-
5
- gemfile = File.expand_path('../../../Gemfile', __dir__)
6
-
7
- if File.exist?(gemfile)
8
- ENV['BUNDLE_GEMFILE'] = gemfile
9
- require 'bundler'
10
- Bundler.setup
11
- end
12
-
13
- $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -1,44 +0,0 @@
1
- # Warning: The database defined as "test" will be erased and
2
- # re-generated from your development database when you run "rake".
3
- # Do not set this db to the same as development or production.
4
- <% if defined?(JRUBY_VERSION) %>
5
- test:
6
- adapter: postgresql
7
- database: apartment_postgresql_test
8
- username: postgres
9
- min_messages: WARNING
10
- driver: org.postgresql.Driver
11
- url: jdbc:postgresql://localhost:5432/apartment_postgresql_test
12
- timeout: 5000
13
- pool: 5
14
-
15
- development:
16
- adapter: postgresql
17
- database: apartment_postgresql_development
18
- username: postgres
19
- min_messages: WARNING
20
- driver: org.postgresql.Driver
21
- url: jdbc:postgresql://localhost:5432/apartment_postgresql_development
22
- timeout: 5000
23
- pool: 5
24
- <% else %>
25
- test:
26
- adapter: postgresql
27
- database: apartment_postgresql_test
28
- username: postgres
29
- min_messages: WARNING
30
- pool: 5
31
- timeout: 5000
32
- host: localhost
33
- port: 5432
34
-
35
- development:
36
- adapter: postgresql
37
- database: apartment_postgresql_development
38
- username: postgres
39
- min_messages: WARNING
40
- pool: 5
41
- timeout: 5000
42
- host: localhost
43
- port: 5432
44
- <% end %>
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Load the rails application
4
- require File.expand_path('application', __dir__)
5
-
6
- # Initialize the rails application
7
- Dummy::Application.initialize!
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Dummy::Application.configure do
4
- # Settings specified here will take precedence over those in config/application.rb
5
-
6
- # In the development environment your application's code is reloaded on
7
- # every request. This slows down response time but is perfect for development
8
- # since you don't have to restart the webserver when you make code changes.
9
- config.cache_classes = false
10
-
11
- config.eager_load = false
12
-
13
- # Log error messages when you accidentally call methods on nil.
14
- config.whiny_nils = true
15
-
16
- # Show full error reports and disable caching
17
- config.consider_all_requests_local = true
18
- config.action_view.debug_rjs = true
19
- config.action_controller.perform_caching = false
20
-
21
- # Don't care if the mailer can't send
22
- config.action_mailer.raise_delivery_errors = false
23
-
24
- # Print deprecation notices to the Rails logger
25
- config.active_support.deprecation = :log
26
-
27
- # Only use best-standards-support built into browsers
28
- config.action_dispatch.best_standards_support = :builtin
29
- end