spec/punchblock/translator/asterisk/call_spec.rb in punchblock-1.1.0 vs spec/punchblock/translator/asterisk/call_spec.rb in punchblock-1.2.0

- old
+ new

@@ -233,10 +233,25 @@ subject.process_ami_event ami_event sleep 5.5 subject.should_not be_alive end + it "should cause all components to send complete events before sending end event" do + subject.expects :answer_if_not_answered + comp_command = Punchblock::Component::Input.new :grammar => {:value => '<grammar/>'}, :mode => :dtmf + comp_command.request! + component = subject.execute_command comp_command + comp_command.response(0.1).should be_a Ref + expected_complete_event = Punchblock::Event::Complete.new :target_call_id => subject.id, :component_id => component.id + expected_complete_event.reason = Punchblock::Event::Complete::Hangup.new + expected_end_event = Punchblock::Event::End.new :reason => :hangup, :target_call_id => subject.id + end_sequence = sequence 'end events' + translator.expects(:handle_pb_event!).with(expected_complete_event).once.in_sequence(end_sequence) + translator.expects(:handle_pb_event!).with(expected_end_event).once.in_sequence(end_sequence) + subject.process_ami_event ami_event + end + context "with an undefined cause" do let(:cause) { '0' } let(:cause_txt) { 'Undefined' } it 'should send an end (hangup) event to the translator' do @@ -734,11 +749,11 @@ Punchblock::Component::Output.new end let(:mock_action) { mock 'Component::Asterisk::Output', :id => 'foo' } - it 'should create an AGI command component actor and execute it asynchronously' do + it 'should create an Output component and execute it asynchronously' do Component::Output.expects(:new).once.with(command, subject).returns mock_action mock_action.expects(:internal=).never mock_action.expects(:execute!).once subject.execute_command command end @@ -749,18 +764,33 @@ Punchblock::Component::Input.new end let(:mock_action) { mock 'Component::Asterisk::Input', :id => 'foo' } - it 'should create an AGI command component actor and execute it asynchronously' do + it 'should create an Input component and execute it asynchronously' do Component::Input.expects(:new).once.with(command, subject).returns mock_action mock_action.expects(:internal=).never mock_action.expects(:execute!).once subject.execute_command command end end + context 'with a Record component' do + let :command do + Punchblock::Component::Record.new + end + + let(:mock_action) { mock 'Component::Asterisk::Record', :id => 'foo' } + + it 'should create a Record component and execute it asynchronously' do + Component::Record.expects(:new).once.with(command, subject).returns mock_action + mock_action.expects(:internal=).never + mock_action.expects(:execute!).once + subject.execute_command command + end + end + context 'with a component command' do let(:component_id) { 'foobar' } let :command do Punchblock::Component::Stop.new :component_id => component_id @@ -787,10 +817,10 @@ end end context 'with a command we do not understand' do let :command do - Punchblock::Component::Record.new + Punchblock::Command::Mute.new end it 'sends an error in response to the command' do subject.execute_command command command.response.should be == ProtocolError.new.setup('command-not-acceptable', "Did not understand command for call #{subject.id}", subject.id)