|
94 | 94 |
|
95 | 95 | context "ActiveRecord connection_pool" do |
96 | 96 | before do |
97 | | - ActiveRecord::Base.connection_handler.clear_active_connections!(:all) |
| 97 | + clear_active_connections! |
98 | 98 | end |
99 | 99 |
|
100 | 100 | context "#features" do |
101 | 101 | it "does not hold onto connections" do |
102 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 102 | + expect(active_connections?).to be(false) |
103 | 103 | subject.features |
104 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 104 | + expect(active_connections?).to be(false) |
105 | 105 | end |
106 | 106 |
|
107 | 107 | it "does not release previously held connection" do |
108 | 108 | ActiveRecord::Base.connection # establish a new connection |
109 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 109 | + expect(active_connections?).to be(true) |
110 | 110 | subject.features |
111 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 111 | + expect(active_connections?).to be(true) |
112 | 112 | end |
113 | 113 | end |
114 | 114 |
|
115 | 115 | context "#get_all" do |
116 | 116 | it "does not hold onto connections" do |
117 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 117 | + expect(active_connections?).to be(false) |
118 | 118 | subject.get_all |
119 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 119 | + expect(active_connections?).to be(false) |
120 | 120 | end |
121 | 121 |
|
122 | 122 | it "does not release previously held connection" do |
123 | 123 | ActiveRecord::Base.connection # establish a new connection |
124 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 124 | + expect(active_connections?).to be(true) |
125 | 125 | subject.get_all |
126 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 126 | + expect(active_connections?).to be(true) |
127 | 127 | end |
128 | 128 | end |
129 | 129 |
|
130 | 130 | context "#add / #remove / #clear" do |
131 | 131 | let(:feature) { Flipper::Feature.new(:search, subject) } |
132 | 132 |
|
133 | 133 | it "does not hold onto connections" do |
134 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 134 | + expect(active_connections?).to be(false) |
135 | 135 | subject.add(feature) |
136 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 136 | + expect(active_connections?).to be(false) |
137 | 137 | subject.remove(feature) |
138 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 138 | + expect(active_connections?).to be(false) |
139 | 139 | subject.clear(feature) |
140 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 140 | + expect(active_connections?).to be(false) |
141 | 141 | end |
142 | 142 |
|
143 | 143 | it "does not release previously held connection" do |
144 | 144 | ActiveRecord::Base.connection # establish a new connection |
145 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 145 | + expect(active_connections?).to be(true) |
146 | 146 | subject.add(feature) |
147 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 147 | + expect(active_connections?).to be(true) |
148 | 148 | subject.remove(feature) |
149 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 149 | + expect(active_connections?).to be(true) |
150 | 150 | subject.clear(feature) |
151 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 151 | + expect(active_connections?).to be(true) |
152 | 152 | end |
153 | 153 | end |
154 | 154 |
|
155 | 155 | context "#get_multi" do |
156 | 156 | let(:feature) { Flipper::Feature.new(:search, subject) } |
157 | 157 |
|
158 | 158 | it "does not hold onto connections" do |
159 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 159 | + expect(active_connections?).to be(false) |
160 | 160 | subject.get_multi([feature]) |
161 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 161 | + expect(active_connections?).to be(false) |
162 | 162 | end |
163 | 163 |
|
164 | 164 | it "does not release previously held connection" do |
165 | 165 | ActiveRecord::Base.connection # establish a new connection |
166 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 166 | + expect(active_connections?).to be(true) |
167 | 167 | subject.get_multi([feature]) |
168 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 168 | + expect(active_connections?).to be(true) |
169 | 169 | end |
170 | 170 | end |
171 | 171 |
|
|
174 | 174 | let(:gate) { feature.gate(:boolean)} |
175 | 175 |
|
176 | 176 | it "does not hold onto connections" do |
177 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 177 | + expect(active_connections?).to be(false) |
178 | 178 | subject.enable(feature, gate, gate.wrap(true)) |
179 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 179 | + expect(active_connections?).to be(false) |
180 | 180 | subject.disable(feature, gate, gate.wrap(false)) |
181 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 181 | + expect(active_connections?).to be(false) |
182 | 182 | end |
183 | 183 |
|
184 | 184 | it "does not release previously held connection" do |
185 | 185 | ActiveRecord::Base.connection # establish a new connection |
186 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 186 | + expect(active_connections?).to be(true) |
187 | 187 | subject.enable(feature, gate, gate.wrap(true)) |
188 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 188 | + expect(active_connections?).to be(true) |
189 | 189 | subject.disable(feature, gate, gate.wrap(false)) |
190 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 190 | + expect(active_connections?).to be(true) |
191 | 191 | end |
192 | 192 | end |
193 | 193 |
|
|
196 | 196 | let(:gate) { feature.gate(:group) } |
197 | 197 |
|
198 | 198 | it "does not hold onto connections" do |
199 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 199 | + expect(active_connections?).to be(false) |
200 | 200 | subject.enable(feature, gate, gate.wrap(:admin)) |
201 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 201 | + expect(active_connections?).to be(false) |
202 | 202 | subject.disable(feature, gate, gate.wrap(:admin)) |
203 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 203 | + expect(active_connections?).to be(false) |
204 | 204 | end |
205 | 205 |
|
206 | 206 | it "does not release previously held connection" do |
207 | 207 | ActiveRecord::Base.connection # establish a new connection |
208 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 208 | + expect(active_connections?).to be(true) |
209 | 209 | subject.enable(feature, gate, gate.wrap(:admin)) |
210 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 210 | + expect(active_connections?).to be(true) |
211 | 211 | subject.disable(feature, gate, gate.wrap(:admin)) |
212 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(true) |
| 212 | + expect(active_connections?).to be(true) |
213 | 213 | end |
214 | 214 | end |
215 | 215 | end |
|
300 | 300 | end |
301 | 301 |
|
302 | 302 | it 'does not hold onto connections during write operations' do |
303 | | - ActiveRecord::Base.connection_handler.clear_active_connections!(:all) |
| 303 | + clear_active_connections! |
304 | 304 |
|
305 | 305 | abstract_class.connected_to(role: :reading) do |
306 | 306 | flipper = Flipper.new(adapter_with_roles) |
307 | 307 | feature = flipper[:connection_test] |
308 | 308 |
|
309 | 309 | feature.enable |
310 | | - expect(ActiveRecord::Base.connection_handler.active_connections?).to be(false) |
| 310 | + expect(active_connections?).to be(false) |
311 | 311 | end |
312 | 312 | end |
313 | 313 | end |
|
363 | 363 | end |
364 | 364 | end |
365 | 365 | end |
| 366 | + |
| 367 | + def active_connections? |
| 368 | + method = ActiveRecord::Base.connection_handler.method(:active_connections?) |
| 369 | + method.arity == 0 ? method.call : method.call(:all) |
| 370 | + end |
| 371 | + |
| 372 | + def clear_active_connections! |
| 373 | + method = ActiveRecord::Base.connection_handler.method(:clear_active_connections!) |
| 374 | + method.arity == 0 ? method.call : method.call(:all) |
| 375 | + end |
366 | 376 | end |
0 commit comments