File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
lib/active_record/connection_adapters
test/cases/connection_adapters Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -50,8 +50,10 @@ def reset
50
50
end
51
51
52
52
def delete ( key )
53
- dealloc cache [ key ]
54
- cache . delete ( key )
53
+ if stmt = cache . delete ( key )
54
+ dealloc ( stmt )
55
+ end
56
+ stmt
55
57
end
56
58
57
59
private
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "cases/helper"
4
+
5
+ module ActiveRecord
6
+ module ConnectionAdapters
7
+ class StatementPoolTest < ActiveRecord ::TestCase
8
+ class TestPool < StatementPool
9
+ private
10
+ def dealloc ( stmt )
11
+ raise ArgumentError unless stmt
12
+ end
13
+ end
14
+
15
+ setup do
16
+ @pool = TestPool . new
17
+ end
18
+
19
+ test "#delete doesn't call dealloc if the statement didn't exist" do
20
+ stmt = Object . new
21
+ sql = "SELECT 1"
22
+ @pool [ sql ] = stmt
23
+ assert_same stmt , @pool [ sql ]
24
+ assert_same stmt , @pool . delete ( sql )
25
+ assert_nil @pool . delete ( sql )
26
+ end
27
+ end
28
+ end
29
+ end
You can’t perform that action at this time.
0 commit comments