punchblock 1.8.0 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +12 -0
  3. data/Gemfile +1 -1
  4. data/lib/punchblock/component/component_node.rb +1 -1
  5. data/lib/punchblock/component/stop.rb +2 -2
  6. data/lib/punchblock/connection/asterisk.rb +3 -3
  7. data/lib/punchblock/connection/freeswitch.rb +2 -2
  8. data/lib/punchblock/connection/xmpp.rb +1 -1
  9. data/lib/punchblock/translator.rb +1 -0
  10. data/lib/punchblock/translator/asterisk.rb +10 -9
  11. data/lib/punchblock/translator/asterisk/call.rb +15 -7
  12. data/lib/punchblock/translator/asterisk/component/asterisk/ami_action.rb +1 -1
  13. data/lib/punchblock/translator/asterisk/component/input.rb +3 -4
  14. data/lib/punchblock/translator/asterisk/component/output.rb +6 -6
  15. data/lib/punchblock/translator/asterisk/component/record.rb +7 -7
  16. data/lib/punchblock/translator/asterisk/component/stop_by_redirect.rb +3 -3
  17. data/lib/punchblock/translator/dtmf_recognizer.rb +87 -0
  18. data/lib/punchblock/translator/freeswitch.rb +9 -7
  19. data/lib/punchblock/translator/freeswitch/call.rb +6 -4
  20. data/lib/punchblock/translator/freeswitch/component/input.rb +1 -2
  21. data/lib/punchblock/translator/freeswitch/component/output.rb +1 -2
  22. data/lib/punchblock/translator/freeswitch/component/tts_output.rb +1 -1
  23. data/lib/punchblock/translator/input_component.rb +17 -64
  24. data/lib/punchblock/version.rb +1 -1
  25. data/punchblock.gemspec +1 -1
  26. data/spec/punchblock/component/input_spec.rb +1 -1
  27. data/spec/punchblock/component/output_spec.rb +33 -3
  28. data/spec/punchblock/component/record_spec.rb +1 -1
  29. data/spec/punchblock/connection/asterisk_spec.rb +3 -3
  30. data/spec/punchblock/connection/freeswitch_spec.rb +3 -2
  31. data/spec/punchblock/connection/xmpp_spec.rb +18 -6
  32. data/spec/punchblock/translator/asterisk/call_spec.rb +83 -31
  33. data/spec/punchblock/translator/asterisk/component/input_spec.rb +1 -1
  34. data/spec/punchblock/translator/asterisk/component/output_spec.rb +32 -27
  35. data/spec/punchblock/translator/asterisk/component/record_spec.rb +47 -43
  36. data/spec/punchblock/translator/asterisk/component/stop_by_redirect_spec.rb +2 -2
  37. data/spec/punchblock/translator/asterisk_spec.rb +28 -26
  38. data/spec/punchblock/translator/freeswitch/call_spec.rb +24 -15
  39. data/spec/punchblock/translator/freeswitch/component/input_spec.rb +1 -1
  40. data/spec/punchblock/translator/freeswitch/component/output_spec.rb +2 -3
  41. data/spec/punchblock/translator/freeswitch/component/record_spec.rb +1 -1
  42. data/spec/punchblock/translator/freeswitch_spec.rb +75 -18
  43. data/spec/spec_helper.rb +1 -1
  44. metadata +24 -74
@@ -15,7 +15,7 @@ module Punchblock
15
15
  end
16
16
  end
17
17
 
18
- let(:mock_call) { mock 'Call', :id => 'foo' }
18
+ let(:mock_call) { Call.new 'SIP/foo', mock('Translator') }
19
19
  subject { MockComponent.new Hash.new, mock_call }
20
20
 
21
21
  describe "#execute_command" do
@@ -37,7 +37,7 @@ module Punchblock
37
37
  end
38
38
 
39
39
  it "sets the command response to true" do
40
- mock_call.should_receive(:redirect_back!)
40
+ mock_call.async.should_receive(:redirect_back)
41
41
  mock_call.should_receive(:register_handler).with do |type, *guards|
42
42
  type.should be == :ami
43
43
  guards.should have(2).guards
@@ -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.should_receive(:shutdown!).once
35
+ call.async.should_receive(:shutdown).once
36
36
  subject.register_call call
37
37
  subject.shutdown
38
38
  end
@@ -147,7 +147,7 @@ module Punchblock
147
147
  end
148
148
 
149
149
  it 'sends the command to the call for execution' do
150
- call.should_receive(:execute_command!).once.with command
150
+ call.async.should_receive(:execute_command).once.with command
151
151
  subject.execute_call_command command
152
152
  end
153
153
  end
@@ -235,10 +235,11 @@ module Punchblock
235
235
  end
236
236
 
237
237
  describe '#execute_component_command' do
238
- let(:component_id) { '123abc' }
239
- let(:component) { mock 'Translator::Asterisk::Component', :id => component_id }
238
+ let(:call) { Translator::Asterisk::Call.new 'SIP/foo', subject }
239
+ let(:component_node) { Component::Output.new }
240
+ let(:component) { Translator::Asterisk::Component::Output.new(component_node, call) }
240
241
 
241
- let(:command) { Component::Stop.new.tap { |c| c.component_id = component_id } }
242
+ let(:command) { Component::Stop.new.tap { |c| c.component_id = component.id } }
242
243
 
243
244
  before do
244
245
  command.request!
@@ -250,7 +251,7 @@ module Punchblock
250
251
  end
251
252
 
252
253
  it 'sends the command to the component for execution' do
253
- component.should_receive(:execute_command!).once.with command
254
+ component.async.should_receive(:execute_command).once.with command
254
255
  subject.execute_component_command command
255
256
  end
256
257
  end
@@ -258,7 +259,7 @@ module Punchblock
258
259
  context "with an unknown component ID" do
259
260
  it 'sends an error in response to the command' do
260
261
  subject.execute_component_command command
261
- command.response.should be == ProtocolError.new.setup(:item_not_found, "Could not find a component with ID #{component_id}", nil, component_id)
262
+ command.response.should be == ProtocolError.new.setup(:item_not_found, "Could not find a component with ID #{component.id}", nil, component.id)
262
263
  end
263
264
  end
264
265
  end
@@ -283,7 +284,7 @@ module Punchblock
283
284
  it 'should instruct the call to send a dial' do
284
285
  mock_call = stub('Asterisk::Call').as_null_object
285
286
  Asterisk::Call.should_receive(:new_link).once.and_return mock_call
286
- mock_call.should_receive(:dial!).once.with command
287
+ mock_call.async.should_receive(:dial).once.with command
287
288
  subject.execute_global_command command
288
289
  end
289
290
  end
@@ -297,7 +298,7 @@ module Punchblock
297
298
 
298
299
  it 'should create a component actor and execute it asynchronously' do
299
300
  Asterisk::Component::Asterisk::AMIAction.should_receive(:new).once.with(command, subject).and_return mock_action
300
- mock_action.should_receive(:execute!).once
301
+ mock_action.async.should_receive(:execute).once
301
302
  subject.execute_global_command command
302
303
  end
303
304
 
@@ -422,7 +423,7 @@ module Punchblock
422
423
  mock_call = stub('Asterisk::Call').as_null_object
423
424
  Asterisk::Call.should_receive(:new).once.and_return mock_call
424
425
  subject.wrapped_object.should_receive(:link)
425
- mock_call.should_receive(:send_offer!).once
426
+ mock_call.async.should_receive(:send_offer).once
426
427
  subject.handle_ami_event ami_event
427
428
  end
428
429
 
@@ -554,7 +555,7 @@ module Punchblock
554
555
  end
555
556
 
556
557
  it 'sends the AMI event to the call and to the connection as a PB event' do
557
- call.should_receive(:process_ami_event!).once.with ami_event
558
+ call.async.should_receive(:process_ami_event).once.with ami_event
558
559
  subject.handle_ami_event ami_event
559
560
  end
560
561
 
@@ -576,8 +577,8 @@ module Punchblock
576
577
  before { subject.register_call call2 }
577
578
 
578
579
  it 'should send the event to both calls and to the connection once as a PB event' do
579
- call.should_receive(:process_ami_event!).once.with ami_event
580
- call2.should_receive(:process_ami_event!).once.with ami_event
580
+ call.async.should_receive(:process_ami_event).once.with ami_event
581
+ call2.async.should_receive(:process_ami_event).once.with ami_event
581
582
  subject.handle_ami_event ami_event
582
583
  end
583
584
  end
@@ -612,12 +613,12 @@ module Punchblock
612
613
  end
613
614
 
614
615
  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.should_receive(:process_ami_event!).once.with ami_event
616
+ call.async.should_receive(:process_ami_event).once.with ami_event
616
617
  subject.handle_ami_event ami_event
617
618
  end
618
619
 
619
620
  it 'does not send the AMI event to a bridged channel if it is not allowed' do
620
- call.should_receive(:process_ami_event!).never.with ami_event2
621
+ call.async.should_receive(:process_ami_event).never.with ami_event2
621
622
  subject.handle_ami_event ami_event2
622
623
  end
623
624
 
@@ -632,6 +633,8 @@ module Punchblock
632
633
  end
633
634
 
634
635
  describe '#run_at_fully_booted' do
636
+ let(:broken_path) { "/this/is/not/a/valid/path" }
637
+
635
638
  let(:passed_show) do
636
639
  OpenStruct.new({:text_body => "[ Context 'adhearsion-redirect' created by 'pbx_config' ]\n '1' => 1. AGI(agi:async)[pbx_config]\n\n-= 1 extension (1 priority) in 1 context. =-"})
637
640
  end
@@ -658,22 +661,21 @@ module Punchblock
658
661
  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
662
  subject.run_at_fully_booted
660
663
  end
664
+
665
+ it 'should check the recording directory for existence' do
666
+ stub_const('Punchblock::Translator::Asterisk::Component::Record::RECORDING_BASE_PATH', broken_path)
667
+ 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}"
668
+ ami_client.should_receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}")
669
+ Punchblock.logger.should_receive(:warn).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")
670
+ subject.run_at_fully_booted
671
+ end
661
672
  end
662
673
 
663
674
  describe '#check_recording_directory' do
664
675
  let(:broken_path) { "/this/is/not/a/valid/path" }
665
- before do
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')
669
- Punchblock::Translator::Asterisk::Component::Record.const_set('RECORDING_BASE_PATH', @new_constant)
670
- end
671
- after do
672
- Punchblock::Translator::Asterisk::Component::Record.__send__(:remove_const,'RECORDING_BASE_PATH')
673
- Punchblock::Translator::Asterisk::Component::Record.const_set('RECORDING_BASE_PATH', @old_constant)
674
- end
675
676
  it 'logs a warning if the recording directory does not exist' do
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
+ stub_const('Punchblock::Translator::Asterisk::Component::Record::RECORDING_BASE_PATH', broken_path)
678
+ Punchblock.logger.should_receive(:warn).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
679
  subject.check_recording_directory
678
680
  end
679
681
  end
@@ -279,6 +279,15 @@ module Punchblock
279
279
  end
280
280
  end
281
281
 
282
+ context 'with no from attribute' do
283
+ let(:from) { nil }
284
+
285
+ it 'sends an originate bgapi command with the cid fields set correctly' do
286
+ stream.should_receive(:bgapi).once.with "originate {return_ring_ready=true,origination_uuid=#{subject.id}}#{to} &park()"
287
+ subject.dial dial_command
288
+ end
289
+ end
290
+
282
291
  context 'with a timeout specified' do
283
292
  let :dial_command_options do
284
293
  { :timeout => 10000 }
@@ -765,7 +774,7 @@ module Punchblock
765
774
  Punchblock::Component::Output.new
766
775
  end
767
776
 
768
- let(:mock_component) { mock 'Freeswitch::Component::Output', :id => 'foo' }
777
+ let(:mock_component) { Translator::Freeswitch::Component::Output.new(command, subject) }
769
778
 
770
779
  ['freeswitch', nil].each do |media_engine|
771
780
  let(:media_engine) { media_engine }
@@ -773,9 +782,9 @@ module Punchblock
773
782
  context "with a media engine of #{media_engine}" do
774
783
  it 'should create an Output component and execute it asynchronously' do
775
784
  Component::Output.should_receive(:new_link).once.with(command, subject).and_return mock_component
776
- mock_component.should_receive(:execute!).once
785
+ mock_component.async.should_receive(:execute).once
777
786
  subject.execute_command command
778
- subject.component_with_id('foo').should be mock_component
787
+ subject.component_with_id(mock_component.id).should be mock_component
779
788
  end
780
789
  end
781
790
  end
@@ -785,9 +794,9 @@ module Punchblock
785
794
 
786
795
  it 'should create a FliteOutput component and execute it asynchronously using flite and the calls default voice' do
787
796
  Component::FliteOutput.should_receive(:new_link).once.with(command, subject).and_return mock_component
788
- mock_component.should_receive(:execute!).once.with(media_engine, default_voice)
797
+ mock_component.async.should_receive(:execute).once.with(media_engine, default_voice)
789
798
  subject.execute_command command
790
- subject.component_with_id('foo').should be mock_component
799
+ subject.component_with_id(mock_component.id).should be mock_component
791
800
  end
792
801
  end
793
802
 
@@ -796,9 +805,9 @@ module Punchblock
796
805
 
797
806
  it 'should create a TTSOutput component and execute it asynchronously using cepstral and the calls default voice' do
798
807
  Component::TTSOutput.should_receive(:new_link).once.with(command, subject).and_return mock_component
799
- mock_component.should_receive(:execute!).once.with(media_engine, default_voice)
808
+ mock_component.async.should_receive(:execute).once.with(media_engine, default_voice)
800
809
  subject.execute_command command
801
- subject.component_with_id('foo').should be mock_component
810
+ subject.component_with_id(mock_component.id).should be mock_component
802
811
  end
803
812
  end
804
813
 
@@ -807,9 +816,9 @@ module Punchblock
807
816
 
808
817
  it 'should create a TTSOutput component and execute it asynchronously using unimrcp and the calls default voice' do
809
818
  Component::TTSOutput.should_receive(:new_link).once.with(command, subject).and_return mock_component
810
- mock_component.should_receive(:execute!).once.with(media_engine, default_voice)
819
+ mock_component.async.should_receive(:execute).once.with(media_engine, default_voice)
811
820
  subject.execute_command command
812
- subject.component_with_id('foo').should be mock_component
821
+ subject.component_with_id(mock_component.id).should be mock_component
813
822
  end
814
823
  end
815
824
 
@@ -822,9 +831,9 @@ module Punchblock
822
831
 
823
832
  it "should use the component media engine and not the platform one if it is set" do
824
833
  Component::Output.should_receive(:new_link).once.with(command_with_renderer, subject).and_return mock_component
825
- mock_component.should_receive(:execute!).once
834
+ mock_component.async.should_receive(:execute).once
826
835
  subject.execute_command command_with_renderer
827
- subject.component_with_id('foo').should be mock_component
836
+ subject.component_with_id(mock_component.id).should be mock_component
828
837
  end
829
838
  end
830
839
  end
@@ -834,11 +843,11 @@ module Punchblock
834
843
  Punchblock::Component::Input.new
835
844
  end
836
845
 
837
- let(:mock_component) { mock 'Freeswitch::Component::Input', :id => 'foo' }
846
+ let(:mock_component) { Translator::Freeswitch::Component::Input.new(command, subject) }
838
847
 
839
848
  it 'should create an Input component and execute it asynchronously' do
840
849
  Component::Input.should_receive(:new_link).once.with(command, subject).and_return mock_component
841
- mock_component.should_receive(:execute!).once
850
+ mock_component.async.should_receive(:execute).once
842
851
  subject.execute_command command
843
852
  end
844
853
  end
@@ -848,11 +857,11 @@ module Punchblock
848
857
  Punchblock::Component::Record.new
849
858
  end
850
859
 
851
- let(:mock_component) { mock 'Freeswitch::Component::Record', :id => 'foo' }
860
+ let(:mock_component) { Translator::Freeswitch::Component::Record.new(command, subject) }
852
861
 
853
862
  it 'should create a Record component and execute it asynchronously' do
854
863
  Component::Record.should_receive(:new_link).once.with(command, subject).and_return mock_component
855
- mock_component.should_receive(:execute!).once
864
+ mock_component.async.should_receive(:execute).once
856
865
  subject.execute_command command
857
866
  end
858
867
  end
@@ -88,7 +88,7 @@ module Punchblock
88
88
  end
89
89
 
90
90
  it "should not process further dtmf events" do
91
- subject.should_receive(:process_dtmf!).never
91
+ subject.async.should_receive(:process_dtmf).never
92
92
  send_dtmf 3
93
93
  end
94
94
  end
@@ -270,10 +270,9 @@ module Punchblock
270
270
 
271
271
  context 'set' do
272
272
  let(:command_opts) { { :voice => 'alison' } }
273
- it "should return an error and not execute any actions" do
273
+ it "should ignore the voice option" do
274
+ expect_playback
274
275
  subject.execute
275
- error = ProtocolError.new.setup 'option error', 'A voice value is unsupported.'
276
- original_command.response(0.1).should be == error
277
276
  end
278
277
  end
279
278
  end
@@ -143,7 +143,7 @@ module Punchblock
143
143
  context "set to a positive number" do
144
144
  let(:command_options) { { :final_timeout => 10 } }
145
145
  it "should return an error and not execute any actions" do
146
- mock_call.should_receive(:send_agi_action!).never
146
+ mock_call.should_receive(:uuid_foo).never
147
147
  subject.execute
148
148
  error = ProtocolError.new.setup 'option error', 'A final-timeout value is unsupported.'
149
149
  original_command.response(0.1).should be == error
@@ -7,7 +7,7 @@ module Punchblock
7
7
  describe Freeswitch do
8
8
  let(:connection) { mock 'Connection::Freeswitch' }
9
9
  let(:media_engine) { :flite }
10
- let(:default_voice) { :hal }
10
+ let(:default_voice) { :hal }
11
11
 
12
12
  let(:translator) { described_class.new connection, media_engine, default_voice }
13
13
  let(:stream) { mock 'RubyFS::Stream' }
@@ -117,7 +117,7 @@ module Punchblock
117
117
  end
118
118
 
119
119
  it 'sends the command to the call for execution' do
120
- call.should_receive(:execute_command!).once.with command
120
+ call.async.should_receive(:execute_command).once.with command
121
121
  subject.execute_call_command command
122
122
  end
123
123
  end
@@ -201,10 +201,11 @@ module Punchblock
201
201
  end
202
202
 
203
203
  describe '#execute_component_command' do
204
- let(:component_id) { '123abc' }
205
- let(:component) { mock 'Translator::Freeswitch::Component', :id => component_id }
204
+ let(:call) { Translator::Freeswitch::Call.new 'SIP/foo', subject }
205
+ let(:component_node) { Component::Output.new }
206
+ let(:component) { Translator::Freeswitch::Component::Output.new(component_node, call) }
206
207
 
207
- let(:command) { Component::Stop.new.tap { |c| c.component_id = component_id } }
208
+ let(:command) { Component::Stop.new.tap { |c| c.component_id = component.id } }
208
209
 
209
210
  before do
210
211
  command.request!
@@ -216,7 +217,7 @@ module Punchblock
216
217
  end
217
218
 
218
219
  it 'sends the command to the component for execution' do
219
- component.should_receive(:execute_command!).once.with command
220
+ component.async.should_receive(:execute_command).once.with command
220
221
  subject.execute_component_command command
221
222
  end
222
223
  end
@@ -224,7 +225,7 @@ module Punchblock
224
225
  context "with an unknown component ID" do
225
226
  it 'sends an error in response to the command' do
226
227
  subject.execute_component_command command
227
- command.response.should be == ProtocolError.new.setup(:item_not_found, "Could not find a component with ID #{component_id}", nil, component_id)
228
+ command.response.should be == ProtocolError.new.setup(:item_not_found, "Could not find a component with ID #{component.id}", nil, component.id)
228
229
  end
229
230
  end
230
231
  end
@@ -257,7 +258,7 @@ module Punchblock
257
258
  it 'should instruct the call to send a dial' do
258
259
  mock_call = stub('Freeswitch::Call').as_null_object
259
260
  Freeswitch::Call.should_receive(:new_link).once.and_return mock_call
260
- mock_call.should_receive(:dial!).once.with command
261
+ mock_call.async.should_receive(:dial).once.with command
261
262
  subject.execute_global_command command
262
263
  end
263
264
  end
@@ -532,7 +533,7 @@ module Punchblock
532
533
  mock_call = stub('Freeswitch::Call').as_null_object
533
534
  Freeswitch::Call.should_receive(:new).once.and_return mock_call
534
535
  subject.wrapped_object.should_receive(:link)
535
- mock_call.should_receive(:send_offer!).once
536
+ mock_call.async.should_receive(:send_offer).once
536
537
  subject.handle_es_event es_event
537
538
  end
538
539
 
@@ -550,7 +551,67 @@ module Punchblock
550
551
  end
551
552
  end
552
553
 
553
- describe 'with an event with an Other-Leg-Unique-ID value' do
554
+ describe "with a CHANNEL_BRIDGE event" do
555
+ describe 'with an Other-Leg-Unique-ID value' do
556
+ let(:call_a) { Freeswitch::Call.new Punchblock.new_uuid, subject }
557
+ let(:call_b) { Freeswitch::Call.new Punchblock.new_uuid, subject }
558
+
559
+ before do
560
+ subject.register_call call_a
561
+ subject.register_call call_b
562
+ end
563
+
564
+ let :es_event do
565
+ RubyFS::Event.new nil, {
566
+ :event_name => 'CHANNEL_BRIDGE',
567
+ :unique_id => call_a.id,
568
+ :other_leg_unique_id => call_b.id
569
+ }
570
+ end
571
+
572
+ it "is delivered to the bridging leg" do
573
+ call_a.async.should_receive(:handle_es_event).once.with es_event
574
+ subject.handle_es_event es_event
575
+ end
576
+
577
+ it "is delivered to the other leg" do
578
+ call_b.async.should_receive(:handle_es_event).once.with es_event
579
+ subject.handle_es_event es_event
580
+ end
581
+ end
582
+ end
583
+
584
+ describe "with a CHANNEL_UNBRIDGE event" do
585
+ describe 'with an Other-Leg-Unique-ID value' do
586
+ let(:call_a) { Freeswitch::Call.new Punchblock.new_uuid, subject }
587
+ let(:call_b) { Freeswitch::Call.new Punchblock.new_uuid, subject }
588
+
589
+ before do
590
+ subject.register_call call_a
591
+ subject.register_call call_b
592
+ end
593
+
594
+ let :es_event do
595
+ RubyFS::Event.new nil, {
596
+ :event_name => 'CHANNEL_UNBRIDGE',
597
+ :unique_id => call_a.id,
598
+ :other_leg_unique_id => call_b.id
599
+ }
600
+ end
601
+
602
+ it "is delivered to the bridging leg" do
603
+ call_a.async.should_receive(:handle_es_event).once.with es_event
604
+ subject.handle_es_event es_event
605
+ end
606
+
607
+ it "is delivered to the other leg" do
608
+ call_b.async.should_receive(:handle_es_event).once.with es_event
609
+ subject.handle_es_event es_event
610
+ end
611
+ end
612
+ end
613
+
614
+ describe 'with an Other-Leg-Unique-ID value' do
554
615
  let(:call_a) { Freeswitch::Call.new Punchblock.new_uuid, subject }
555
616
  let(:call_b) { Freeswitch::Call.new Punchblock.new_uuid, subject }
556
617
 
@@ -566,13 +627,9 @@ module Punchblock
566
627
  }
567
628
  end
568
629
 
569
- it "is delivered to the bridging leg" do
570
- call_a.should_receive(:handle_es_event!).once.with es_event
571
- subject.handle_es_event es_event
572
- end
573
-
574
- it "is delivered to the other leg" do
575
- call_b.should_receive(:handle_es_event!).once.with es_event
630
+ it "is delivered only to the primary leg" do
631
+ call_a.async.should_receive(:handle_es_event).once.with es_event
632
+ call_b.async.should_receive(:handle_es_event).never
576
633
  subject.handle_es_event es_event
577
634
  end
578
635
  end
@@ -587,7 +644,7 @@ module Punchblock
587
644
  end
588
645
 
589
646
  it 'sends the ES event to the call' do
590
- call.should_receive(:handle_es_event!).once.with es_event
647
+ call.async.should_receive(:handle_es_event).once.with es_event
591
648
  subject.handle_es_event es_event
592
649
  end
593
650
  end