punchblock 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +34 -21
  3. data/Rakefile +20 -0
  4. data/lib/punchblock/client/component_registry.rb +2 -0
  5. data/lib/punchblock/client.rb +2 -2
  6. data/lib/punchblock/command/accept.rb +2 -0
  7. data/lib/punchblock/command/answer.rb +2 -0
  8. data/lib/punchblock/command/dial.rb +2 -0
  9. data/lib/punchblock/command/hangup.rb +2 -0
  10. data/lib/punchblock/command/join.rb +2 -0
  11. data/lib/punchblock/command/mute.rb +2 -0
  12. data/lib/punchblock/command/redirect.rb +2 -0
  13. data/lib/punchblock/command/reject.rb +3 -1
  14. data/lib/punchblock/command/unjoin.rb +2 -0
  15. data/lib/punchblock/command/unmute.rb +2 -0
  16. data/lib/punchblock/command.rb +2 -0
  17. data/lib/punchblock/command_node.rb +2 -0
  18. data/lib/punchblock/component/asterisk/agi/command.rb +4 -2
  19. data/lib/punchblock/component/asterisk/agi.rb +2 -0
  20. data/lib/punchblock/component/asterisk/ami/action.rb +4 -2
  21. data/lib/punchblock/component/asterisk/ami.rb +2 -0
  22. data/lib/punchblock/component/asterisk.rb +2 -0
  23. data/lib/punchblock/component/component_node.rb +2 -0
  24. data/lib/punchblock/component/input.rb +2 -0
  25. data/lib/punchblock/component/output.rb +2 -0
  26. data/lib/punchblock/component/record.rb +2 -0
  27. data/lib/punchblock/component/stop.rb +2 -0
  28. data/lib/punchblock/component.rb +2 -0
  29. data/lib/punchblock/connection/asterisk.rb +4 -1
  30. data/lib/punchblock/connection/connected.rb +2 -0
  31. data/lib/punchblock/connection/generic_connection.rb +5 -0
  32. data/lib/punchblock/connection/xmpp.rb +5 -6
  33. data/lib/punchblock/connection.rb +2 -0
  34. data/lib/punchblock/core_ext/blather/stanza/presence.rb +2 -0
  35. data/lib/punchblock/core_ext/blather/stanza.rb +2 -0
  36. data/lib/punchblock/core_ext/ruby.rb +1 -12
  37. data/lib/punchblock/disconnected_error.rb +2 -0
  38. data/lib/punchblock/event/answered.rb +2 -0
  39. data/lib/punchblock/event/asterisk/ami/event.rb +3 -1
  40. data/lib/punchblock/event/asterisk/ami.rb +2 -0
  41. data/lib/punchblock/event/asterisk.rb +2 -0
  42. data/lib/punchblock/event/complete.rb +3 -1
  43. data/lib/punchblock/event/dtmf.rb +2 -0
  44. data/lib/punchblock/event/end.rb +2 -0
  45. data/lib/punchblock/event/joined.rb +2 -0
  46. data/lib/punchblock/event/offer.rb +6 -0
  47. data/lib/punchblock/event/ringing.rb +2 -0
  48. data/lib/punchblock/event/unjoined.rb +2 -0
  49. data/lib/punchblock/event.rb +2 -0
  50. data/lib/punchblock/has_headers.rb +3 -1
  51. data/lib/punchblock/header.rb +2 -0
  52. data/lib/punchblock/key_value_pair_node.rb +2 -0
  53. data/lib/punchblock/media_container.rb +2 -0
  54. data/lib/punchblock/media_node.rb +2 -0
  55. data/lib/punchblock/protocol_error.rb +2 -0
  56. data/lib/punchblock/rayo_node.rb +4 -3
  57. data/lib/punchblock/ref.rb +2 -0
  58. data/lib/punchblock/translator/asterisk/call.rb +80 -26
  59. data/lib/punchblock/translator/asterisk/component/asterisk/agi_command.rb +3 -1
  60. data/lib/punchblock/translator/asterisk/component/asterisk/ami_action.rb +3 -1
  61. data/lib/punchblock/translator/asterisk/component/asterisk.rb +2 -0
  62. data/lib/punchblock/translator/asterisk/component/input.rb +4 -2
  63. data/lib/punchblock/translator/asterisk/component/output.rb +21 -3
  64. data/lib/punchblock/translator/asterisk/component.rb +2 -0
  65. data/lib/punchblock/translator/asterisk.rb +50 -20
  66. data/lib/punchblock/translator.rb +2 -0
  67. data/lib/punchblock/version.rb +3 -1
  68. data/lib/punchblock.rb +2 -0
  69. data/punchblock.gemspec +2 -2
  70. data/spec/capture_warnings.rb +32 -0
  71. data/spec/punchblock/client/component_registry_spec.rb +2 -0
  72. data/spec/punchblock/client_spec.rb +3 -1
  73. data/spec/punchblock/command/accept_spec.rb +3 -1
  74. data/spec/punchblock/command/answer_spec.rb +3 -1
  75. data/spec/punchblock/command/dial_spec.rb +12 -10
  76. data/spec/punchblock/command/hangup_spec.rb +3 -1
  77. data/spec/punchblock/command/join_spec.rb +11 -9
  78. data/spec/punchblock/command/mute_spec.rb +3 -1
  79. data/spec/punchblock/command/redirect_spec.rb +5 -3
  80. data/spec/punchblock/command/reject_spec.rb +7 -5
  81. data/spec/punchblock/command/unjoin_spec.rb +7 -5
  82. data/spec/punchblock/command/unmute_spec.rb +3 -1
  83. data/spec/punchblock/command_node_spec.rb +9 -7
  84. data/spec/punchblock/component/asterisk/agi/command_spec.rb +21 -19
  85. data/spec/punchblock/component/asterisk/ami/action_spec.rb +19 -17
  86. data/spec/punchblock/component/component_node_spec.rb +5 -3
  87. data/spec/punchblock/component/input_spec.rb +51 -49
  88. data/spec/punchblock/component/output_spec.rb +60 -58
  89. data/spec/punchblock/component/record_spec.rb +36 -34
  90. data/spec/punchblock/connection/asterisk_spec.rb +9 -4
  91. data/spec/punchblock/connection/xmpp_spec.rb +40 -39
  92. data/spec/punchblock/event/answered_spec.rb +4 -2
  93. data/spec/punchblock/event/asterisk/ami/event_spec.rb +9 -7
  94. data/spec/punchblock/event/complete_spec.rb +12 -10
  95. data/spec/punchblock/event/dtmf_spec.rb +6 -4
  96. data/spec/punchblock/event/end_spec.rb +6 -4
  97. data/spec/punchblock/event/joined_spec.rb +8 -6
  98. data/spec/punchblock/event/offer_spec.rb +7 -5
  99. data/spec/punchblock/event/ringing_spec.rb +4 -2
  100. data/spec/punchblock/event/unjoined_spec.rb +8 -6
  101. data/spec/punchblock/header_spec.rb +13 -11
  102. data/spec/punchblock/protocol_error_spec.rb +8 -6
  103. data/spec/punchblock/ref_spec.rb +5 -3
  104. data/spec/punchblock/translator/asterisk/call_spec.rb +261 -14
  105. data/spec/punchblock/translator/asterisk/component/asterisk/agi_command_spec.rb +13 -11
  106. data/spec/punchblock/translator/asterisk/component/asterisk/ami_action_spec.rb +4 -2
  107. data/spec/punchblock/translator/asterisk/component/input_spec.rb +10 -8
  108. data/spec/punchblock/translator/asterisk/component/output_spec.rb +111 -20
  109. data/spec/punchblock/translator/asterisk/component_spec.rb +3 -1
  110. data/spec/punchblock/translator/asterisk_spec.rb +107 -10
  111. data/spec/spec_helper.rb +23 -17
  112. data/spec/support/mock_connection_with_event_handler.rb +2 -0
  113. metadata +43 -41
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Punchblock
@@ -8,32 +10,32 @@ module Punchblock
8
10
  let(:component_id) { 'abc123' }
9
11
  subject { ProtocolError.new name, text, call_id, component_id }
10
12
 
11
- its(:inspect) { should == '#<Punchblock::ProtocolError: name=:item_not_found text="Could not find call [id=f6d437f4-1e18-457b-99f8-b5d853f50347]" call_id="f6d437f4-1e18-457b-99f8-b5d853f50347" component_id="abc123">' }
13
+ its(:inspect) { should be == '#<Punchblock::ProtocolError: name=:item_not_found text="Could not find call [id=f6d437f4-1e18-457b-99f8-b5d853f50347]" call_id="f6d437f4-1e18-457b-99f8-b5d853f50347" component_id="abc123">' }
12
14
 
13
15
  describe "comparison" do
14
16
  context "with the same name, text, call ID and component ID" do
15
17
  let(:comparison) { ProtocolError.new name, text, call_id, component_id }
16
- it { should == comparison }
18
+ it { should be == comparison }
17
19
  end
18
20
 
19
21
  context "with a different name" do
20
22
  let(:comparison) { ProtocolError.new :foo, text, call_id, component_id }
21
- it { should_not == comparison }
23
+ it { should_not be == comparison }
22
24
  end
23
25
 
24
26
  context "with a different text" do
25
27
  let(:comparison) { ProtocolError.new name, 'foo', call_id, component_id }
26
- it { should_not == comparison }
28
+ it { should_not be == comparison }
27
29
  end
28
30
 
29
31
  context "with a different call ID" do
30
32
  let(:comparison) { ProtocolError.new name, text, 'foo', component_id }
31
- it { should_not == comparison }
33
+ it { should_not be == comparison }
32
34
  end
33
35
 
34
36
  context "with a different component ID" do
35
37
  let(:comparison) { ProtocolError.new name, text, call_id, 'foo' }
36
- it { should_not == comparison }
38
+ it { should_not be == comparison }
37
39
  end
38
40
  end
39
41
  end
@@ -1,9 +1,11 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Punchblock
4
6
  describe Ref do
5
7
  it 'registers itself' do
6
- RayoNode.class_from_registration(:ref, 'urn:xmpp:rayo:1').should == Ref
8
+ RayoNode.class_from_registration(:ref, 'urn:xmpp:rayo:1').should be == Ref
7
9
  end
8
10
 
9
11
  describe "from a stanza" do
@@ -15,13 +17,13 @@ module Punchblock
15
17
 
16
18
  it_should_behave_like 'event'
17
19
 
18
- its(:id) { should == 'fgh4590' }
20
+ its(:id) { should be == 'fgh4590' }
19
21
  end
20
22
 
21
23
  describe "when setting options in initializer" do
22
24
  subject { Ref.new :id => 'foo' }
23
25
 
24
- its(:id) { should == 'foo' }
26
+ its(:id) { should be == 'foo' }
25
27
  end
26
28
  end
27
29
  end # Punchblock
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Punchblock
@@ -6,7 +8,6 @@ module Punchblock
6
8
  describe Call do
7
9
  let(:channel) { 'SIP/foo' }
8
10
  let(:translator) { stub_everything 'Translator::Asterisk' }
9
- let(:env) { "agi_request%3A%20async%0Aagi_channel%3A%20SIP%2F1234-00000000%0Aagi_language%3A%20en%0Aagi_type%3A%20SIP%0Aagi_uniqueid%3A%201320835995.0%0Aagi_version%3A%201.8.4.1%0Aagi_callerid%3A%205678%0Aagi_calleridname%3A%20Jane%20Smith%0Aagi_callingpres%3A%200%0Aagi_callingani2%3A%200%0Aagi_callington%3A%200%0Aagi_callingtns%3A%200%0Aagi_dnid%3A%201000%0Aagi_rdnis%3A%20unknown%0Aagi_context%3A%20default%0Aagi_extension%3A%201000%0Aagi_priority%3A%201%0Aagi_enhanced%3A%200.0%0Aagi_accountcode%3A%20%0Aagi_threadid%3A%204366221312%0A%0A" }
10
11
  let(:agi_env) do
11
12
  {
12
13
  :agi_request => 'async',
@@ -57,12 +58,12 @@ module Punchblock
57
58
  }
58
59
  end
59
60
 
60
- subject { Call.new channel, translator, env }
61
+ subject { Call.new channel, translator, agi_env }
61
62
 
62
63
  its(:id) { should be_a String }
63
- its(:channel) { should == channel }
64
+ its(:channel) { should be == channel }
64
65
  its(:translator) { should be translator }
65
- its(:agi_env) { should == agi_env }
66
+ its(:agi_env) { should be == agi_env }
66
67
 
67
68
  describe '#shutdown' do
68
69
  it 'should terminate the actor' do
@@ -93,7 +94,7 @@ module Punchblock
93
94
 
94
95
  it 'should make the call identify as inbound' do
95
96
  subject.send_offer
96
- subject.direction.should == :inbound
97
+ subject.direction.should be == :inbound
97
98
  subject.inbound?.should be true
98
99
  subject.outbound?.should be false
99
100
  end
@@ -191,12 +192,12 @@ module Punchblock
191
192
  it 'sends the call ID as a response to the Dial' do
192
193
  subject.dial dial_command
193
194
  dial_command.response
194
- dial_command.call_id.should == subject.id
195
+ dial_command.call_id.should be == subject.id
195
196
  end
196
197
 
197
198
  it 'should make the call identify as outbound' do
198
199
  subject.dial dial_command
199
- subject.direction.should == :outbound
200
+ subject.direction.should be == :outbound
200
201
  subject.outbound?.should be true
201
202
  subject.inbound?.should be false
202
203
  end
@@ -230,10 +231,22 @@ module Punchblock
230
231
  it "should cause the actor to be terminated" do
231
232
  translator.expects(:handle_pb_event!).once
232
233
  subject.process_ami_event ami_event
233
- sleep 0.5
234
+ sleep 5.5
234
235
  subject.should_not be_alive
235
236
  end
236
237
 
238
+ context "with an undefined cause" do
239
+ let(:cause) { '0' }
240
+ let(:cause_txt) { 'Undefined' }
241
+
242
+ it 'should send an end (hangup) event to the translator' do
243
+ expected_end_event = Punchblock::Event::End.new :reason => :hangup,
244
+ :call_id => subject.id
245
+ translator.expects(:handle_pb_event!).with expected_end_event
246
+ subject.process_ami_event ami_event
247
+ end
248
+ end
249
+
237
250
  context "with a normal clearing cause" do
238
251
  let(:cause) { '16' }
239
252
  let(:cause_txt) { 'Normal Clearing' }
@@ -443,6 +456,172 @@ module Punchblock
443
456
  subject.process_ami_event ami_event
444
457
  end
445
458
  end
459
+
460
+ context 'with a BridgeExec event' do
461
+ let :ami_event do
462
+ RubyAMI::Event.new('BridgeExec').tap do |e|
463
+ e['Privilege'] = "call,all"
464
+ e['Response'] = "Success"
465
+ e['Channel1'] = "SIP/foo"
466
+ e['Channel2'] = "SIP/5678-00000000"
467
+ end
468
+ end
469
+
470
+ let(:other_channel) { 'SIP/5678-00000000' }
471
+ let(:other_call_id) { 'def567' }
472
+ let :command do
473
+ Punchblock::Command::Join.new :other_call_id => other_call_id
474
+ end
475
+
476
+ before do
477
+ subject.pending_joins[other_channel] = command
478
+ command.request!
479
+ end
480
+
481
+ it 'retrieves and sets success on the correct Join' do
482
+ subject.process_ami_event ami_event
483
+ command.response(0.5).should be == true
484
+ end
485
+ end
486
+
487
+ context 'with a Bridge event' do
488
+ let(:other_channel) { 'SIP/5678-00000000' }
489
+ let(:other_call_id) { 'def567' }
490
+ let :other_call do
491
+ Call.new other_channel, translator
492
+ end
493
+
494
+ let :ami_event do
495
+ RubyAMI::Event.new('Bridge').tap do |e|
496
+ e['Privilege'] = "call,all"
497
+ e['Bridgestate'] = state
498
+ e['Bridgetype'] = "core"
499
+ e['Channel1'] = channel
500
+ e['Channel2'] = other_channel
501
+ e['Uniqueid1'] = "1319717537.11"
502
+ e['Uniqueid2'] = "1319717537.10"
503
+ e['CallerID1'] = "1234"
504
+ e['CallerID2'] = "5678"
505
+ end
506
+ end
507
+
508
+ let :switched_ami_event do
509
+ RubyAMI::Event.new('Bridge').tap do |e|
510
+ e['Privilege'] = "call,all"
511
+ e['Bridgestate'] = state
512
+ e['Bridgetype'] = "core"
513
+ e['Channel1'] = other_channel
514
+ e['Channel2'] = channel
515
+ e['Uniqueid1'] = "1319717537.11"
516
+ e['Uniqueid2'] = "1319717537.10"
517
+ e['CallerID1'] = "1234"
518
+ e['CallerID2'] = "5678"
519
+ end
520
+ end
521
+
522
+ before do
523
+ translator.register_call other_call
524
+ translator.expects(:call_for_channel).with(other_channel).returns(other_call)
525
+ other_call.expects(:id).returns other_call_id
526
+ end
527
+
528
+ context "of state 'Link'" do
529
+ let(:state) { 'Link' }
530
+
531
+ let :expected_joined do
532
+ Punchblock::Event::Joined.new.tap do |joined|
533
+ joined.call_id = subject.id
534
+ joined.other_call_id = other_call_id
535
+ end
536
+ end
537
+
538
+ it 'sends the Joined event when the call is the first channel' do
539
+ translator.expects(:handle_pb_event!).with expected_joined
540
+ subject.process_ami_event ami_event
541
+ end
542
+
543
+ it 'sends the Joined event when the call is the second channel' do
544
+ translator.expects(:handle_pb_event!).with expected_joined
545
+ subject.process_ami_event switched_ami_event
546
+ end
547
+ end
548
+
549
+ context "of state 'Unlink'" do
550
+ let(:state) { 'Unlink' }
551
+
552
+ let :expected_unjoined do
553
+ Punchblock::Event::Unjoined.new.tap do |joined|
554
+ joined.call_id = subject.id
555
+ joined.other_call_id = other_call_id
556
+ end
557
+ end
558
+
559
+ it 'sends the Unjoined event when the call is the first channel' do
560
+ translator.expects(:handle_pb_event!).with expected_unjoined
561
+ subject.process_ami_event ami_event
562
+ end
563
+
564
+ it 'sends the Unjoined event when the call is the second channel' do
565
+ translator.expects(:handle_pb_event!).with expected_unjoined
566
+ subject.process_ami_event switched_ami_event
567
+ end
568
+ end
569
+ end
570
+
571
+ context 'with an Unlink event' do
572
+ let(:other_channel) { 'SIP/5678-00000000' }
573
+ let(:other_call_id) { 'def567' }
574
+ let :other_call do
575
+ Call.new other_channel, translator
576
+ end
577
+
578
+ let :ami_event do
579
+ RubyAMI::Event.new('Unlink').tap do |e|
580
+ e['Privilege'] = "call,all"
581
+ e['Channel1'] = channel
582
+ e['Channel2'] = other_channel
583
+ e['Uniqueid1'] = "1319717537.11"
584
+ e['Uniqueid2'] = "1319717537.10"
585
+ e['CallerID1'] = "1234"
586
+ e['CallerID2'] = "5678"
587
+ end
588
+ end
589
+
590
+ let :switched_ami_event do
591
+ RubyAMI::Event.new('Unlink').tap do |e|
592
+ e['Privilege'] = "call,all"
593
+ e['Channel1'] = other_channel
594
+ e['Channel2'] = channel
595
+ e['Uniqueid1'] = "1319717537.11"
596
+ e['Uniqueid2'] = "1319717537.10"
597
+ e['CallerID1'] = "1234"
598
+ e['CallerID2'] = "5678"
599
+ end
600
+ end
601
+
602
+ before do
603
+ translator.register_call other_call
604
+ translator.expects(:call_for_channel).with(other_channel).returns(other_call)
605
+ other_call.expects(:id).returns other_call_id
606
+ end
607
+
608
+ let :expected_unjoined do
609
+ Punchblock::Event::Unjoined.new.tap do |joined|
610
+ joined.call_id = subject.id
611
+ joined.other_call_id = other_call_id
612
+ end
613
+ end
614
+
615
+ it 'sends the Unjoined event when the call is the first channel' do
616
+ translator.expects(:handle_pb_event!).with expected_unjoined
617
+ subject.process_ami_event ami_event
618
+ end
619
+
620
+ it 'sends the Unjoined event when the call is the second channel' do
621
+ translator.expects(:handle_pb_event!).with expected_unjoined
622
+ subject.process_ami_event switched_ami_event
623
+ end
624
+ end
446
625
  end
447
626
 
448
627
  describe '#execute_command' do
@@ -465,7 +644,7 @@ module Punchblock
465
644
  component = subject.execute_command command
466
645
  component.internal.should be_true
467
646
  agi_command = subject.wrapped_object.instance_variable_get(:'@current_agi_command')
468
- agi_command.name.should == "EXEC RINGING"
647
+ agi_command.name.should be == "EXEC RINGING"
469
648
  agi_command.execute!
470
649
  agi_command.add_event expected_agi_complete_event
471
650
  command.response(0.5).should be true
@@ -479,7 +658,7 @@ module Punchblock
479
658
  component = subject.execute_command command
480
659
  component.internal.should be_true
481
660
  agi_command = subject.wrapped_object.instance_variable_get(:'@current_agi_command')
482
- agi_command.name.should == "EXEC ANSWER"
661
+ agi_command.name.should be == "EXEC ANSWER"
483
662
  agi_command.execute!
484
663
  agi_command.add_event expected_agi_complete_event
485
664
  command.response(0.5).should be true
@@ -492,7 +671,7 @@ module Punchblock
492
671
  it "should send a Hangup AMI command and set the command's response" do
493
672
  subject.execute_command command
494
673
  ami_action = subject.wrapped_object.instance_variable_get(:'@current_ami_action')
495
- ami_action.name.should == "hangup"
674
+ ami_action.name.should be == "hangup"
496
675
  ami_action << RubyAMI::Response.new
497
676
  command.response(0.5).should be true
498
677
  end
@@ -566,7 +745,7 @@ module Punchblock
566
745
  context "for an unknown component ID" do
567
746
  it 'sends an error in response to the command' do
568
747
  subject.execute_command command
569
- command.response.should == ProtocolError.new('component-not-found', "Could not find a component with ID #{component_id} for call #{subject.id}", subject.id, component_id)
748
+ command.response.should be == ProtocolError.new('component-not-found', "Could not find a component with ID #{component_id} for call #{subject.id}", subject.id, component_id)
570
749
  end
571
750
  end
572
751
  end
@@ -578,10 +757,78 @@ module Punchblock
578
757
 
579
758
  it 'sends an error in response to the command' do
580
759
  subject.execute_command command
581
- command.response.should == ProtocolError.new('command-not-acceptable', "Did not understand command for call #{subject.id}", subject.id)
760
+ command.response.should be == ProtocolError.new('command-not-acceptable', "Did not understand command for call #{subject.id}", subject.id)
582
761
  end
583
762
  end
584
- end
763
+
764
+ context "with a join command" do
765
+ let(:other_call_id) { "abc123" }
766
+ let(:other_channel) { 'SIP/bar' }
767
+ let(:other_translator) { stub_everything 'Translator::Asterisk' }
768
+
769
+ let :other_call do
770
+ Call.new other_channel, other_translator
771
+ end
772
+
773
+ let :command do
774
+ Punchblock::Command::Join.new :other_call_id => other_call_id
775
+ end
776
+
777
+ it "executes the proper dialplan Bridge application" do
778
+ translator.expects(:call_with_id).with(other_call_id).returns(other_call)
779
+ subject.execute_command command
780
+ agi_command = subject.wrapped_object.instance_variable_get(:'@current_agi_command')
781
+ agi_command.name.should be == "EXEC Bridge"
782
+ agi_command.params_array.should be == [other_channel]
783
+ end
784
+
785
+ it "adds the join to the @pending_joins hash" do
786
+ translator.expects(:call_with_id).with(other_call_id).returns(other_call)
787
+ subject.execute_command command
788
+ subject.pending_joins[other_channel].should be command
789
+ end
790
+ end
791
+
792
+ context "with an unjoin command" do
793
+ let(:other_call_id) { "abc123" }
794
+ let(:other_channel) { 'SIP/bar' }
795
+
796
+ let :other_call do
797
+ Call.new other_channel, translator
798
+ end
799
+
800
+ let :command do
801
+ Punchblock::Command::Unjoin.new :other_call_id => other_call_id
802
+ end
803
+
804
+ it "executes the unjoin through redirection" do
805
+ translator.expects(:call_with_id).with(other_call_id).returns(nil)
806
+ subject.execute_command command
807
+ ami_action = subject.wrapped_object.instance_variable_get(:'@current_ami_action')
808
+ ami_action.name.should be == "redirect"
809
+ ami_action.headers['Channel'].should be == channel
810
+ ami_action.headers['Exten'].should be == Punchblock::Translator::Asterisk::REDIRECT_EXTENSION
811
+ ami_action.headers['Priority'].should be == Punchblock::Translator::Asterisk::REDIRECT_PRIORITY
812
+ ami_action.headers['Context'].should be == Punchblock::Translator::Asterisk::REDIRECT_CONTEXT
813
+ end
814
+
815
+ it "executes the unjoin through redirection, on the subject call and the other call" do
816
+ translator.expects(:call_with_id).with(other_call_id).returns(other_call)
817
+ subject.execute_command command
818
+ ami_action = subject.wrapped_object.instance_variable_get(:'@current_ami_action')
819
+ ami_action.name.should be == "redirect"
820
+ ami_action.headers['Channel'].should be == channel
821
+ ami_action.headers['Exten'].should be == Punchblock::Translator::Asterisk::REDIRECT_EXTENSION
822
+ ami_action.headers['Priority'].should be == Punchblock::Translator::Asterisk::REDIRECT_PRIORITY
823
+ ami_action.headers['Context'].should be == Punchblock::Translator::Asterisk::REDIRECT_CONTEXT
824
+
825
+ ami_action.headers['ExtraChannel'].should be == other_channel
826
+ ami_action.headers['ExtraExten'].should be == Punchblock::Translator::Asterisk::REDIRECT_EXTENSION
827
+ ami_action.headers['ExtraPriority'].should be == Punchblock::Translator::Asterisk::REDIRECT_PRIORITY
828
+ ami_action.headers['ExtraContext'].should be == Punchblock::Translator::Asterisk::REDIRECT_CONTEXT
829
+ end
830
+ end
831
+ end#execute_command
585
832
 
586
833
  describe '#send_agi_action' do
587
834
  it 'should send an appropriate AsyncAGI AMI action' do
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Punchblock
@@ -118,8 +120,8 @@ module Punchblock
118
120
 
119
121
  complete_event = command.complete_event 0.5
120
122
 
121
- complete_event.component_id.should == component_id.to_s
122
- complete_event.reason.should == expected_complete_reason
123
+ complete_event.component_id.should be == component_id.to_s
124
+ complete_event.reason.should be == expected_complete_reason
123
125
  end
124
126
  end
125
127
  end
@@ -130,9 +132,9 @@ module Punchblock
130
132
 
131
133
  it 'should provide the code and result' do
132
134
  code, result, data = subject.parse_agi_result result_string
133
- code.should == 200
134
- result.should == 123
135
- data.should == ''
135
+ code.should be == 200
136
+ result.should be == 123
137
+ data.should be == ''
136
138
  end
137
139
  end
138
140
 
@@ -141,9 +143,9 @@ module Punchblock
141
143
 
142
144
  it 'should provide the code and result' do
143
145
  code, result, data = subject.parse_agi_result result_string
144
- code.should == 200
145
- result.should == -123
146
- data.should == 'timeout'
146
+ code.should be == 200
147
+ result.should be == -123
148
+ data.should be == 'timeout'
147
149
  end
148
150
  end
149
151
 
@@ -152,9 +154,9 @@ module Punchblock
152
154
 
153
155
  it 'should provide the code and result' do
154
156
  code, result, data = subject.parse_agi_result result_string
155
- code.should == 200
156
- result.should == 123
157
- data.should == 'foo=bar'
157
+ code.should be == 200
158
+ result.should be == 123
159
+ data.should be == 'foo=bar'
158
160
  end
159
161
  end
160
162
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Punchblock
@@ -122,14 +124,14 @@ module Punchblock
122
124
  action << event
123
125
  subject.handle_response response
124
126
  action << terminating_event
125
- @event.should == event_node
127
+ @event.should be == event_node
126
128
  end
127
129
 
128
130
  it 'should send a complete event to the component node' do
129
131
  subject.action << response
130
132
  subject.action << terminating_event
131
133
 
132
- command.complete_event(0.5).reason.should == expected_complete_reason
134
+ command.complete_event(0.5).reason.should be == expected_complete_reason
133
135
  end
134
136
  end
135
137
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Punchblock
@@ -98,7 +100,7 @@ module Punchblock
98
100
  end
99
101
 
100
102
  it "should send a success complete event with the relevant data" do
101
- reason.should == expected_event
103
+ reason.should be == expected_event
102
104
  end
103
105
  end
104
106
 
@@ -114,7 +116,7 @@ module Punchblock
114
116
  end
115
117
 
116
118
  it "should send a nomatch complete event" do
117
- reason.should == expected_event
119
+ reason.should be == expected_event
118
120
  end
119
121
  end
120
122
  end
@@ -125,7 +127,7 @@ module Punchblock
125
127
  it "should return an error and not execute any actions" do
126
128
  subject.execute
127
129
  error = ProtocolError.new 'option error', 'A grammar document is required.'
128
- command.response(0.1).should == error
130
+ command.response(0.1).should be == error
129
131
  end
130
132
  end
131
133
  end
@@ -136,7 +138,7 @@ module Punchblock
136
138
  it "should return an error and not execute any actions" do
137
139
  subject.execute
138
140
  error = ProtocolError.new 'option error', 'A mode value other than DTMF is unsupported on Asterisk.'
139
- command.response(0.1).should == error
141
+ command.response(0.1).should be == error
140
142
  end
141
143
  end
142
144
 
@@ -145,7 +147,7 @@ module Punchblock
145
147
  it "should return an error and not execute any actions" do
146
148
  subject.execute
147
149
  error = ProtocolError.new 'option error', 'A mode value other than DTMF is unsupported on Asterisk.'
148
- command.response(0.1).should == error
150
+ command.response(0.1).should be == error
149
151
  end
150
152
  end
151
153
 
@@ -154,7 +156,7 @@ module Punchblock
154
156
  it "should return an error and not execute any actions" do
155
157
  subject.execute
156
158
  error = ProtocolError.new 'option error', 'A mode value other than DTMF is unsupported on Asterisk.'
157
- command.response(0.1).should == error
159
+ command.response(0.1).should be == error
158
160
  end
159
161
  end
160
162
  end
@@ -212,7 +214,7 @@ module Punchblock
212
214
  it "should return an error and not execute any actions" do
213
215
  subject.execute
214
216
  error = ProtocolError.new 'option error', 'An initial timeout value that is negative (and not -1) is invalid.'
215
- command.response(0.1).should == error
217
+ command.response(0.1).should be == error
216
218
  end
217
219
  end
218
220
  end
@@ -264,7 +266,7 @@ module Punchblock
264
266
  it "should return an error and not execute any actions" do
265
267
  subject.execute
266
268
  error = ProtocolError.new 'option error', 'An inter-digit timeout value that is negative (and not -1) is invalid.'
267
- command.response(0.1).should == error
269
+ command.response(0.1).should be == error
268
270
  end
269
271
  end
270
272
  end