|
33 | 33 |
|
34 | 34 | before do |
35 | 35 | allow(ENV).to receive(:fetch).and_call_original |
36 | | - allow(ENV).to receive(:fetch).with('MYSQL_CONNECTION_POOL_ENABLED', 'true') |
| 36 | + allow(ENV).to receive(:fetch).with('MYSQL_CONNECTION_POOL_ENABLED', 'false') |
37 | 37 | .and_return(connection_pooling_enabled) |
38 | 38 |
|
39 | 39 | subject.setup |
40 | 40 | end |
41 | 41 |
|
| 42 | + after do |
| 43 | + subject.dispose |
| 44 | + end |
| 45 | + |
42 | 46 | describe '#initialize' do |
43 | 47 | context 'when options are not provided' do |
44 | 48 | it 'returns the default options' do |
|
99 | 103 | describe '#dispose' do |
100 | 104 | context 'when connection pooling is enabled' do |
101 | 105 | it 'disposes of the pool and clears connector reference' do |
102 | | - pool = instance_double(MysqlFramework::MysqlConnectionPool) |
| 106 | + pool = instance_double(MysqlFramework::MysqlConnectionPool, dispose: true) |
103 | 107 | allow(pool).to receive(:dispose) |
104 | 108 | subject.instance_variable_set(:@connection_pool, pool) |
105 | 109 |
|
|
123 | 127 | describe '#check_out' do |
124 | 128 | context 'when connection pooling is enabled' do |
125 | 129 | it 'checks out pooled connection' do |
126 | | - pool = instance_double(MysqlFramework::MysqlConnectionPool) |
| 130 | + pool = instance_double(MysqlFramework::MysqlConnectionPool, dispose: true) |
127 | 131 | client = instance_double(Mysql2::Client) |
128 | 132 | allow(pool).to receive(:check_out).and_return(client) |
129 | 133 | subject.instance_variable_set(:@connection_pool, pool) |
|
148 | 152 | describe '#check_in' do |
149 | 153 | context 'when connection pooling is enabled' do |
150 | 154 | it 'checks in a pooled connection' do |
151 | | - pool = instance_double(MysqlFramework::MysqlConnectionPool) |
| 155 | + pool = instance_double(MysqlFramework::MysqlConnectionPool, dispose: true) |
152 | 156 | allow(pool).to receive(:check_in) |
153 | 157 | subject.instance_variable_set(:@connection_pool, pool) |
154 | 158 |
|
|
208 | 212 |
|
209 | 213 | context 'when connection pooling is enabled' do |
210 | 214 | it 'delegates to the connection pool' do |
211 | | - pool = instance_double(MysqlFramework::MysqlConnectionPool) |
| 215 | + pool = instance_double(MysqlFramework::MysqlConnectionPool, dispose: true) |
212 | 216 | subject.instance_variable_set(:@connection_pool, pool) |
213 | 217 |
|
214 | 218 | expect(pool).to receive(:with_client).with(discard_current_pool_connection: false).and_yield(client) |
215 | 219 | expect { |b| subject.with_client(&b) }.to yield_with_args(client) |
216 | 220 | end |
217 | 221 |
|
218 | 222 | it 'passes discard_current_pool_connection: true to the pool when requested' do |
219 | | - pool = instance_double(MysqlFramework::MysqlConnectionPool) |
| 223 | + pool = instance_double(MysqlFramework::MysqlConnectionPool, dispose: true) |
220 | 224 | subject.instance_variable_set(:@connection_pool, pool) |
221 | 225 |
|
222 | 226 | expect(pool).to receive(:with_client).with(discard_current_pool_connection: true).and_yield(client) |
223 | 227 | subject.with_client(discard_current_pool_connection: true) { |_c| nil } |
224 | 228 | end |
225 | 229 |
|
226 | 230 | it 'returns the block result' do |
227 | | - pool = instance_double(MysqlFramework::MysqlConnectionPool) |
| 231 | + pool = instance_double(MysqlFramework::MysqlConnectionPool, dispose: true) |
228 | 232 | subject.instance_variable_set(:@connection_pool, pool) |
229 | 233 | allow(pool).to receive(:with_client).and_yield(client) |
230 | 234 |
|
|
0 commit comments