punchblock 1.6.1 → 1.7.0
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.
- data/CHANGELOG.md +8 -0
- data/Guardfile +1 -1
- data/Rakefile +1 -1
- data/lib/punchblock/client.rb +5 -8
- data/lib/punchblock/client/component_registry.rb +8 -1
- data/lib/punchblock/component/component_node.rb +1 -0
- data/lib/punchblock/component/output.rb +15 -1
- data/lib/punchblock/translator/asterisk.rb +1 -1
- data/lib/punchblock/translator/asterisk/call.rb +1 -1
- data/lib/punchblock/translator/asterisk/component/output.rb +5 -1
- data/lib/punchblock/translator/freeswitch.rb +7 -1
- data/lib/punchblock/translator/freeswitch/call.rb +10 -6
- data/lib/punchblock/translator/freeswitch/component.rb +1 -1
- data/lib/punchblock/version.rb +1 -1
- data/punchblock.gemspec +1 -2
- data/spec/punchblock/client/component_registry_spec.rb +7 -0
- data/spec/punchblock/client_spec.rb +14 -12
- data/spec/punchblock/command_node_spec.rb +2 -2
- data/spec/punchblock/component/component_node_spec.rb +10 -3
- data/spec/punchblock/component/input_spec.rb +1 -1
- data/spec/punchblock/component/output_spec.rb +32 -27
- data/spec/punchblock/component/record_spec.rb +5 -5
- data/spec/punchblock/connection/asterisk_spec.rb +7 -7
- data/spec/punchblock/connection/freeswitch_spec.rb +8 -8
- data/spec/punchblock/connection/xmpp_spec.rb +9 -9
- data/spec/punchblock/translator/asterisk/call_spec.rb +65 -65
- data/spec/punchblock/translator/asterisk/component/asterisk/agi_command_spec.rb +17 -20
- data/spec/punchblock/translator/asterisk/component/asterisk/ami_action_spec.rb +13 -16
- data/spec/punchblock/translator/asterisk/component/input_spec.rb +9 -12
- data/spec/punchblock/translator/asterisk/component/output_spec.rb +62 -29
- data/spec/punchblock/translator/asterisk/component/record_spec.rb +38 -42
- data/spec/punchblock/translator/asterisk/component/stop_by_redirect_spec.rb +2 -2
- data/spec/punchblock/translator/asterisk/component_spec.rb +5 -5
- data/spec/punchblock/translator/asterisk_spec.rb +55 -55
- data/spec/punchblock/translator/freeswitch/call_spec.rb +80 -54
- data/spec/punchblock/translator/freeswitch/component/flite_output_spec.rb +7 -10
- data/spec/punchblock/translator/freeswitch/component/input_spec.rb +8 -10
- data/spec/punchblock/translator/freeswitch/component/output_spec.rb +9 -12
- data/spec/punchblock/translator/freeswitch/component/record_spec.rb +31 -34
- data/spec/punchblock/translator/freeswitch/component/tts_output_spec.rb +7 -10
- data/spec/punchblock/translator/freeswitch/component_spec.rb +6 -6
- data/spec/punchblock/translator/freeswitch_spec.rb +27 -27
- data/spec/punchblock_spec.rb +5 -6
- data/spec/spec_helper.rb +2 -3
- data/spec/support/mock_connection_with_event_handler.rb +8 -19
- metadata +5 -21
|
@@ -7,11 +7,8 @@ module Punchblock
|
|
|
7
7
|
class Asterisk
|
|
8
8
|
module Component
|
|
9
9
|
describe Record do
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
original_command.add_event event
|
|
13
|
-
end
|
|
14
|
-
end
|
|
10
|
+
include HasMockCallbackConnection
|
|
11
|
+
|
|
15
12
|
let(:media_engine) { nil }
|
|
16
13
|
let(:channel) { 'SIP/foo' }
|
|
17
14
|
let(:translator) { Punchblock::Translator::Asterisk.new mock('AMI'), connection, media_engine }
|
|
@@ -34,16 +31,16 @@ module Punchblock
|
|
|
34
31
|
before { original_command.request! }
|
|
35
32
|
|
|
36
33
|
it "returns an error if the call is not answered yet" do
|
|
37
|
-
mock_call.
|
|
34
|
+
mock_call.should_receive(:answered?).and_return(false)
|
|
38
35
|
subject.execute
|
|
39
36
|
error = ProtocolError.new.setup 'option error', 'Record cannot be used on a call that is not answered.'
|
|
40
37
|
original_command.response(0.1).should be == error
|
|
41
38
|
end
|
|
42
39
|
|
|
43
|
-
before { mock_call.
|
|
40
|
+
before { mock_call.stub(:answered?).and_return(true) }
|
|
44
41
|
|
|
45
42
|
it "sets command response to a reference to the component" do
|
|
46
|
-
mock_call.
|
|
43
|
+
mock_call.should_receive(:send_ami_action!)
|
|
47
44
|
subject.execute
|
|
48
45
|
original_command.response(0.1).should be_a Ref
|
|
49
46
|
original_command.component_id.should be == subject.id
|
|
@@ -51,13 +48,13 @@ module Punchblock
|
|
|
51
48
|
|
|
52
49
|
it "starts a recording via AMI, using the component ID as the filename" do
|
|
53
50
|
filename = "#{Record::RECORDING_BASE_PATH}/#{subject.id}"
|
|
54
|
-
mock_call.
|
|
51
|
+
mock_call.should_receive(:send_ami_action!).once.with('Monitor', 'Channel' => channel, 'File' => filename, 'Format' => 'wav', 'Mix' => true)
|
|
55
52
|
subject.execute
|
|
56
53
|
end
|
|
57
54
|
|
|
58
55
|
it "sends a success complete event when the recording ends" do
|
|
59
56
|
full_filename = "file://#{Record::RECORDING_BASE_PATH}/#{subject.id}.wav"
|
|
60
|
-
mock_call.
|
|
57
|
+
mock_call.should_receive(:send_ami_action!)
|
|
61
58
|
subject.execute
|
|
62
59
|
monitor_stop_event = RubyAMI::Event.new('MonitorStop').tap do |e|
|
|
63
60
|
e['Channel'] = channel
|
|
@@ -72,7 +69,7 @@ module Punchblock
|
|
|
72
69
|
context "set to nil" do
|
|
73
70
|
let(:command_options) { { :start_paused => nil } }
|
|
74
71
|
it "should execute normally" do
|
|
75
|
-
mock_call.
|
|
72
|
+
mock_call.should_receive(:send_ami_action!).once
|
|
76
73
|
subject.execute
|
|
77
74
|
original_command.response(0.1).should be_a Ref
|
|
78
75
|
end
|
|
@@ -81,7 +78,7 @@ module Punchblock
|
|
|
81
78
|
context "set to false" do
|
|
82
79
|
let(:command_options) { { :start_paused => false } }
|
|
83
80
|
it "should execute normally" do
|
|
84
|
-
mock_call.
|
|
81
|
+
mock_call.should_receive(:send_ami_action!).once
|
|
85
82
|
subject.execute
|
|
86
83
|
original_command.response(0.1).should be_a Ref
|
|
87
84
|
end
|
|
@@ -90,7 +87,7 @@ module Punchblock
|
|
|
90
87
|
context "set to true" do
|
|
91
88
|
let(:command_options) { { :start_paused => true } }
|
|
92
89
|
it "should return an error and not execute any actions" do
|
|
93
|
-
mock_call.
|
|
90
|
+
mock_call.should_receive(:send_agi_action!).never
|
|
94
91
|
subject.execute
|
|
95
92
|
error = ProtocolError.new.setup 'option error', 'A start-paused value of true is unsupported.'
|
|
96
93
|
original_command.response(0.1).should be == error
|
|
@@ -102,7 +99,7 @@ module Punchblock
|
|
|
102
99
|
context "set to nil" do
|
|
103
100
|
let(:command_options) { { :initial_timeout => nil } }
|
|
104
101
|
it "should execute normally" do
|
|
105
|
-
mock_call.
|
|
102
|
+
mock_call.should_receive(:send_ami_action!).once
|
|
106
103
|
subject.execute
|
|
107
104
|
original_command.response(0.1).should be_a Ref
|
|
108
105
|
end
|
|
@@ -111,7 +108,7 @@ module Punchblock
|
|
|
111
108
|
context "set to -1" do
|
|
112
109
|
let(:command_options) { { :initial_timeout => -1 } }
|
|
113
110
|
it "should execute normally" do
|
|
114
|
-
mock_call.
|
|
111
|
+
mock_call.should_receive(:send_ami_action!).once
|
|
115
112
|
subject.execute
|
|
116
113
|
original_command.response(0.1).should be_a Ref
|
|
117
114
|
end
|
|
@@ -120,7 +117,7 @@ module Punchblock
|
|
|
120
117
|
context "set to a positive number" do
|
|
121
118
|
let(:command_options) { { :initial_timeout => 10 } }
|
|
122
119
|
it "should return an error and not execute any actions" do
|
|
123
|
-
mock_call.
|
|
120
|
+
mock_call.should_receive(:send_agi_action!).never
|
|
124
121
|
subject.execute
|
|
125
122
|
error = ProtocolError.new.setup 'option error', 'An initial-timeout value is unsupported.'
|
|
126
123
|
original_command.response(0.1).should be == error
|
|
@@ -132,7 +129,7 @@ module Punchblock
|
|
|
132
129
|
context "set to nil" do
|
|
133
130
|
let(:command_options) { { :final_timeout => nil } }
|
|
134
131
|
it "should execute normally" do
|
|
135
|
-
mock_call.
|
|
132
|
+
mock_call.should_receive(:send_ami_action!).once
|
|
136
133
|
subject.execute
|
|
137
134
|
original_command.response(0.1).should be_a Ref
|
|
138
135
|
end
|
|
@@ -141,7 +138,7 @@ module Punchblock
|
|
|
141
138
|
context "set to -1" do
|
|
142
139
|
let(:command_options) { { :final_timeout => -1 } }
|
|
143
140
|
it "should execute normally" do
|
|
144
|
-
mock_call.
|
|
141
|
+
mock_call.should_receive(:send_ami_action!).once
|
|
145
142
|
subject.execute
|
|
146
143
|
original_command.response(0.1).should be_a Ref
|
|
147
144
|
end
|
|
@@ -150,7 +147,7 @@ module Punchblock
|
|
|
150
147
|
context "set to a positive number" do
|
|
151
148
|
let(:command_options) { { :final_timeout => 10 } }
|
|
152
149
|
it "should return an error and not execute any actions" do
|
|
153
|
-
mock_call.
|
|
150
|
+
mock_call.should_receive(:send_agi_action!).never
|
|
154
151
|
subject.execute
|
|
155
152
|
error = ProtocolError.new.setup 'option error', 'A final-timeout value is unsupported.'
|
|
156
153
|
original_command.response(0.1).should be == error
|
|
@@ -162,13 +159,13 @@ module Punchblock
|
|
|
162
159
|
context "set to nil" do
|
|
163
160
|
let(:command_options) { { :format => nil } }
|
|
164
161
|
it "should execute as 'wav'" do
|
|
165
|
-
mock_call.
|
|
162
|
+
mock_call.should_receive(:send_ami_action!).once.with('Monitor', hash_including('Format' => 'wav'))
|
|
166
163
|
subject.execute
|
|
167
164
|
original_command.response(0.1).should be_a Ref
|
|
168
165
|
end
|
|
169
166
|
|
|
170
167
|
it "provides the correct filename in the recording" do
|
|
171
|
-
mock_call.
|
|
168
|
+
mock_call.should_receive(:send_ami_action!)
|
|
172
169
|
subject.execute
|
|
173
170
|
monitor_stop_event = RubyAMI::Event.new('MonitorStop').tap do |e|
|
|
174
171
|
e['Channel'] = channel
|
|
@@ -181,13 +178,13 @@ module Punchblock
|
|
|
181
178
|
context "set to 'mp3'" do
|
|
182
179
|
let(:command_options) { { :format => 'mp3' } }
|
|
183
180
|
it "should execute as 'mp3'" do
|
|
184
|
-
mock_call.
|
|
181
|
+
mock_call.should_receive(:send_ami_action!).once.with('Monitor', hash_including('Format' => 'mp3'))
|
|
185
182
|
subject.execute
|
|
186
183
|
original_command.response(0.1).should be_a Ref
|
|
187
184
|
end
|
|
188
185
|
|
|
189
186
|
it "provides the correct filename in the recording" do
|
|
190
|
-
mock_call.
|
|
187
|
+
mock_call.should_receive(:send_ami_action!)
|
|
191
188
|
subject.execute
|
|
192
189
|
monitor_stop_event = RubyAMI::Event.new('MonitorStop').tap do |e|
|
|
193
190
|
e['Channel'] = channel
|
|
@@ -202,8 +199,8 @@ module Punchblock
|
|
|
202
199
|
context "set to nil" do
|
|
203
200
|
let(:command_options) { { :start_beep => nil } }
|
|
204
201
|
it "should execute normally" do
|
|
205
|
-
mock_call.
|
|
206
|
-
mock_call.
|
|
202
|
+
mock_call.should_receive(:send_agi_action!).never.with('STREAM FILE', 'beep', '""')
|
|
203
|
+
mock_call.should_receive(:send_ami_action!).once
|
|
207
204
|
subject.execute
|
|
208
205
|
original_command.response(0.1).should be_a Ref
|
|
209
206
|
end
|
|
@@ -212,8 +209,8 @@ module Punchblock
|
|
|
212
209
|
context "set to false" do
|
|
213
210
|
let(:command_options) { { :start_beep => false } }
|
|
214
211
|
it "should execute normally" do
|
|
215
|
-
mock_call.
|
|
216
|
-
mock_call.
|
|
212
|
+
mock_call.should_receive(:send_agi_action!).never.with('STREAM FILE', 'beep', '""')
|
|
213
|
+
mock_call.should_receive(:send_ami_action!).once
|
|
217
214
|
subject.execute
|
|
218
215
|
original_command.response(0.1).should be_a Ref
|
|
219
216
|
end
|
|
@@ -223,10 +220,9 @@ module Punchblock
|
|
|
223
220
|
let(:command_options) { { :start_beep => true } }
|
|
224
221
|
|
|
225
222
|
it "should play a beep before recording" do
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
mock_call.
|
|
229
|
-
mock_call.expects(:send_ami_action!).once.in_sequence(execute_seq)
|
|
223
|
+
subject.wrapped_object.should_receive(:wait).once
|
|
224
|
+
mock_call.should_receive(:send_agi_action!).once.with('STREAM FILE', 'beep', '""').ordered
|
|
225
|
+
mock_call.should_receive(:send_ami_action!).once.ordered
|
|
230
226
|
subject.execute
|
|
231
227
|
original_command.response(0.1).should be_a Ref
|
|
232
228
|
end
|
|
@@ -235,7 +231,7 @@ module Punchblock
|
|
|
235
231
|
def mock_call.send_agi_action!(*args)
|
|
236
232
|
yield
|
|
237
233
|
end
|
|
238
|
-
mock_call.
|
|
234
|
+
mock_call.should_receive(:send_ami_action!).once
|
|
239
235
|
subject.execute
|
|
240
236
|
original_command.response(0.1).should be_a Ref
|
|
241
237
|
end
|
|
@@ -246,7 +242,7 @@ module Punchblock
|
|
|
246
242
|
context "set to nil" do
|
|
247
243
|
let(:command_options) { { :max_duration => nil } }
|
|
248
244
|
it "should execute normally" do
|
|
249
|
-
mock_call.
|
|
245
|
+
mock_call.should_receive(:send_ami_action!).once
|
|
250
246
|
subject.execute
|
|
251
247
|
original_command.response(0.1).should be_a Ref
|
|
252
248
|
end
|
|
@@ -255,7 +251,7 @@ module Punchblock
|
|
|
255
251
|
context "set to -1" do
|
|
256
252
|
let(:command_options) { { :max_duration => -1 } }
|
|
257
253
|
it "should execute normally" do
|
|
258
|
-
mock_call.
|
|
254
|
+
mock_call.should_receive(:send_ami_action!).once
|
|
259
255
|
subject.execute
|
|
260
256
|
original_command.response(0.1).should be_a Ref
|
|
261
257
|
end
|
|
@@ -277,8 +273,8 @@ module Punchblock
|
|
|
277
273
|
let(:command_options) { { :max_duration => 1000 } }
|
|
278
274
|
|
|
279
275
|
it "executes a StopMonitor action" do
|
|
280
|
-
mock_call.
|
|
281
|
-
mock_call.
|
|
276
|
+
mock_call.should_receive :send_ami_action!
|
|
277
|
+
mock_call.should_receive(:send_ami_action!).once.with('StopMonitor', 'Channel' => channel)
|
|
282
278
|
subject.execute
|
|
283
279
|
sleep 1.2
|
|
284
280
|
end
|
|
@@ -322,8 +318,8 @@ module Punchblock
|
|
|
322
318
|
let(:command) { Punchblock::Component::Stop.new }
|
|
323
319
|
|
|
324
320
|
before do
|
|
325
|
-
mock_call.
|
|
326
|
-
mock_call.
|
|
321
|
+
mock_call.should_receive :send_ami_action!
|
|
322
|
+
mock_call.should_receive(:answered?).and_return(true)
|
|
327
323
|
command.request!
|
|
328
324
|
original_command.request!
|
|
329
325
|
subject.execute
|
|
@@ -337,14 +333,14 @@ module Punchblock
|
|
|
337
333
|
end
|
|
338
334
|
|
|
339
335
|
it "sets the command response to true" do
|
|
340
|
-
mock_call.
|
|
336
|
+
mock_call.should_receive :send_ami_action!
|
|
341
337
|
subject.execute_command command
|
|
342
338
|
send_stop_event
|
|
343
339
|
command.response(0.1).should be == true
|
|
344
340
|
end
|
|
345
341
|
|
|
346
342
|
it "executes a StopMonitor action" do
|
|
347
|
-
mock_call.
|
|
343
|
+
mock_call.should_receive(:send_ami_action!).once.with('StopMonitor', 'Channel' => channel)
|
|
348
344
|
subject.execute_command command
|
|
349
345
|
end
|
|
350
346
|
|
|
@@ -386,7 +382,7 @@ module Punchblock
|
|
|
386
382
|
end
|
|
387
383
|
|
|
388
384
|
it "pauses the recording via AMI" do
|
|
389
|
-
mock_call.
|
|
385
|
+
mock_call.should_receive(:send_ami_action!).once.with('PauseMonitor', 'Channel' => channel)
|
|
390
386
|
subject.execute_command command
|
|
391
387
|
end
|
|
392
388
|
end
|
|
@@ -409,7 +405,7 @@ module Punchblock
|
|
|
409
405
|
end
|
|
410
406
|
|
|
411
407
|
it "resumes the recording via AMI" do
|
|
412
|
-
mock_call.
|
|
408
|
+
mock_call.should_receive(:send_ami_action!).once.with('ResumeMonitor', 'Channel' => channel)
|
|
413
409
|
subject.execute_command command
|
|
414
410
|
end
|
|
415
411
|
end
|
|
@@ -37,8 +37,8 @@ module Punchblock
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
it "sets the command response to true" do
|
|
40
|
-
mock_call.
|
|
41
|
-
mock_call.
|
|
40
|
+
mock_call.should_receive(:redirect_back!)
|
|
41
|
+
mock_call.should_receive(:register_handler).with do |type, *guards|
|
|
42
42
|
type.should be == :ami
|
|
43
43
|
guards.should have(2).guards
|
|
44
44
|
guards[0].should be_a Proc
|
|
@@ -35,7 +35,7 @@ module Punchblock
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it "should send the event to the connection" do
|
|
38
|
-
connection.
|
|
38
|
+
connection.should_receive(:handle_event).once.with expected_event
|
|
39
39
|
subject.send_event event
|
|
40
40
|
end
|
|
41
41
|
|
|
@@ -43,7 +43,7 @@ module Punchblock
|
|
|
43
43
|
before { subject.internal = true }
|
|
44
44
|
|
|
45
45
|
it "should add the event to the command" do
|
|
46
|
-
command.
|
|
46
|
+
command.should_receive(:add_event).once.with expected_event
|
|
47
47
|
subject.send_event event
|
|
48
48
|
end
|
|
49
49
|
end
|
|
@@ -60,12 +60,12 @@ module Punchblock
|
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
it "should send a complete event with the specified reason" do
|
|
63
|
-
subject.wrapped_object.
|
|
63
|
+
subject.wrapped_object.should_receive(:send_event).once.with expected_event
|
|
64
64
|
subject.send_complete_event reason
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
it "should cause the actor to be shut down" do
|
|
68
|
-
subject.wrapped_object.
|
|
68
|
+
subject.wrapped_object.stub(:send_event).and_return true
|
|
69
69
|
subject.send_complete_event reason
|
|
70
70
|
sleep 0.2
|
|
71
71
|
subject.should_not be_alive
|
|
@@ -74,7 +74,7 @@ module Punchblock
|
|
|
74
74
|
|
|
75
75
|
describe "#call_ended" do
|
|
76
76
|
it "should send a complete event with the call hangup reason" do
|
|
77
|
-
subject.wrapped_object.
|
|
77
|
+
subject.wrapped_object.should_receive(:send_complete_event).once.with Punchblock::Event::Complete::Hangup.new
|
|
78
78
|
subject.call_ended
|
|
79
79
|
end
|
|
80
80
|
end
|
|
@@ -32,7 +32,7 @@ module Punchblock
|
|
|
32
32
|
describe '#shutdown' do
|
|
33
33
|
it "instructs all calls to shutdown" do
|
|
34
34
|
call = Asterisk::Call.new 'foo', subject
|
|
35
|
-
call.
|
|
35
|
+
call.should_receive(:shutdown!).once
|
|
36
36
|
subject.register_call call
|
|
37
37
|
subject.shutdown
|
|
38
38
|
end
|
|
@@ -50,7 +50,7 @@ module Punchblock
|
|
|
50
50
|
let(:call_id) { 'abc123' }
|
|
51
51
|
|
|
52
52
|
it 'executes the call command' do
|
|
53
|
-
subject.wrapped_object.
|
|
53
|
+
subject.wrapped_object.should_receive(:execute_call_command).with do |c|
|
|
54
54
|
c.should be command
|
|
55
55
|
c.target_call_id.should be == call_id
|
|
56
56
|
end
|
|
@@ -63,7 +63,7 @@ module Punchblock
|
|
|
63
63
|
let(:component_id) { '123abc' }
|
|
64
64
|
|
|
65
65
|
it 'executes the component command' do
|
|
66
|
-
subject.wrapped_object.
|
|
66
|
+
subject.wrapped_object.should_receive(:execute_component_command).with do |c|
|
|
67
67
|
c.should be command
|
|
68
68
|
c.component_id.should be == component_id
|
|
69
69
|
end
|
|
@@ -75,7 +75,7 @@ module Punchblock
|
|
|
75
75
|
let(:command) { Command::Dial.new }
|
|
76
76
|
|
|
77
77
|
it 'executes the command directly' do
|
|
78
|
-
subject.wrapped_object.
|
|
78
|
+
subject.wrapped_object.should_receive(:execute_global_command).with command
|
|
79
79
|
subject.execute_command command
|
|
80
80
|
end
|
|
81
81
|
end
|
|
@@ -87,7 +87,7 @@ module Punchblock
|
|
|
87
87
|
let(:call) { Translator::Asterisk::Call.new channel, subject }
|
|
88
88
|
|
|
89
89
|
before do
|
|
90
|
-
call.
|
|
90
|
+
call.stub(:id).and_return call_id
|
|
91
91
|
subject.register_call call
|
|
92
92
|
end
|
|
93
93
|
|
|
@@ -106,7 +106,7 @@ module Punchblock
|
|
|
106
106
|
let(:call) { Translator::Asterisk::Call.new channel, subject }
|
|
107
107
|
|
|
108
108
|
before do
|
|
109
|
-
call.
|
|
109
|
+
call.stub(:id).and_return call_id
|
|
110
110
|
subject.register_call call
|
|
111
111
|
end
|
|
112
112
|
|
|
@@ -142,12 +142,12 @@ module Punchblock
|
|
|
142
142
|
|
|
143
143
|
before do
|
|
144
144
|
command.request!
|
|
145
|
-
call.
|
|
145
|
+
call.stub(:id).and_return call_id
|
|
146
146
|
subject.register_call call
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
it 'sends the command to the call for execution' do
|
|
150
|
-
call.
|
|
150
|
+
call.should_receive(:execute_command!).once.with command
|
|
151
151
|
subject.execute_call_command command
|
|
152
152
|
end
|
|
153
153
|
end
|
|
@@ -166,7 +166,7 @@ module Punchblock
|
|
|
166
166
|
|
|
167
167
|
before do
|
|
168
168
|
subject.execute_command dial_command
|
|
169
|
-
ami_client.
|
|
169
|
+
ami_client.as_null_object
|
|
170
170
|
end
|
|
171
171
|
|
|
172
172
|
it 'sends an error in response to the command' do
|
|
@@ -176,7 +176,7 @@ module Punchblock
|
|
|
176
176
|
raise 'Woops, I died'
|
|
177
177
|
end
|
|
178
178
|
|
|
179
|
-
connection.
|
|
179
|
+
connection.should_receive(:handle_event).once.with end_error_event
|
|
180
180
|
|
|
181
181
|
lambda { call.oops }.should raise_error(/Woops, I died/)
|
|
182
182
|
sleep 0.1
|
|
@@ -202,7 +202,7 @@ module Punchblock
|
|
|
202
202
|
let(:call_id) { call.id }
|
|
203
203
|
|
|
204
204
|
before do
|
|
205
|
-
connection.
|
|
205
|
+
connection.stub :handle_event
|
|
206
206
|
subject.handle_ami_event ami_event
|
|
207
207
|
call_id
|
|
208
208
|
end
|
|
@@ -212,7 +212,7 @@ module Punchblock
|
|
|
212
212
|
raise 'Woops, I died'
|
|
213
213
|
end
|
|
214
214
|
|
|
215
|
-
connection.
|
|
215
|
+
connection.should_receive(:handle_event).once.with end_error_event
|
|
216
216
|
|
|
217
217
|
lambda { call.oops }.should raise_error(/Woops, I died/)
|
|
218
218
|
sleep 0.1
|
|
@@ -250,7 +250,7 @@ module Punchblock
|
|
|
250
250
|
end
|
|
251
251
|
|
|
252
252
|
it 'sends the command to the component for execution' do
|
|
253
|
-
component.
|
|
253
|
+
component.should_receive(:execute_command!).once.with command
|
|
254
254
|
subject.execute_component_command command
|
|
255
255
|
end
|
|
256
256
|
end
|
|
@@ -271,7 +271,7 @@ module Punchblock
|
|
|
271
271
|
|
|
272
272
|
before do
|
|
273
273
|
command.request!
|
|
274
|
-
ami_client.
|
|
274
|
+
ami_client.as_null_object
|
|
275
275
|
end
|
|
276
276
|
|
|
277
277
|
it 'should be able to look up the call by channel ID' do
|
|
@@ -281,9 +281,9 @@ module Punchblock
|
|
|
281
281
|
end
|
|
282
282
|
|
|
283
283
|
it 'should instruct the call to send a dial' do
|
|
284
|
-
mock_call =
|
|
285
|
-
Asterisk::Call.
|
|
286
|
-
mock_call.
|
|
284
|
+
mock_call = stub('Asterisk::Call').as_null_object
|
|
285
|
+
Asterisk::Call.should_receive(:new_link).once.and_return mock_call
|
|
286
|
+
mock_call.should_receive(:dial!).once.with command
|
|
287
287
|
subject.execute_global_command command
|
|
288
288
|
end
|
|
289
289
|
end
|
|
@@ -293,17 +293,17 @@ module Punchblock
|
|
|
293
293
|
Component::Asterisk::AMI::Action.new :name => 'Status', :params => { :channel => 'foo' }
|
|
294
294
|
end
|
|
295
295
|
|
|
296
|
-
let(:mock_action) {
|
|
296
|
+
let(:mock_action) { stub('Asterisk::Component::Asterisk::AMIAction').as_null_object }
|
|
297
297
|
|
|
298
298
|
it 'should create a component actor and execute it asynchronously' do
|
|
299
|
-
Asterisk::Component::Asterisk::AMIAction.
|
|
300
|
-
mock_action.
|
|
299
|
+
Asterisk::Component::Asterisk::AMIAction.should_receive(:new).once.with(command, subject).and_return mock_action
|
|
300
|
+
mock_action.should_receive(:execute!).once
|
|
301
301
|
subject.execute_global_command command
|
|
302
302
|
end
|
|
303
303
|
|
|
304
304
|
it 'registers the component' do
|
|
305
|
-
Asterisk::Component::Asterisk::AMIAction.
|
|
306
|
-
subject.wrapped_object.
|
|
305
|
+
Asterisk::Component::Asterisk::AMIAction.should_receive(:new).once.with(command, subject).and_return mock_action
|
|
306
|
+
subject.wrapped_object.should_receive(:register_component).with mock_action
|
|
307
307
|
subject.execute_global_command command
|
|
308
308
|
end
|
|
309
309
|
end
|
|
@@ -323,7 +323,7 @@ module Punchblock
|
|
|
323
323
|
describe '#handle_pb_event' do
|
|
324
324
|
it 'should forward the event to the connection' do
|
|
325
325
|
event = mock 'Punchblock::Event'
|
|
326
|
-
subject.connection.
|
|
326
|
+
subject.connection.should_receive(:handle_event).once.with event
|
|
327
327
|
subject.handle_pb_event event
|
|
328
328
|
end
|
|
329
329
|
end
|
|
@@ -347,13 +347,13 @@ module Punchblock
|
|
|
347
347
|
end
|
|
348
348
|
|
|
349
349
|
it 'should create a Punchblock AMI event object and pass it to the connection' do
|
|
350
|
-
subject.connection.
|
|
350
|
+
subject.connection.should_receive(:handle_event).once.with expected_pb_event
|
|
351
351
|
subject.handle_ami_event ami_event
|
|
352
352
|
end
|
|
353
353
|
|
|
354
354
|
context 'with something that is not a RubyAMI::Event' do
|
|
355
355
|
it 'does not send anything to the connection' do
|
|
356
|
-
subject.connection.
|
|
356
|
+
subject.connection.should_receive(:handle_event).never
|
|
357
357
|
subject.handle_ami_event :foo
|
|
358
358
|
end
|
|
359
359
|
end
|
|
@@ -363,15 +363,15 @@ module Punchblock
|
|
|
363
363
|
|
|
364
364
|
context 'once' do
|
|
365
365
|
it 'does not send anything to the connection' do
|
|
366
|
-
subject.connection.
|
|
366
|
+
subject.connection.should_receive(:handle_event).never
|
|
367
367
|
subject.handle_ami_event ami_event
|
|
368
368
|
end
|
|
369
369
|
end
|
|
370
370
|
|
|
371
371
|
context 'twice' do
|
|
372
372
|
it 'sends a connected event to the event handler' do
|
|
373
|
-
subject.connection.
|
|
374
|
-
subject.wrapped_object.
|
|
373
|
+
subject.connection.should_receive(:handle_event).once.with Connection::Connected.new
|
|
374
|
+
subject.wrapped_object.should_receive(:run_at_fully_booted).once
|
|
375
375
|
subject.handle_ami_event ami_event
|
|
376
376
|
subject.handle_ami_event ami_event
|
|
377
377
|
end
|
|
@@ -387,7 +387,7 @@ module Punchblock
|
|
|
387
387
|
end
|
|
388
388
|
end
|
|
389
389
|
|
|
390
|
-
before { subject.wrapped_object.
|
|
390
|
+
before { subject.wrapped_object.stub :handle_pb_event }
|
|
391
391
|
|
|
392
392
|
it 'should be able to look up the call by channel ID' do
|
|
393
393
|
subject.handle_ami_event ami_event
|
|
@@ -419,10 +419,10 @@ module Punchblock
|
|
|
419
419
|
end
|
|
420
420
|
|
|
421
421
|
it 'should instruct the call to send an offer' do
|
|
422
|
-
mock_call =
|
|
423
|
-
Asterisk::Call.
|
|
424
|
-
subject.wrapped_object.
|
|
425
|
-
mock_call.
|
|
422
|
+
mock_call = stub('Asterisk::Call').as_null_object
|
|
423
|
+
Asterisk::Call.should_receive(:new).once.and_return mock_call
|
|
424
|
+
subject.wrapped_object.should_receive(:link)
|
|
425
|
+
mock_call.should_receive(:send_offer!).once
|
|
426
426
|
subject.handle_ami_event ami_event
|
|
427
427
|
end
|
|
428
428
|
|
|
@@ -434,7 +434,7 @@ module Punchblock
|
|
|
434
434
|
end
|
|
435
435
|
|
|
436
436
|
it "should not create a new call" do
|
|
437
|
-
Asterisk::Call.
|
|
437
|
+
Asterisk::Call.should_receive(:new).never
|
|
438
438
|
subject.handle_ami_event ami_event
|
|
439
439
|
end
|
|
440
440
|
end
|
|
@@ -449,7 +449,7 @@ module Punchblock
|
|
|
449
449
|
end
|
|
450
450
|
|
|
451
451
|
it "should not create a new call" do
|
|
452
|
-
Asterisk::Call.
|
|
452
|
+
Asterisk::Call.should_receive(:new).never
|
|
453
453
|
subject.handle_ami_event ami_event
|
|
454
454
|
end
|
|
455
455
|
|
|
@@ -469,7 +469,7 @@ module Punchblock
|
|
|
469
469
|
end
|
|
470
470
|
|
|
471
471
|
it "should not create a new call" do
|
|
472
|
-
Asterisk::Call.
|
|
472
|
+
Asterisk::Call.should_receive(:new).never
|
|
473
473
|
subject.handle_ami_event ami_event
|
|
474
474
|
end
|
|
475
475
|
|
|
@@ -492,8 +492,8 @@ module Punchblock
|
|
|
492
492
|
end
|
|
493
493
|
|
|
494
494
|
before do
|
|
495
|
-
ami_client.
|
|
496
|
-
subject.wrapped_object.
|
|
495
|
+
ami_client.as_null_object
|
|
496
|
+
subject.wrapped_object.stub :handle_pb_event
|
|
497
497
|
end
|
|
498
498
|
|
|
499
499
|
context "matching a call that was created by a Dial command" do
|
|
@@ -554,7 +554,7 @@ module Punchblock
|
|
|
554
554
|
end
|
|
555
555
|
|
|
556
556
|
it 'sends the AMI event to the call and to the connection as a PB event' do
|
|
557
|
-
call.
|
|
557
|
+
call.should_receive(:process_ami_event!).once.with ami_event
|
|
558
558
|
subject.handle_ami_event ami_event
|
|
559
559
|
end
|
|
560
560
|
|
|
@@ -576,8 +576,8 @@ module Punchblock
|
|
|
576
576
|
before { subject.register_call call2 }
|
|
577
577
|
|
|
578
578
|
it 'should send the event to both calls and to the connection once as a PB event' do
|
|
579
|
-
call.
|
|
580
|
-
call2.
|
|
579
|
+
call.should_receive(:process_ami_event!).once.with ami_event
|
|
580
|
+
call2.should_receive(:process_ami_event!).once.with ami_event
|
|
581
581
|
subject.handle_ami_event ami_event
|
|
582
582
|
end
|
|
583
583
|
end
|
|
@@ -612,12 +612,12 @@ module Punchblock
|
|
|
612
612
|
end
|
|
613
613
|
|
|
614
614
|
it 'sends the AMI event to the call and to the connection as a PB event if it is an allowed event' do
|
|
615
|
-
call.
|
|
615
|
+
call.should_receive(:process_ami_event!).once.with ami_event
|
|
616
616
|
subject.handle_ami_event ami_event
|
|
617
617
|
end
|
|
618
618
|
|
|
619
619
|
it 'does not send the AMI event to a bridged channel if it is not allowed' do
|
|
620
|
-
call.
|
|
620
|
+
call.should_receive(:process_ami_event!).never.with ami_event2
|
|
621
621
|
subject.handle_ami_event ami_event2
|
|
622
622
|
end
|
|
623
623
|
|
|
@@ -626,7 +626,7 @@ module Punchblock
|
|
|
626
626
|
|
|
627
627
|
describe '#send_ami_action' do
|
|
628
628
|
it 'should send the action to the AMI client' do
|
|
629
|
-
ami_client.
|
|
629
|
+
ami_client.should_receive(:send_action).once.with 'foo', :foo => :bar
|
|
630
630
|
subject.send_ami_action 'foo', :foo => :bar
|
|
631
631
|
end
|
|
632
632
|
end
|
|
@@ -641,31 +641,31 @@ module Punchblock
|
|
|
641
641
|
end
|
|
642
642
|
|
|
643
643
|
it 'should send the redirect extension Command to the AMI client' do
|
|
644
|
-
ami_client.
|
|
645
|
-
ami_client.
|
|
644
|
+
ami_client.should_receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
|
|
645
|
+
ami_client.should_receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}")
|
|
646
646
|
subject.run_at_fully_booted
|
|
647
647
|
end
|
|
648
648
|
|
|
649
649
|
it 'should check the context for existence and do nothing if it is there' do
|
|
650
|
-
ami_client.
|
|
651
|
-
ami_client.
|
|
650
|
+
ami_client.should_receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
|
|
651
|
+
ami_client.should_receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").and_yield(passed_show)
|
|
652
652
|
subject.run_at_fully_booted
|
|
653
653
|
end
|
|
654
654
|
|
|
655
655
|
it 'should check the context for existence and log an error if it is not there' do
|
|
656
|
-
ami_client.
|
|
657
|
-
ami_client.
|
|
658
|
-
Punchblock.logger.
|
|
656
|
+
ami_client.should_receive(:send_action).once.with 'Command', 'Command' => "dialplan add extension #{Asterisk::REDIRECT_EXTENSION},#{Asterisk::REDIRECT_PRIORITY},AGI,agi:async into #{Asterisk::REDIRECT_CONTEXT}"
|
|
657
|
+
ami_client.should_receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").and_yield(failed_show)
|
|
658
|
+
Punchblock.logger.should_receive(:error).once.with("Punchblock failed to add the #{Asterisk::REDIRECT_EXTENSION} extension to the #{Asterisk::REDIRECT_CONTEXT} context. Please add a [#{Asterisk::REDIRECT_CONTEXT}] entry to your dialplan.")
|
|
659
659
|
subject.run_at_fully_booted
|
|
660
660
|
end
|
|
661
661
|
end
|
|
662
|
-
|
|
662
|
+
|
|
663
663
|
describe '#check_recording_directory' do
|
|
664
664
|
let(:broken_path) { "/this/is/not/a/valid/path" }
|
|
665
665
|
before do
|
|
666
666
|
@new_constant = broken_path
|
|
667
|
-
@old_constant = Punchblock::Translator::Asterisk::Component::Record::RECORDING_BASE_PATH
|
|
668
|
-
Punchblock::Translator::Asterisk::Component::Record.__send__(:remove_const,'RECORDING_BASE_PATH')
|
|
667
|
+
@old_constant = Punchblock::Translator::Asterisk::Component::Record::RECORDING_BASE_PATH
|
|
668
|
+
Punchblock::Translator::Asterisk::Component::Record.__send__(:remove_const,'RECORDING_BASE_PATH')
|
|
669
669
|
Punchblock::Translator::Asterisk::Component::Record.const_set('RECORDING_BASE_PATH', @new_constant)
|
|
670
670
|
end
|
|
671
671
|
after do
|
|
@@ -673,7 +673,7 @@ module Punchblock
|
|
|
673
673
|
Punchblock::Translator::Asterisk::Component::Record.const_set('RECORDING_BASE_PATH', @old_constant)
|
|
674
674
|
end
|
|
675
675
|
it 'logs a warning if the recording directory does not exist' do
|
|
676
|
-
Punchblock.logger.
|
|
676
|
+
Punchblock.logger.should_receive(:warning).once.with("Recordings directory #{broken_path} does not exist. Recording might not work. This warning can be ignored if Adhearsion is running on a separate machine than Asterisk. See http://adhearsion.com/docs/call-controllers#recording")
|
|
677
677
|
subject.check_recording_directory
|
|
678
678
|
end
|
|
679
679
|
end
|