spec/punchblock/translator/asterisk/call_spec.rb in punchblock-0.6.2 vs spec/punchblock/translator/asterisk/call_spec.rb in punchblock-0.7.0

- old
+ new

@@ -110,18 +110,16 @@ let :component do Component::Asterisk::AGICommand.new mock_component_node, subject.translator end let(:ami_event) do - RubyAMI::Event.new("AGIExec").tap do |e| + RubyAMI::Event.new("AsyncAGI").tap do |e| e["SubEvent"] = "End" e["Channel"] = "SIP/1234-00000000" - e["CommandId"] = component.id + e["CommandID"] = component.id e["Command"] = "EXEC ANSWER" - e["ResultCode"] = "200" - e["Result"] = "Success" - e["Data"] = "FOO" + e["Result"] = "200%20result=123%20(timeout)%0A" end end before do subject.register_component component @@ -150,11 +148,11 @@ context 'with an accept command' do let(:command) { Command::Accept.new } it "should send an EXEC RINGING AGI command and set the command's response" do subject.execute_command command - agi_command = subject.actor_subject.instance_variable_get(:'@current_agi_command') + agi_command = subject.wrapped_object.instance_variable_get(:'@current_agi_command') agi_command.name.should == "EXEC RINGING" agi_command.execute! agi_command.add_event expected_agi_complete_event command.response(0.5).should be true end @@ -163,11 +161,11 @@ context 'with an answer command' do let(:command) { Command::Answer.new } it "should send an EXEC ANSWER AGI command and set the command's response" do subject.execute_command command - agi_command = subject.actor_subject.instance_variable_get(:'@current_agi_command') + agi_command = subject.wrapped_object.instance_variable_get(:'@current_agi_command') agi_command.name.should == "EXEC ANSWER" agi_command.execute! agi_command.add_event expected_agi_complete_event command.response(0.5).should be true end @@ -176,11 +174,11 @@ context 'with a hangup command' do let(:command) { Command::Hangup.new } it "should send a Hangup AMI command and set the command's response" do subject.execute_command command - ami_action = subject.actor_subject.instance_variable_get(:'@current_ami_action') + ami_action = subject.wrapped_object.instance_variable_get(:'@current_ami_action') ami_action.name.should == "hangup" ami_action << RubyAMI::Response.new command.response(0.5).should be true end end @@ -196,15 +194,34 @@ Component::Asterisk::AGICommand.expects(:new).once.with(command, subject).returns mock_action 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 + end + + let :mock_component do + mock 'Component', :id => component_id + end + + before { subject.register_component mock_component } + + it 'should send the command to the component for execution' do + mock_component.expects(:execute_command!).once + subject.execute_command command + end + end end describe '#send_agi_action' do it 'should send an appropriate AsyncAGI AMI action' do pending - subject.actor_subject.expects(:send_ami_action).once.with('AGI', 'Command' => 'FOO', 'Channel' => subject.channel) + subject.wrapped_object.expects(:send_ami_action).once.with('AGI', 'Command' => 'FOO', 'Channel' => subject.channel) subject.send_agi_action 'FOO' end end describe '#send_ami_action' do