1
1
require 'spec_helper'
2
2
3
- # include patch under test
4
- require 'msf/core/patches/active_record'
5
3
# helps with environment configuration to use for connection to database
6
4
require 'metasploit/framework'
7
5
@@ -33,9 +31,9 @@ def database_configurations_pathname
33
31
ActiveRecord ::Base . clear_all_connections!
34
32
end
35
33
36
- context '#active_thread_connection ?' do
37
- subject ( :active_thread_connection ? ) do
38
- connection_pool . active_thread_connection ?
34
+ context '#active_connection ?' do
35
+ subject ( :active_connection ? ) do
36
+ connection_pool . active_connection ?
39
37
end
40
38
41
39
# Let! so that Thread is captured before creating and entering new Threads
@@ -47,50 +45,22 @@ def database_configurations_pathname
47
45
ActiveRecord ::Base . connection_pool . connection
48
46
end
49
47
50
- context 'with connection id' do
51
- subject ( :active_thread_connection? ) do
52
- connection_pool . active_thread_connection? ( connection_id )
53
- end
54
-
55
- context 'with connection id from other thread that has connection' do
56
- let ( :connection_id ) do
57
- main_thread . object_id
58
- end
59
-
60
- it 'should be true' do
61
- thread = Thread . new do
62
- Thread . current . should_not == main_thread
63
-
64
- expect ( active_thread_connection? ) . to be_true
65
- end
66
-
67
- thread . join
68
- end
69
- end
48
+ context 'in thread with connection' do
49
+ it { should be_true }
70
50
end
71
51
72
- context 'without connection id' do
73
- context 'in thread with connection' do
74
- it { should be_true }
75
- end
76
-
77
- context 'in thread without connection' do
78
- it 'should be false' do
79
- thread = Thread . new do
80
- Thread . current . should_not == main_thread
81
- expect ( active_thread_connection? ) . to be_false
82
- end
83
-
84
- thread . join
52
+ context 'in thread without connection' do
53
+ it 'should be false' do
54
+ thread = Thread . new do
55
+ Thread . current . should_not == main_thread
56
+ expect ( active_connection? ) . to be_false
85
57
end
58
+
59
+ thread . join
86
60
end
87
61
end
88
62
end
89
63
90
- context 'checkout' do
91
-
92
- end
93
-
94
64
context '#with_connection' do
95
65
def reserved_connection_count
96
66
connection_pool . instance_variable_get ( :@reserved_connections ) . length
@@ -110,19 +80,6 @@ def reserved_connection_count
110
80
connection_pool . with_connection { }
111
81
end
112
82
113
- it 'should call #active_thread_connection? with #current_connection_id' do
114
- current_connection_id = mock ( 'Connection ID' )
115
- connection_pool . stub ( :current_connection_id => current_connection_id )
116
-
117
- connection_pool . should_receive (
118
- :active_thread_connection?
119
- ) . with (
120
- current_connection_id
121
- ) . and_call_original
122
-
123
- connection_pool . with_connection { }
124
- end
125
-
126
83
it 'should yield #connection' do
127
84
connection = mock ( 'Connection' )
128
85
connection_pool . stub ( :connection => connection )
@@ -141,8 +98,8 @@ def reserved_connection_count
141
98
connection_pool . checkin connection
142
99
end
143
100
144
- it 'should return true from #active_thread_connection ?' do
145
- expect ( connection_pool . active_thread_connection ?) . to be_true
101
+ it 'should return true from #active_connection ?' do
102
+ expect ( connection_pool . active_connection ?) . to be_true
146
103
end
147
104
148
105
context 'with error' do
@@ -173,8 +130,8 @@ def reserved_connection_count
173
130
end
174
131
175
132
context 'without active thread connection' do
176
- it 'should return false from #active_thread_connection ?' do
177
- expect ( connection_pool . active_thread_connection ?) . to be_false
133
+ it 'should return false from #active_connection ?' do
134
+ expect ( connection_pool . active_connection ?) . to be_false
178
135
end
179
136
180
137
context 'with error' do
0 commit comments