apartment 0.26.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -1
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +9 -0
  5. data/HISTORY.md +8 -0
  6. data/README.md +30 -7
  7. data/TODO.md +9 -0
  8. data/apartment.gemspec +9 -8
  9. data/lib/apartment.rb +9 -18
  10. data/lib/apartment/adapters/abstract_adapter.rb +63 -30
  11. data/lib/apartment/adapters/jdbc_mysql_adapter.rb +2 -2
  12. data/lib/apartment/adapters/jdbc_postgresql_adapter.rb +3 -3
  13. data/lib/apartment/adapters/mysql2_adapter.rb +10 -6
  14. data/lib/apartment/adapters/postgresql_adapter.rb +15 -21
  15. data/lib/apartment/adapters/sqlite3_adapter.rb +4 -4
  16. data/lib/apartment/deprecation.rb +13 -0
  17. data/lib/apartment/elevators/generic.rb +3 -2
  18. data/lib/apartment/elevators/host_hash.rb +1 -1
  19. data/lib/apartment/migrator.rb +3 -3
  20. data/lib/apartment/tasks/enhancements.rb +31 -21
  21. data/lib/apartment/tenant.rb +10 -7
  22. data/lib/apartment/version.rb +1 -1
  23. data/lib/generators/apartment/install/templates/apartment.rb +41 -22
  24. data/lib/tasks/apartment.rake +1 -1
  25. data/spec/adapters/jdbc_mysql_adapter_spec.rb +1 -1
  26. data/spec/adapters/jdbc_postgresql_adapter_spec.rb +2 -2
  27. data/spec/adapters/mysql2_adapter_spec.rb +4 -2
  28. data/spec/adapters/postgresql_adapter_spec.rb +3 -3
  29. data/spec/adapters/sqlite3_adapter_spec.rb +1 -1
  30. data/spec/dummy_engine/.gitignore +8 -0
  31. data/spec/dummy_engine/Gemfile +15 -0
  32. data/spec/dummy_engine/Rakefile +34 -0
  33. data/spec/dummy_engine/bin/rails +12 -0
  34. data/spec/dummy_engine/config/initializers/apartment.rb +51 -0
  35. data/spec/dummy_engine/dummy_engine.gemspec +24 -0
  36. data/spec/dummy_engine/lib/dummy_engine.rb +4 -0
  37. data/spec/dummy_engine/lib/dummy_engine/engine.rb +4 -0
  38. data/spec/dummy_engine/lib/dummy_engine/version.rb +3 -0
  39. data/spec/dummy_engine/test/dummy/Rakefile +6 -0
  40. data/spec/dummy_engine/test/dummy/config.ru +4 -0
  41. data/spec/dummy_engine/test/dummy/config/application.rb +22 -0
  42. data/spec/dummy_engine/test/dummy/config/boot.rb +5 -0
  43. data/spec/dummy_engine/test/dummy/config/database.yml +25 -0
  44. data/spec/dummy_engine/test/dummy/config/environment.rb +5 -0
  45. data/spec/dummy_engine/test/dummy/config/environments/development.rb +37 -0
  46. data/spec/dummy_engine/test/dummy/config/environments/production.rb +78 -0
  47. data/spec/dummy_engine/test/dummy/config/environments/test.rb +39 -0
  48. data/spec/dummy_engine/test/dummy/config/initializers/assets.rb +8 -0
  49. data/spec/dummy_engine/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  50. data/spec/dummy_engine/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  51. data/spec/dummy_engine/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  52. data/spec/dummy_engine/test/dummy/config/initializers/inflections.rb +16 -0
  53. data/spec/dummy_engine/test/dummy/config/initializers/mime_types.rb +4 -0
  54. data/spec/dummy_engine/test/dummy/config/initializers/session_store.rb +3 -0
  55. data/spec/dummy_engine/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  56. data/spec/dummy_engine/test/dummy/config/locales/en.yml +23 -0
  57. data/spec/dummy_engine/test/dummy/config/routes.rb +56 -0
  58. data/spec/dummy_engine/test/dummy/config/secrets.yml +22 -0
  59. data/spec/examples/connection_adapter_examples.rb +5 -5
  60. data/spec/examples/generic_adapter_examples.rb +75 -37
  61. data/spec/examples/schema_adapter_examples.rb +19 -24
  62. data/spec/integration/query_caching_spec.rb +3 -3
  63. data/spec/integration/use_within_an_engine_spec.rb +28 -0
  64. data/spec/spec_helper.rb +1 -1
  65. data/spec/support/setup.rb +9 -9
  66. data/spec/{database_spec.rb → tenant_spec.rb} +20 -30
  67. data/spec/unit/config_spec.rb +2 -2
  68. data/spec/unit/elevators/domain_spec.rb +1 -1
  69. data/spec/unit/elevators/generic_spec.rb +2 -2
  70. data/spec/unit/elevators/host_hash_spec.rb +5 -5
  71. data/spec/unit/elevators/subdomain_spec.rb +2 -2
  72. data/spec/unit/migrator_spec.rb +7 -7
  73. metadata +104 -43
@@ -26,16 +26,16 @@ describe 'query caching' do
26
26
 
27
27
  it 'clears the ActiveRecord::QueryCache after switching databases' do
28
28
  db_names.each do |db_name|
29
- Apartment::Tenant.switch db_name
29
+ Apartment::Tenant.switch! db_name
30
30
  User.create! name: db_name
31
31
  end
32
32
 
33
33
  ActiveRecord::Base.connection.enable_query_cache!
34
34
 
35
- Apartment::Tenant.switch db_names.first
35
+ Apartment::Tenant.switch! db_names.first
36
36
  User.find_by_name(db_names.first).name.should == db_names.first
37
37
 
38
- Apartment::Tenant.switch db_names.last
38
+ Apartment::Tenant.switch! db_names.last
39
39
  User.find_by_name(db_names.first).should be_nil
40
40
  end
41
41
  end
@@ -0,0 +1,28 @@
1
+ describe 'using apartment within an engine' do
2
+
3
+ before do
4
+ engine_path = Pathname.new(File.expand_path('../../dummy_engine', __FILE__))
5
+ require engine_path.join('test/dummy/config/application')
6
+ @rake = Rake::Application.new
7
+ Rake.application = @rake
8
+ stub_const 'APP_RAKEFILE', engine_path.join('test/dummy/Rakefile')
9
+ load 'rails/tasks/engine.rake'
10
+ end
11
+
12
+ it 'sucessfully runs rake db:migrate in the engine root' do
13
+ expect{ Rake::Task['db:migrate'].invoke }.to_not raise_error
14
+ end
15
+
16
+ it 'sucessfully runs rake app:db:migrate in the engine root' do
17
+ expect{ Rake::Task['app:db:migrate'].invoke }.to_not raise_error
18
+ end
19
+
20
+ context 'when Apartment.db_migrate_tenants is false' do
21
+ it 'should not enhance tasks' do
22
+ Apartment.db_migrate_tenants = false
23
+ expect(Apartment::RakeTaskEnhancer).to_not receive(:enhance_task).with('db:migrate')
24
+ Rake::Task['db:migrate'].invoke
25
+ end
26
+ end
27
+
28
+ end
@@ -29,7 +29,7 @@ RSpec.configure do |config|
29
29
  config.include Apartment::Spec::Setup
30
30
 
31
31
  # Somewhat brutal hack so that rails 4 postgres extensions don't modify this file
32
- config.after(:suite) do
32
+ config.after(:all) do
33
33
  `git checkout -- spec/dummy/db/schema.rb`
34
34
  end
35
35
  end
@@ -4,8 +4,6 @@ module Apartment
4
4
 
5
5
  def self.included(base)
6
6
  base.instance_eval do
7
- let(:config){ database_config }
8
-
9
7
  let(:db1){ Apartment::Test.next_db }
10
8
  let(:db2){ Apartment::Test.next_db }
11
9
  let(:connection){ ActiveRecord::Base.connection }
@@ -14,6 +12,13 @@ module Apartment
14
12
  # any before/after hooks defined in individual tests
15
13
  # Otherwise these actually get run after test defined hooks
16
14
  around(:each) do |example|
15
+
16
+ def config
17
+ db = example.metadata.fetch(:database, :postgresql)
18
+
19
+ Apartment::Test.config['connections'][db.to_s].symbolize_keys
20
+ end
21
+
17
22
  # before
18
23
  Apartment::Tenant.reload!(config)
19
24
  ActiveRecord::Base.establish_connection config
@@ -26,7 +31,7 @@ module Apartment
26
31
 
27
32
  Apartment.excluded_models.each do |model|
28
33
  klass = model.constantize
29
-
34
+
30
35
  Apartment.connection_class.remove_connection(klass)
31
36
  klass.clear_all_connections!
32
37
  klass.reset_table_name
@@ -37,11 +42,6 @@ module Apartment
37
42
  end
38
43
  end
39
44
  end
40
-
41
- def database_config
42
- db = example.metadata.fetch(:database, :postgresql)
43
- Apartment::Test.config['connections'][db.to_s].symbolize_keys
44
- end
45
45
  end
46
46
  end
47
- end
47
+ end
@@ -3,26 +3,19 @@ require 'spec_helper'
3
3
  describe Apartment::Tenant do
4
4
  context "using mysql", database: :mysql do
5
5
 
6
- before do
7
- subject.stub(:config).and_return config # Use mysql database config for this test
8
- end
6
+ before { subject.reload!(config) }
9
7
 
10
8
  describe "#adapter" do
11
- before do
12
- subject.reload!
13
- end
14
-
15
9
  it "should load mysql adapter" do
16
10
  subject.adapter
17
- Apartment::Adapters::Mysql2Adapter.should be_a(Class)
11
+ expect(Apartment::Adapters::Mysql2Adapter).to be_a(Class)
18
12
  end
19
13
  end
20
14
 
21
15
  # TODO this doesn't belong here, but there aren't integration tests currently for mysql
22
16
  # where to put???
23
- describe "#exception recovery", :type => :request do
17
+ describe "exception recovery", :type => :request do
24
18
  before do
25
- subject.reload!
26
19
  subject.create db1
27
20
  end
28
21
  after{ subject.drop db1 }
@@ -37,6 +30,7 @@ describe Apartment::Tenant do
37
30
  # end
38
31
  end
39
32
 
33
+ # TODO re-organize these tests
40
34
  context "with prefix and schemas" do
41
35
  describe "#create" do
42
36
  before do
@@ -45,7 +39,7 @@ describe Apartment::Tenant do
45
39
  config.use_schemas = true
46
40
  end
47
41
 
48
- subject.reload!(config) # switch to Mysql2SchemaAdapter
42
+ subject.reload!(config)
49
43
  end
50
44
 
51
45
  after { subject.drop "db_with_prefix" rescue nil }
@@ -60,21 +54,17 @@ describe Apartment::Tenant do
60
54
  context "using postgresql", database: :postgresql do
61
55
  before do
62
56
  Apartment.use_schemas = true
63
- subject.stub(:config).and_return config # Use postgresql database config for this test
57
+ subject.reload!(config)
64
58
  end
65
59
 
66
60
  describe "#adapter" do
67
- before do
68
- subject.reload!
69
- end
70
-
71
61
  it "should load postgresql adapter" do
72
62
  subject.adapter
73
63
  Apartment::Adapters::PostgresqlAdapter.should be_a(Class)
74
64
  end
75
65
 
76
- it "should raise exception with invalid adapter specified" do
77
- subject.stub(:config).and_return config.merge(:adapter => 'unknown')
66
+ it "raises exception with invalid adapter specified" do
67
+ subject.reload!(config.merge(adapter: 'unknown'))
78
68
 
79
69
  expect {
80
70
  Apartment::Tenant.adapter
@@ -83,19 +73,19 @@ describe Apartment::Tenant do
83
73
 
84
74
  context "threadsafety" do
85
75
  before { subject.create db1 }
86
- after { subject.drop db1 }
76
+ after { subject.drop db1 }
87
77
 
88
78
  it 'has a threadsafe adapter' do
89
- subject.switch(db1)
90
- thread = Thread.new { subject.current_tenant.should == Apartment.default_schema }
79
+ subject.switch!(db1)
80
+ thread = Thread.new { subject.current.should == Apartment.default_tenant }
91
81
  thread.join
92
- subject.current_tenant.should == db1
82
+ subject.current.should == db1
93
83
  end
94
84
  end
95
85
  end
96
86
 
87
+ # TODO above spec are also with use_schemas=true
97
88
  context "with schemas" do
98
-
99
89
  before do
100
90
  Apartment.configure do |config|
101
91
  config.excluded_models = []
@@ -109,12 +99,12 @@ describe Apartment::Tenant do
109
99
 
110
100
  describe "#create" do
111
101
  it "should seed data" do
112
- subject.switch db1
102
+ subject.switch! db1
113
103
  User.count.should be > 0
114
104
  end
115
105
  end
116
106
 
117
- describe "#switch" do
107
+ describe "#switch!" do
118
108
 
119
109
  let(:x){ rand(3) }
120
110
 
@@ -124,16 +114,16 @@ describe Apartment::Tenant do
124
114
  after{ subject.drop db2 }
125
115
 
126
116
  it "should create a model instance in the current schema" do
127
- subject.switch db2
117
+ subject.switch! db2
128
118
  db2_count = User.count + x.times{ User.create }
129
119
 
130
- subject.switch db1
120
+ subject.switch! db1
131
121
  db_count = User.count + x.times{ User.create }
132
122
 
133
- subject.switch db2
123
+ subject.switch! db2
134
124
  User.count.should == db2_count
135
125
 
136
- subject.switch db1
126
+ subject.switch! db1
137
127
  User.count.should == db_count
138
128
  end
139
129
  end
@@ -151,7 +141,7 @@ describe Apartment::Tenant do
151
141
  subject.reset # ensure we're on public schema
152
142
  count = Company.count + x.times{ Company.create }
153
143
 
154
- subject.switch db1
144
+ subject.switch! db1
155
145
  x.times{ Company.create }
156
146
  Company.count.should == count + x
157
147
  subject.reset
@@ -25,7 +25,7 @@ describe Apartment do
25
25
  config.excluded_models = []
26
26
  config.use_schemas = false
27
27
  end
28
- Apartment.use_schemas.should be_false
28
+ Apartment.use_schemas.should be false
29
29
  end
30
30
 
31
31
  it "should set seed_after_create" do
@@ -33,7 +33,7 @@ describe Apartment do
33
33
  config.excluded_models = []
34
34
  config.seed_after_create = true
35
35
  end
36
- Apartment.seed_after_create.should be_true
36
+ Apartment.seed_after_create.should be true
37
37
  end
38
38
 
39
39
  it "should set tld_length" do
@@ -24,7 +24,7 @@ describe Apartment::Elevators::Domain do
24
24
 
25
25
  describe "#call" do
26
26
  it "switches to the proper tenant" do
27
- Apartment::Tenant.should_receive(:switch).with('example')
27
+ Apartment::Tenant.should_receive(:switch!).with('example')
28
28
 
29
29
  elevator.call('HTTP_HOST' => 'www.example.com')
30
30
  end
@@ -15,7 +15,7 @@ describe Apartment::Elevators::Generic do
15
15
  it "calls the processor if given" do
16
16
  elevator = described_class.new(Proc.new{}, Proc.new{'tenant1'})
17
17
 
18
- Apartment::Tenant.should_receive(:switch).with('tenant1')
18
+ Apartment::Tenant.should_receive(:switch!).with('tenant1')
19
19
 
20
20
  elevator.call('HTTP_HOST' => 'foo.bar.com')
21
21
  end
@@ -29,7 +29,7 @@ describe Apartment::Elevators::Generic do
29
29
  it "switches to the parsed db_name" do
30
30
  elevator = MyElevator.new(Proc.new{})
31
31
 
32
- Apartment::Tenant.should_receive(:switch).with('tenant2')
32
+ Apartment::Tenant.should_receive(:switch!).with('tenant2')
33
33
 
34
34
  elevator.call('HTTP_HOST' => 'foo.bar.com')
35
35
  end
@@ -11,20 +11,20 @@ describe Apartment::Elevators::HostHash do
11
11
  elevator.parse_tenant_name(request).should == 'example_tenant'
12
12
  end
13
13
 
14
- it "raises DatabaseNotFound exception if there is no host" do
14
+ it "raises TenantNotFound exception if there is no host" do
15
15
  request = ActionDispatch::Request.new('HTTP_HOST' => '')
16
- expect { elevator.parse_tenant_name(request) }.to raise_error(Apartment::DatabaseNotFound)
16
+ expect { elevator.parse_tenant_name(request) }.to raise_error(Apartment::TenantNotFound)
17
17
  end
18
18
 
19
- it "raises DatabaseNotFound exception if there is no database associated to current host" do
19
+ it "raises TenantNotFound exception if there is no database associated to current host" do
20
20
  request = ActionDispatch::Request.new('HTTP_HOST' => 'example2.com')
21
- expect { elevator.parse_tenant_name(request) }.to raise_error(Apartment::DatabaseNotFound)
21
+ expect { elevator.parse_tenant_name(request) }.to raise_error(Apartment::TenantNotFound)
22
22
  end
23
23
  end
24
24
 
25
25
  describe "#call" do
26
26
  it "switches to the proper tenant" do
27
- Apartment::Tenant.should_receive(:switch).with('example_tenant')
27
+ Apartment::Tenant.should_receive(:switch!).with('example_tenant')
28
28
 
29
29
  elevator.call('HTTP_HOST' => 'example.com')
30
30
  end
@@ -39,14 +39,14 @@ describe Apartment::Elevators::Subdomain do
39
39
 
40
40
  describe "#call" do
41
41
  it "switches to the proper tenant" do
42
- Apartment::Tenant.should_receive(:switch).with('tenant1')
42
+ Apartment::Tenant.should_receive(:switch!).with('tenant1')
43
43
  elevator.call('HTTP_HOST' => 'tenant1.example.com')
44
44
  end
45
45
 
46
46
  it "ignores excluded subdomains" do
47
47
  described_class.excluded_subdomains = %w{foo}
48
48
 
49
- Apartment::Tenant.should_not_receive(:switch)
49
+ Apartment::Tenant.should_not_receive(:switch!)
50
50
 
51
51
  elevator.call('HTTP_HOST' => 'foo.bar.com')
52
52
 
@@ -9,8 +9,8 @@ describe Apartment::Migrator do
9
9
  before { Apartment::Tenant.adapter.stub(:connect_to_new) }
10
10
 
11
11
  describe "::migrate" do
12
- it "processes and migrates" do
13
- expect(Apartment::Tenant).to receive(:process).with(tenant).and_call_original
12
+ it "switches and migrates" do
13
+ expect(Apartment::Tenant).to receive(:switch).with(tenant).and_call_original
14
14
  expect(ActiveRecord::Migrator).to receive(:migrate)
15
15
 
16
16
  Apartment::Migrator.migrate(tenant)
@@ -18,8 +18,8 @@ describe Apartment::Migrator do
18
18
  end
19
19
 
20
20
  describe "::run" do
21
- it "processes and runs" do
22
- expect(Apartment::Tenant).to receive(:process).with(tenant).and_call_original
21
+ it "switches and runs" do
22
+ expect(Apartment::Tenant).to receive(:switch).with(tenant).and_call_original
23
23
  expect(ActiveRecord::Migrator).to receive(:run).with(:up, anything, 1234)
24
24
 
25
25
  Apartment::Migrator.run(:up, tenant, 1234)
@@ -27,11 +27,11 @@ describe Apartment::Migrator do
27
27
  end
28
28
 
29
29
  describe "::rollback" do
30
- it "processes and rolls back" do
31
- expect(Apartment::Tenant).to receive(:process).with(tenant).and_call_original
30
+ it "switches and rolls back" do
31
+ expect(Apartment::Tenant).to receive(:switch).with(tenant).and_call_original
32
32
  expect(ActiveRecord::Migrator).to receive(:rollback).with(anything, 2)
33
33
 
34
34
  Apartment::Migrator.rollback(tenant, 2)
35
35
  end
36
36
  end
37
- end
37
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apartment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brunner
@@ -9,152 +9,152 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-13 00:00:00.000000000 Z
12
+ date: 2015-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: 3.1.2
21
- - - <
21
+ - - "<"
22
22
  - !ruby/object:Gem::Version
23
23
  version: '5.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
- - - '>='
28
+ - - ">="
29
29
  - !ruby/object:Gem::Version
30
30
  version: 3.1.2
31
- - - <
31
+ - - "<"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '5.0'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rack
36
36
  requirement: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.3.6
41
41
  type: :runtime
42
42
  prerelease: false
43
43
  version_requirements: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.3.6
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: appraisal
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rake
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.9'
69
69
  type: :development
70
70
  prerelease: false
71
71
  version_requirements: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.9'
76
76
  - !ruby/object:Gem::Dependency
77
77
  name: rspec-rails
78
78
  requirement: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.14'
83
83
  type: :development
84
84
  prerelease: false
85
85
  version_requirements: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '2.14'
90
90
  - !ruby/object:Gem::Dependency
91
91
  name: guard-rspec
92
92
  requirement: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '4.2'
97
97
  type: :development
98
98
  prerelease: false
99
99
  version_requirements: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '4.2'
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: capybara
106
106
  requirement: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 1.0.0
110
+ version: '2.0'
111
111
  type: :development
112
112
  prerelease: false
113
113
  version_requirements: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 1.0.0
117
+ version: '2.0'
118
118
  - !ruby/object:Gem::Dependency
119
119
  name: mysql2
120
120
  requirement: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.3.10
125
125
  type: :development
126
126
  prerelease: false
127
127
  version_requirements: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ~>
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
131
  version: 0.3.10
132
132
  - !ruby/object:Gem::Dependency
133
133
  name: pg
134
134
  requirement: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: 0.11.0
139
139
  type: :development
140
140
  prerelease: false
141
141
  version_requirements: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - '>='
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: 0.11.0
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: sqlite3
148
148
  requirement: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  type: :development
154
154
  prerelease: false
155
155
  version_requirements: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - '>='
157
+ - - ">="
158
158
  - !ruby/object:Gem::Version
159
159
  version: '0'
160
160
  description: Apartment allows Rack applications to deal with database multitenancy
@@ -166,12 +166,12 @@ executables: []
166
166
  extensions: []
167
167
  extra_rdoc_files: []
168
168
  files:
169
- - .gitignore
170
- - .pryrc
171
- - .rspec
172
- - .ruby-gemset
173
- - .ruby-version
174
- - .travis.yml
169
+ - ".gitignore"
170
+ - ".pryrc"
171
+ - ".rspec"
172
+ - ".ruby-gemset"
173
+ - ".ruby-version"
174
+ - ".travis.yml"
175
175
  - Appraisals
176
176
  - Gemfile
177
177
  - Guardfile
@@ -194,6 +194,7 @@ files:
194
194
  - lib/apartment/adapters/postgresql_adapter.rb
195
195
  - lib/apartment/adapters/sqlite3_adapter.rb
196
196
  - lib/apartment/console.rb
197
+ - lib/apartment/deprecation.rb
197
198
  - lib/apartment/elevators/domain.rb
198
199
  - lib/apartment/elevators/first_subdomain.rb
199
200
  - lib/apartment/elevators/generic.rb
@@ -216,7 +217,6 @@ files:
216
217
  - spec/adapters/sqlite3_adapter_spec.rb
217
218
  - spec/apartment_spec.rb
218
219
  - spec/config/database.yml.sample
219
- - spec/database_spec.rb
220
220
  - spec/dummy/Rakefile
221
221
  - spec/dummy/app/controllers/application_controller.rb
222
222
  - spec/dummy/app/helpers/application_helper.rb
@@ -251,11 +251,41 @@ files:
251
251
  - spec/dummy/public/favicon.ico
252
252
  - spec/dummy/public/stylesheets/.gitkeep
253
253
  - spec/dummy/script/rails
254
+ - spec/dummy_engine/.gitignore
255
+ - spec/dummy_engine/Gemfile
256
+ - spec/dummy_engine/Rakefile
257
+ - spec/dummy_engine/bin/rails
258
+ - spec/dummy_engine/config/initializers/apartment.rb
259
+ - spec/dummy_engine/dummy_engine.gemspec
260
+ - spec/dummy_engine/lib/dummy_engine.rb
261
+ - spec/dummy_engine/lib/dummy_engine/engine.rb
262
+ - spec/dummy_engine/lib/dummy_engine/version.rb
263
+ - spec/dummy_engine/test/dummy/Rakefile
264
+ - spec/dummy_engine/test/dummy/config.ru
265
+ - spec/dummy_engine/test/dummy/config/application.rb
266
+ - spec/dummy_engine/test/dummy/config/boot.rb
267
+ - spec/dummy_engine/test/dummy/config/database.yml
268
+ - spec/dummy_engine/test/dummy/config/environment.rb
269
+ - spec/dummy_engine/test/dummy/config/environments/development.rb
270
+ - spec/dummy_engine/test/dummy/config/environments/production.rb
271
+ - spec/dummy_engine/test/dummy/config/environments/test.rb
272
+ - spec/dummy_engine/test/dummy/config/initializers/assets.rb
273
+ - spec/dummy_engine/test/dummy/config/initializers/backtrace_silencers.rb
274
+ - spec/dummy_engine/test/dummy/config/initializers/cookies_serializer.rb
275
+ - spec/dummy_engine/test/dummy/config/initializers/filter_parameter_logging.rb
276
+ - spec/dummy_engine/test/dummy/config/initializers/inflections.rb
277
+ - spec/dummy_engine/test/dummy/config/initializers/mime_types.rb
278
+ - spec/dummy_engine/test/dummy/config/initializers/session_store.rb
279
+ - spec/dummy_engine/test/dummy/config/initializers/wrap_parameters.rb
280
+ - spec/dummy_engine/test/dummy/config/locales/en.yml
281
+ - spec/dummy_engine/test/dummy/config/routes.rb
282
+ - spec/dummy_engine/test/dummy/config/secrets.yml
254
283
  - spec/examples/connection_adapter_examples.rb
255
284
  - spec/examples/generic_adapter_examples.rb
256
285
  - spec/examples/schema_adapter_examples.rb
257
286
  - spec/integration/apartment_rake_integration_spec.rb
258
287
  - spec/integration/query_caching_spec.rb
288
+ - spec/integration/use_within_an_engine_spec.rb
259
289
  - spec/schemas/v1.rb
260
290
  - spec/schemas/v2.rb
261
291
  - spec/schemas/v3.rb
@@ -267,6 +297,7 @@ files:
267
297
  - spec/support/requirements.rb
268
298
  - spec/support/setup.rb
269
299
  - spec/tasks/apartment_rake_spec.rb
300
+ - spec/tenant_spec.rb
270
301
  - spec/unit/config_spec.rb
271
302
  - spec/unit/elevators/domain_spec.rb
272
303
  - spec/unit/elevators/first_subdomain_spec.rb
@@ -284,13 +315,13 @@ post_install_message: |2
284
315
 
285
316
  Apartment Deprecation Warning
286
317
 
287
- `Apartment::Database` has been deprecated in favour of `Apartment::Tenant`.
288
- Please update your application to use the new constant as it is a more
289
- appropriate abstraction.
318
+ `Apartment::Tenant.process` has been deprecated in favour of `Apartment::Tenant.switch`.
319
+ You must now always pass a block to `switch`.
290
320
 
291
- To further this, DatabaseNotFound, SchemaNotFound, DatabaseExists and
292
- SchemaExists exceptions will all be removed, you should instead use
293
- TenantNotFound and TenantExists to catch any exceptions.
321
+ To get the previous `switch` behaviour where you can switch to a tenant
322
+ without a block, use `Apartment::Tenant.switch!`.
323
+ This is to indicate that your call actually has a side affect of changing
324
+ the scope of your queries to that tenant.
294
325
 
295
326
  ********************************
296
327
  rdoc_options: []
@@ -298,17 +329,17 @@ require_paths:
298
329
  - lib
299
330
  required_ruby_version: !ruby/object:Gem::Requirement
300
331
  requirements:
301
- - - '>='
332
+ - - ">="
302
333
  - !ruby/object:Gem::Version
303
334
  version: '0'
304
335
  required_rubygems_version: !ruby/object:Gem::Requirement
305
336
  requirements:
306
- - - '>='
337
+ - - ">="
307
338
  - !ruby/object:Gem::Version
308
339
  version: '0'
309
340
  requirements: []
310
341
  rubyforge_project:
311
- rubygems_version: 2.2.2
342
+ rubygems_version: 2.4.3
312
343
  signing_key:
313
344
  specification_version: 4
314
345
  summary: A Ruby gem for managing database multitenancy
@@ -320,7 +351,6 @@ test_files:
320
351
  - spec/adapters/sqlite3_adapter_spec.rb
321
352
  - spec/apartment_spec.rb
322
353
  - spec/config/database.yml.sample
323
- - spec/database_spec.rb
324
354
  - spec/dummy/Rakefile
325
355
  - spec/dummy/app/controllers/application_controller.rb
326
356
  - spec/dummy/app/helpers/application_helper.rb
@@ -355,11 +385,41 @@ test_files:
355
385
  - spec/dummy/public/favicon.ico
356
386
  - spec/dummy/public/stylesheets/.gitkeep
357
387
  - spec/dummy/script/rails
388
+ - spec/dummy_engine/.gitignore
389
+ - spec/dummy_engine/Gemfile
390
+ - spec/dummy_engine/Rakefile
391
+ - spec/dummy_engine/bin/rails
392
+ - spec/dummy_engine/config/initializers/apartment.rb
393
+ - spec/dummy_engine/dummy_engine.gemspec
394
+ - spec/dummy_engine/lib/dummy_engine.rb
395
+ - spec/dummy_engine/lib/dummy_engine/engine.rb
396
+ - spec/dummy_engine/lib/dummy_engine/version.rb
397
+ - spec/dummy_engine/test/dummy/Rakefile
398
+ - spec/dummy_engine/test/dummy/config.ru
399
+ - spec/dummy_engine/test/dummy/config/application.rb
400
+ - spec/dummy_engine/test/dummy/config/boot.rb
401
+ - spec/dummy_engine/test/dummy/config/database.yml
402
+ - spec/dummy_engine/test/dummy/config/environment.rb
403
+ - spec/dummy_engine/test/dummy/config/environments/development.rb
404
+ - spec/dummy_engine/test/dummy/config/environments/production.rb
405
+ - spec/dummy_engine/test/dummy/config/environments/test.rb
406
+ - spec/dummy_engine/test/dummy/config/initializers/assets.rb
407
+ - spec/dummy_engine/test/dummy/config/initializers/backtrace_silencers.rb
408
+ - spec/dummy_engine/test/dummy/config/initializers/cookies_serializer.rb
409
+ - spec/dummy_engine/test/dummy/config/initializers/filter_parameter_logging.rb
410
+ - spec/dummy_engine/test/dummy/config/initializers/inflections.rb
411
+ - spec/dummy_engine/test/dummy/config/initializers/mime_types.rb
412
+ - spec/dummy_engine/test/dummy/config/initializers/session_store.rb
413
+ - spec/dummy_engine/test/dummy/config/initializers/wrap_parameters.rb
414
+ - spec/dummy_engine/test/dummy/config/locales/en.yml
415
+ - spec/dummy_engine/test/dummy/config/routes.rb
416
+ - spec/dummy_engine/test/dummy/config/secrets.yml
358
417
  - spec/examples/connection_adapter_examples.rb
359
418
  - spec/examples/generic_adapter_examples.rb
360
419
  - spec/examples/schema_adapter_examples.rb
361
420
  - spec/integration/apartment_rake_integration_spec.rb
362
421
  - spec/integration/query_caching_spec.rb
422
+ - spec/integration/use_within_an_engine_spec.rb
363
423
  - spec/schemas/v1.rb
364
424
  - spec/schemas/v2.rb
365
425
  - spec/schemas/v3.rb
@@ -371,6 +431,7 @@ test_files:
371
431
  - spec/support/requirements.rb
372
432
  - spec/support/setup.rb
373
433
  - spec/tasks/apartment_rake_spec.rb
434
+ - spec/tenant_spec.rb
374
435
  - spec/unit/config_spec.rb
375
436
  - spec/unit/elevators/domain_spec.rb
376
437
  - spec/unit/elevators/first_subdomain_spec.rb