mysql_framework 0.1.2.rc1 → 0.1.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
  SHA256:
3
- metadata.gz: f327b700f17750938d41a83a10dbb3870339cc053ac9f85b8b190fcaa952ecd3
4
- data.tar.gz: 6ee8a9ce9d1b286330cbf269bbe117c0c098690b086536e199f7da9eb93d01da
3
+ metadata.gz: b6968df02ffdf51ca8bfd97439bd9dec1ba2c958daac8875e0b5d6bb49f1ae46
4
+ data.tar.gz: 95f5f9ab5f79185f714a673ea8117b31f2daa5eddefe33ca0c5a7eaf170efa35
5
5
  SHA512:
6
- metadata.gz: eaf60ca0754e7df7259fa3c4ef99b75925c803a587d9ed02c628a1bbfdfb73afff9dd818223de93a0ce077bbbf20419aaaf452fd04742573af458ca8d5d30820
7
- data.tar.gz: d30a6dfbaeb8c943339db350bfa629680974963343682b54baadc4d956bd6ab0ef16387beb5c0e257c7a6cecfd90c5849029e842f3c5cb114c9b992d612f1085
6
+ metadata.gz: 447e5df159a57b64c82dcdb174501f2263cb04df75adcc9d55a45af027f6fb0504c67a17a7b99d5c2c9f049bfec4906a7c1fe28b93bde5325abaaab3cf381dce
7
+ data.tar.gz: 8793497128e20a8966c3ac4906ee7ae3d1d8db08895b62523e2696e410d360c534d6cc4442c0d875cb48c3ddecf95a8140322fbba2b646382d0c6b3707e8e186
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MysqlFramework
4
- VERSION = '0.1.2.rc1'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -28,10 +28,24 @@ describe MysqlFramework::Connector do
28
28
  let(:client) { double(close: true, ping: true, closed?: false) }
29
29
  let(:gems) { MysqlFramework::SqlTable.new('gems') }
30
30
  let(:existing_client) { Mysql2::Client.new(default_options) }
31
+ let(:connection_pooling_enabled) { 'true' }
31
32
 
32
33
  subject { described_class.new }
33
34
 
34
- before(:each) { subject.setup }
35
+ before(:each) do
36
+ original_fetch = ENV.method(:fetch)
37
+
38
+ allow(ENV).to receive(:fetch) do |var, default|
39
+ if var == 'MYSQL_CONNECTION_POOL_ENABLED'
40
+ connection_pooling_enabled
41
+ else
42
+ original_fetch.call(var, default)
43
+ end
44
+ end
45
+
46
+ subject.setup
47
+ end
48
+
35
49
  after(:each) { subject.dispose }
36
50
 
37
51
  describe '#initialize' do
@@ -69,10 +83,22 @@ describe MysqlFramework::Connector do
69
83
  end
70
84
 
71
85
  describe '#setup' do
72
- it 'creates a connection pool with the specified number of conections' do
73
- subject.setup
86
+ context 'when connection pooling is enabled' do
87
+ it 'creates a connection pool with the specified number of conections' do
88
+ subject.setup
89
+
90
+ expect(subject.connections.length).to eq(start_pool_size)
91
+ end
92
+ end
93
+
94
+ context 'when connection pooling is disabled' do
95
+ let(:connection_pooling_enabled) { 'false' }
74
96
 
75
- expect(subject.connections.length).to eq(start_pool_size)
97
+ it "doesn't create a connection pool" do
98
+ subject.setup
99
+
100
+ expect(subject.connections).to be_nil
101
+ end
76
102
  end
77
103
  end
78
104
 
@@ -92,42 +118,55 @@ describe MysqlFramework::Connector do
92
118
  end
93
119
 
94
120
  describe '#check_out' do
95
- context 'when there are available connections' do
96
- before do
97
- subject.connections.clear
98
- subject.connections.push(client)
99
- end
121
+ context 'when connection pooling is enabled' do
122
+ context 'when there are available connections' do
123
+ before do
124
+ subject.connections.clear
125
+ subject.connections.push(client)
126
+ end
100
127
 
101
- it 'returns a client instance from the pool' do
102
- expect(subject.check_out).to eq(client)
103
- end
128
+ it 'returns a client instance from the pool' do
129
+ expect(subject.check_out).to eq(client)
130
+ end
104
131
 
105
- context 'and :reconnect is set to true' do
106
- let(:options) do
107
- {
108
- host: ENV.fetch('MYSQL_HOST'),
109
- port: ENV.fetch('MYSQL_PORT'),
110
- database: "#{ENV.fetch('MYSQL_DATABASE')}_2",
111
- username: ENV.fetch('MYSQL_USERNAME'),
112
- password: ENV.fetch('MYSQL_PASSWORD'),
113
- reconnect: true
114
- }
132
+ context 'and :reconnect is set to true' do
133
+ let(:options) do
134
+ {
135
+ host: ENV.fetch('MYSQL_HOST'),
136
+ port: ENV.fetch('MYSQL_PORT'),
137
+ database: "#{ENV.fetch('MYSQL_DATABASE')}_2",
138
+ username: ENV.fetch('MYSQL_USERNAME'),
139
+ password: ENV.fetch('MYSQL_PASSWORD'),
140
+ reconnect: true
141
+ }
142
+ end
143
+
144
+ subject { described_class.new(options) }
145
+
146
+ it 'pings the server to force a reconnect' do
147
+ expect(client).to receive(:ping)
148
+
149
+ subject.check_out
150
+ end
115
151
  end
116
152
 
117
- subject { described_class.new(options) }
153
+ context 'and :reconnect is set to false' do
154
+ subject { described_class.new(options) }
118
155
 
119
- it 'pings the server to force a reconnect' do
120
- expect(client).to receive(:ping)
156
+ it 'pings the server to force a reconnect' do
157
+ expect(client).not_to receive(:ping)
121
158
 
122
- subject.check_out
159
+ subject.check_out
160
+ end
123
161
  end
124
162
  end
125
163
 
126
- context 'and :reconnect is set to false' do
127
- subject { described_class.new(options) }
164
+ context 'when connection pooling is disabled' do
165
+ let(:connection_pooling_enabled) { 'false' }
128
166
 
129
- it 'pings the server to force a reconnect' do
130
- expect(client).not_to receive(:ping)
167
+ it 'instantiates and returns a new connection directly' do
168
+ expect(subject.connections).not_to receive(:pop)
169
+ expect(Mysql2::Client).to receive(:new)
131
170
 
132
171
  subject.check_out
133
172
  end
@@ -164,20 +203,33 @@ describe MysqlFramework::Connector do
164
203
  end
165
204
 
166
205
  describe '#check_in' do
167
- it 'returns the provided client to the connection pool' do
168
- expect(subject.connections).to receive(:push).with(client)
206
+ context 'when connection pooling is enabled' do
207
+ it 'returns the provided client to the connection pool' do
208
+ expect(subject.connections).to receive(:push).with(client)
209
+
210
+ subject.check_in(client)
211
+ end
169
212
 
170
- subject.check_in(client)
213
+ context 'when the connection has been closed by the server' do
214
+ let(:closed_client) { double(close: true, closed?: true) }
215
+
216
+ it 'instantiates a new connection and returns it' do
217
+ expect(Mysql2::Client).to receive(:new).with(default_options).and_return(client)
218
+ expect(subject.connections).to receive(:push).with(client)
219
+
220
+ subject.check_in(closed_client)
221
+ end
222
+ end
171
223
  end
172
224
 
173
- context 'when the connection has been closed by the server' do
174
- let(:closed_client) { double(close: true, closed?: true) }
225
+ context 'when connection pooling is disabled' do
226
+ let(:connection_pooling_enabled) { 'false' }
175
227
 
176
- it 'instantiates a new connection and returns it' do
177
- expect(Mysql2::Client).to receive(:new).with(default_options).and_return(client)
178
- expect(subject.connections).to receive(:push).with(client)
228
+ it 'closes the connection and does not add it to the connection pool' do
229
+ expect(client).to receive(:close)
230
+ expect(subject.connections).not_to receive(:push)
179
231
 
180
- subject.check_in(closed_client)
232
+ subject.check_in(client)
181
233
  end
182
234
  end
183
235
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysql_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.rc1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sage
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-30 00:00:00.000000000 Z
11
+ date: 2018-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -148,9 +148,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  requirements:
151
- - - ">"
151
+ - - ">="
152
152
  - !ruby/object:Gem::Version
153
- version: 1.3.1
153
+ version: '0'
154
154
  requirements: []
155
155
  rubyforge_project:
156
156
  rubygems_version: 2.7.8