motel-activerecord 2.0.1 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e6d9032d0282402d7614ce54ba275eece042195
4
- data.tar.gz: 69029443e84cbcbbfc29807f0d33ff3467412a80
3
+ metadata.gz: 9fbaa9ba220f8c8e43153d3a33126775ab84dd2d
4
+ data.tar.gz: 66c6308ddd2a4af6c95017774751f5f0a9da1bed
5
5
  SHA512:
6
- metadata.gz: 43978db6dc9237717afce5e7352162237227527542efacd971ef4063e91de2e99b4283728776944ee27f0fdff3f69574124b18f5a6a740abec519d5879d94459
7
- data.tar.gz: e524af21dd5090ea2921eee78481ae22eee9dc5336406f21df7c580fcee322b7d2a0f24f32eb6a389c69c6b76eeaf0d525e0fb047866146089bb6d73b035379b
6
+ metadata.gz: 4a3e16176b7af293e9ed37ca96bf9cecab919be0860b3ed8ae8ec4bff643ea8346aeb1a3d34a4c9ea7f3bfe6a3539f7ddc02f4395e23f6804269bd886a93391d
7
+ data.tar.gz: a5fbe186c1197d2d5cd9ef0be38abaa96cfbe785a2168f4651b733c752022c9ff745164976d2148b5db18c0934b37d690c4c520494215eb589dc449ae800fee0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.0.2
@@ -11,9 +11,11 @@ module Motel
11
11
  module ClassMethods
12
12
 
13
13
  def establish_connection(config)
14
- resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new(Motel::Manager.tenants)
15
- spec = resolver.spec(config)
16
- connection_handler.establish_connection (ENV['TENANT'] || self.name), spec
14
+ tenant_name = Motel::Manager.determines_tenant || self.name
15
+ resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new
16
+ spec = resolver.spec(config)
17
+
18
+ connection_handler.establish_connection tenant_name, spec
17
19
  end
18
20
 
19
21
  def connection_pool
@@ -53,7 +53,7 @@ describe Motel::ConnectionAdapters::ConnectionHandler do
53
53
  context 'existing tenant' do
54
54
 
55
55
  it 'initializes and returns a connection' do
56
- expect(@handler.retrieve_connection('foo')).to be_true
56
+ expect(@handler.retrieve_connection('foo')).to be_truthy
57
57
  end
58
58
 
59
59
  it 'returns a connection' do
@@ -80,7 +80,7 @@ describe Motel::ConnectionAdapters::ConnectionHandler do
80
80
  context 'existing tenant' do
81
81
 
82
82
  it 'initializes and returns a connection pool' do
83
- expect(@handler.retrieve_connection_pool('foo')).to be_true
83
+ expect(@handler.retrieve_connection_pool('foo')).to be_truthy
84
84
  end
85
85
 
86
86
  it 'returns a connection pool' do
@@ -106,11 +106,11 @@ describe Motel::ConnectionAdapters::ConnectionHandler do
106
106
 
107
107
  it 'returns true' do
108
108
  @handler.retrieve_connection('foo')
109
- expect(@handler.connected?('foo')).to be_true
109
+ expect(@handler.connected?('foo')).to be_truthy
110
110
  end
111
111
 
112
112
  it 'returns false' do
113
- expect(@handler.connected?('foo')).to be_false
113
+ expect(@handler.connected?('foo')).to be_falsey
114
114
  end
115
115
 
116
116
  end
@@ -118,12 +118,12 @@ describe Motel::ConnectionAdapters::ConnectionHandler do
118
118
  describe '#active_connections?' do
119
119
 
120
120
  it 'has not active connections' do
121
- expect(@handler.active_connections?).to be_false
121
+ expect(@handler.active_connections?).to be_falsey
122
122
  end
123
123
 
124
124
  it 'has active connections' do
125
125
  @handler.retrieve_connection('foo')
126
- expect(@handler.active_connections?).to be_true
126
+ expect(@handler.active_connections?).to be_truthy
127
127
  end
128
128
 
129
129
  end
@@ -132,10 +132,10 @@ describe Motel::ConnectionAdapters::ConnectionHandler do
132
132
 
133
133
  it 'removes the connection' do
134
134
  @handler.retrieve_connection('foo')
135
- expect(@handler.active_connections?).to be_true
135
+ expect(@handler.active_connections?).to be_truthy
136
136
 
137
137
  @handler.remove_connection('foo')
138
- expect(@handler.active_connections?).to be_false
138
+ expect(@handler.active_connections?).to be_falsey
139
139
  end
140
140
 
141
141
  end
@@ -96,11 +96,11 @@ describe Motel::Manager do
96
96
  describe '#tenants' do
97
97
 
98
98
  it 'returns tenant foo' do
99
- expect(@manager.tenants.key?('foo')).to be_true
99
+ expect(@manager.tenants.key?('foo')).to be_truthy
100
100
  end
101
101
 
102
102
  it 'returns tenant bar' do
103
- expect(@manager.tenants.key?('bar')).to be_true
103
+ expect(@manager.tenants.key?('bar')).to be_truthy
104
104
  end
105
105
 
106
106
  end
@@ -117,7 +117,7 @@ describe Motel::Manager do
117
117
  describe '#tenant?' do
118
118
 
119
119
  it 'returns true if tenant foo does exist' do
120
- expect(@manager.tenant?('foo')).to be_true
120
+ expect(@manager.tenant?('foo')).to be_truthy
121
121
  end
122
122
 
123
123
  it 'returns true if tenant baz does exist' do
@@ -125,11 +125,11 @@ describe Motel::Manager do
125
125
  spec = resolver.spec(BAZ_SPEC)
126
126
  handler = ActiveRecord::Base.connection_handler
127
127
  handler.establish_connection('baz', spec)
128
- expect(@manager.tenant?('baz')).to be_true
128
+ expect(@manager.tenant?('baz')).to be_truthy
129
129
  end
130
130
 
131
131
  it 'returns false if tenant does not exist' do
132
- expect(@manager.tenant?('foobar')).to be_false
132
+ expect(@manager.tenant?('foobar')).to be_falsey
133
133
  end
134
134
 
135
135
  end
@@ -139,7 +139,7 @@ describe Motel::Manager do
139
139
  it 'adds new tenant' do
140
140
  @manager.add_tenant('baz', BAZ_SPEC)
141
141
 
142
- expect(@tenants_source.tenant?('baz')).to be_true
142
+ expect(@tenants_source.tenant?('baz')).to be_truthy
143
143
  end
144
144
 
145
145
  end
@@ -166,12 +166,12 @@ describe Motel::Manager do
166
166
  describe '#delete_tenant' do
167
167
 
168
168
  it 'returns true' do
169
- expect(@manager.delete_tenant('foo')).to be_true
169
+ expect(@manager.delete_tenant('foo')).to be_truthy
170
170
  end
171
171
 
172
172
  it 'deletes tenant' do
173
173
  @manager.delete_tenant('foo')
174
- expect(@tenants_source.tenant?('foo')).to be_false
174
+ expect(@tenants_source.tenant?('foo')).to be_falsey
175
175
  end
176
176
 
177
177
  it 'removes connection of tenant' do
@@ -22,10 +22,28 @@ describe ActiveRecord::Base do
22
22
 
23
23
  describe '.establish_connection' do
24
24
 
25
- it 'establishes a connection keyed by the class name' do
26
- ActiveRecord::Base.establish_connection(BAZ_SPEC)
25
+ context 'setting the current tenant name' do
26
+
27
+ before(:each) do
28
+ Motel::Manager.current_tenant = 'foo'
29
+ end
30
+
31
+ it 'establishes a connection keyed by tenant name' do
32
+ ActiveRecord::Base.establish_connection(FOO_SPEC)
33
+
34
+ expect(ActiveRecord::Base.connection_handler.active_tenants).to include('foo')
35
+ end
36
+
37
+ end
38
+
39
+ context 'without setting the current tenant name' do
40
+
41
+ it 'establishes a connection keyed by class name' do
42
+ ActiveRecord::Base.establish_connection(BAZ_SPEC)
43
+
44
+ expect(ActiveRecord::Base.connection_handler.active_tenants).to include('ActiveRecord::Base')
45
+ end
27
46
 
28
- expect(ActiveRecord::Base.connection_handler.active_tenants).to include('ActiveRecord::Base')
29
47
  end
30
48
 
31
49
  end
@@ -88,12 +106,12 @@ describe ActiveRecord::Base do
88
106
 
89
107
  it 'returns true' do
90
108
  Motel::Manager.current_tenant = 'foo'
91
- expect(ActiveRecord::Base.connected?).to be_true
109
+ expect(ActiveRecord::Base.connected?).to be_truthy
92
110
  end
93
111
 
94
112
  it 'returns false' do
95
113
  Motel::Manager.current_tenant = 'bar'
96
- expect(ActiveRecord::Base.connected?).to be_false
114
+ expect(ActiveRecord::Base.connected?).to be_falsey
97
115
  end
98
116
 
99
117
  end
@@ -72,7 +72,7 @@ describe Motel::Sources::Database do
72
72
  end
73
73
 
74
74
  it 'exist foo key' do
75
- expect(@tenants_source.tenants.key?('foo')).to be_true
75
+ expect(@tenants_source.tenants.key?('foo')).to be_truthy
76
76
  end
77
77
 
78
78
  it 'tenant foo has a correct spec' do
@@ -81,7 +81,7 @@ describe Motel::Sources::Database do
81
81
  end
82
82
 
83
83
  it 'exist bar key' do
84
- expect(@tenants_source.tenants.key?('bar')).to be_true
84
+ expect(@tenants_source.tenants.key?('bar')).to be_truthy
85
85
  end
86
86
 
87
87
  it 'tenant bar has a correct spec' do
@@ -115,11 +115,11 @@ describe Motel::Sources::Database do
115
115
  describe '#tenant?' do
116
116
 
117
117
  it 'returns true if tenant does exist' do
118
- expect(@tenants_source.tenant?('foo')).to be_true
118
+ expect(@tenants_source.tenant?('foo')).to be_truthy
119
119
  end
120
120
 
121
121
  it 'returns false if tenant does not exist' do
122
- expect(@tenants_source.tenant?('baz')).to be_false
122
+ expect(@tenants_source.tenant?('baz')).to be_falsey
123
123
  end
124
124
 
125
125
  end
@@ -11,7 +11,7 @@ describe Motel::Sources::Default do
11
11
  describe '#tenants' do
12
12
 
13
13
  it 'exist foo key' do
14
- expect(@tenants_source.tenants.key?('foo')).to be_true
14
+ expect(@tenants_source.tenants.key?('foo')).to be_truthy
15
15
  end
16
16
 
17
17
  it 'tenant foo has a correct spec' do
@@ -20,7 +20,7 @@ describe Motel::Sources::Default do
20
20
  end
21
21
 
22
22
  it 'exist bar key' do
23
- expect(@tenants_source.tenants.key?('bar')).to be_true
23
+ expect(@tenants_source.tenants.key?('bar')).to be_truthy
24
24
  end
25
25
 
26
26
  it 'tenant bar has a correct spec' do
@@ -54,11 +54,11 @@ describe Motel::Sources::Default do
54
54
  describe '#tenant?' do
55
55
 
56
56
  it 'returns true if tenant does exist' do
57
- expect(@tenants_source.tenant?('foo')).to be_true
57
+ expect(@tenants_source.tenant?('foo')).to be_truthy
58
58
  end
59
59
 
60
60
  it 'returns false if tenant does not exist' do
61
- expect(@tenants_source.tenant?('baz')).to be_false
61
+ expect(@tenants_source.tenant?('baz')).to be_falsey
62
62
  end
63
63
 
64
64
  end
@@ -84,7 +84,7 @@ describe Motel::Sources::Default do
84
84
  'baz', {'adapter' => BAZ_SPEC['adapter'], 'database' => BAZ_SPEC['database']}
85
85
  )
86
86
 
87
- expect(@tenants_source.tenants.key?('baz')).to be_true
87
+ expect(@tenants_source.tenants.key?('baz')).to be_truthy
88
88
  expect(@tenants_source.tenants['baz']['adapter']).to eq BAZ_SPEC['adapter']
89
89
  expect(@tenants_source.tenants['baz']['database']).to eq BAZ_SPEC['database']
90
90
  end
@@ -98,7 +98,7 @@ describe Motel::Sources::Default do
98
98
  'baz', {adapter: BAZ_SPEC['adapter'], database: BAZ_SPEC['database']}
99
99
  )
100
100
 
101
- expect(@tenants_source.tenants.key?('baz')).to be_true
101
+ expect(@tenants_source.tenants.key?('baz')).to be_truthy
102
102
  expect(@tenants_source.tenants['baz']['adapter']).to eq BAZ_SPEC['adapter']
103
103
  expect(@tenants_source.tenants['baz']['database']).to eq BAZ_SPEC['database']
104
104
  end
@@ -158,7 +158,7 @@ describe Motel::Sources::Default do
158
158
  it 'remove tenant from ActiveRecord::Base.configurations' do
159
159
  @tenants_source.delete_tenant('foo')
160
160
 
161
- expect(@tenants_source.tenants.key?('foo')).to be_false
161
+ expect(@tenants_source.tenants.key?('foo')).to be_falsey
162
162
  end
163
163
 
164
164
  end
@@ -33,7 +33,7 @@ describe Motel::Sources::Redis do
33
33
  end
34
34
 
35
35
  it 'exist foo key' do
36
- expect(@tenants_source.tenants.key?('foo')).to be_true
36
+ expect(@tenants_source.tenants.key?('foo')).to be_truthy
37
37
  end
38
38
 
39
39
  it 'tenant foo has a correct spec' do
@@ -42,7 +42,7 @@ describe Motel::Sources::Redis do
42
42
  end
43
43
 
44
44
  it 'exist bar key' do
45
- expect(@tenants_source.tenants.key?('bar')).to be_true
45
+ expect(@tenants_source.tenants.key?('bar')).to be_truthy
46
46
  end
47
47
 
48
48
  it 'tenant bar has a correct spec' do
@@ -76,11 +76,11 @@ describe Motel::Sources::Redis do
76
76
  describe '#tenant?' do
77
77
 
78
78
  it 'returns true if tenant does exist' do
79
- expect(@tenants_source.tenant?('foo')).to be_true
79
+ expect(@tenants_source.tenant?('foo')).to be_truthy
80
80
  end
81
81
 
82
82
  it 'returns false if tenant does not exist' do
83
- expect(@tenants_source.tenant?('baz')).to be_false
83
+ expect(@tenants_source.tenant?('baz')).to be_falsey
84
84
  end
85
85
 
86
86
  end
@@ -178,8 +178,8 @@ describe Motel::Sources::Redis do
178
178
  it 'remove tenant from redis server' do
179
179
  @tenants_source.delete_tenant('foo')
180
180
 
181
- expect(@redis_server.hexists("#{@prefix_tenant_alias}foo", 'adapter')).to be_false
182
- expect(@redis_server.hexists("#{@prefix_tenant_alias}foo", 'database')).to be_false
181
+ expect(@redis_server.hexists("#{@prefix_tenant_alias}foo", 'adapter')).to be_falsey
182
+ expect(@redis_server.hexists("#{@prefix_tenant_alias}foo", 'database')).to be_falsey
183
183
  end
184
184
 
185
185
  end
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,6 @@ BAR_SPEC = {'adapter' => 'sqlite3', 'database' => "#{TEMP_DIR}/bar.sqlite3"}
9
9
  BAZ_SPEC = {'adapter' => 'sqlite3', 'database' => "#{TEMP_DIR}/baz.sqlite3"}
10
10
 
11
11
  RSpec.configure do |config|
12
- config.color_enabled = true
12
+ config.color = true
13
13
  end
14
14
 
Binary file
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motel-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Martínez Valdelamar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-21 00:00:00.000000000 Z
11
+ date: 2014-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '4.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '4.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: redis
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 3.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 3.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.3.0
61
+ version: '3.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.3.0
68
+ version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.0'
83
83
  description: ActiveRecord extension to use connections to multiple databases
@@ -86,34 +86,34 @@ executables: []
86
86
  extensions: []
87
87
  extra_rdoc_files: []
88
88
  files:
89
+ - README.md
90
+ - VERSION
89
91
  - lib/motel-activerecord.rb
92
+ - lib/motel/connection_adapters.rb
93
+ - lib/motel/connection_adapters/connection_handler.rb
94
+ - lib/motel/connection_adapters/connection_specification.rb
95
+ - lib/motel/connection_adapters/connection_specification/resolver.rb
96
+ - lib/motel/errors.rb
97
+ - lib/motel/lobby.rb
90
98
  - lib/motel/manager.rb
91
- - lib/motel/sources.rb
99
+ - lib/motel/multi_tenant.rb
92
100
  - lib/motel/railtie.rb
101
+ - lib/motel/sources.rb
93
102
  - lib/motel/sources/database.rb
94
103
  - lib/motel/sources/default.rb
95
104
  - lib/motel/sources/redis.rb
96
- - lib/motel/errors.rb
97
105
  - lib/motel/version.rb
98
- - lib/motel/connection_adapters.rb
99
- - lib/motel/multi_tenant.rb
100
- - lib/motel/connection_adapters/connection_specification/resolver.rb
101
- - lib/motel/connection_adapters/connection_specification.rb
102
- - lib/motel/connection_adapters/connection_handler.rb
103
- - lib/motel/lobby.rb
104
- - VERSION
105
- - README.md
106
- - spec/tmp/foo.sqlite3
107
- - spec/tmp/tenants.sqlite3
108
- - spec/spec_helper.rb
109
- - spec/lib/motel/sources/default_spec.rb
110
- - spec/lib/motel/sources/database_spec.rb
111
- - spec/lib/motel/sources/redis_spec.rb
112
- - spec/lib/motel/connection_adapters/connection_specification/resolver_spec.rb
113
106
  - spec/lib/motel/connection_adapters/connection_handler_spec.rb
114
- - spec/lib/motel/multi_tenant_spec.rb
107
+ - spec/lib/motel/connection_adapters/connection_specification/resolver_spec.rb
115
108
  - spec/lib/motel/lobby_spec.rb
116
109
  - spec/lib/motel/manager_spec.rb
110
+ - spec/lib/motel/multi_tenant_spec.rb
111
+ - spec/lib/motel/sources/database_spec.rb
112
+ - spec/lib/motel/sources/default_spec.rb
113
+ - spec/lib/motel/sources/redis_spec.rb
114
+ - spec/spec_helper.rb
115
+ - spec/tmp/foo.sqlite3
116
+ - spec/tmp/tenants.sqlite3
117
117
  homepage: https://github.com/dimarval/motel-activerecord
118
118
  licenses:
119
119
  - MIT
@@ -124,17 +124,17 @@ require_paths:
124
124
  - lib
125
125
  required_ruby_version: !ruby/object:Gem::Requirement
126
126
  requirements:
127
- - - ~>
127
+ - - "~>"
128
128
  - !ruby/object:Gem::Version
129
129
  version: '2.0'
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  requirements:
132
- - - '>='
132
+ - - ">="
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.0.3
137
+ rubygems_version: 2.2.2
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: Multi-tenant gem
@@ -142,12 +142,11 @@ test_files:
142
142
  - spec/tmp/foo.sqlite3
143
143
  - spec/tmp/tenants.sqlite3
144
144
  - spec/spec_helper.rb
145
+ - spec/lib/motel/manager_spec.rb
146
+ - spec/lib/motel/connection_adapters/connection_specification/resolver_spec.rb
147
+ - spec/lib/motel/connection_adapters/connection_handler_spec.rb
145
148
  - spec/lib/motel/sources/default_spec.rb
146
149
  - spec/lib/motel/sources/database_spec.rb
147
150
  - spec/lib/motel/sources/redis_spec.rb
148
- - spec/lib/motel/connection_adapters/connection_specification/resolver_spec.rb
149
- - spec/lib/motel/connection_adapters/connection_handler_spec.rb
150
- - spec/lib/motel/multi_tenant_spec.rb
151
151
  - spec/lib/motel/lobby_spec.rb
152
- - spec/lib/motel/manager_spec.rb
153
- has_rdoc:
152
+ - spec/lib/motel/multi_tenant_spec.rb