spec/punchblock/translator/asterisk_spec.rb in punchblock-1.8.0 vs spec/punchblock/translator/asterisk_spec.rb in punchblock-1.8.1
- old
+ new
@@ -30,11 +30,11 @@
end
describe '#shutdown' do
it "instructs all calls to shutdown" do
call = Asterisk::Call.new 'foo', subject
- call.should_receive(:shutdown!).once
+ call.async.should_receive(:shutdown).once
subject.register_call call
subject.shutdown
end
it "terminates the actor" do
@@ -145,11 +145,11 @@
call.stub(:id).and_return call_id
subject.register_call call
end
it 'sends the command to the call for execution' do
- call.should_receive(:execute_command!).once.with command
+ call.async.should_receive(:execute_command).once.with command
subject.execute_call_command command
end
end
let :end_error_event do
@@ -233,14 +233,15 @@
end
end
end
describe '#execute_component_command' do
- let(:component_id) { '123abc' }
- let(:component) { mock 'Translator::Asterisk::Component', :id => component_id }
+ let(:call) { Translator::Asterisk::Call.new 'SIP/foo', subject }
+ let(:component_node) { Component::Output.new }
+ let(:component) { Translator::Asterisk::Component::Output.new(component_node, call) }
- let(:command) { Component::Stop.new.tap { |c| c.component_id = component_id } }
+ let(:command) { Component::Stop.new.tap { |c| c.component_id = component.id } }
before do
command.request!
end
@@ -248,19 +249,19 @@
before do
subject.register_component component
end
it 'sends the command to the component for execution' do
- component.should_receive(:execute_command!).once.with command
+ component.async.should_receive(:execute_command).once.with command
subject.execute_component_command command
end
end
context "with an unknown component ID" do
it 'sends an error in response to the command' do
subject.execute_component_command command
- command.response.should be == ProtocolError.new.setup(:item_not_found, "Could not find a component with ID #{component_id}", nil, component_id)
+ command.response.should be == ProtocolError.new.setup(:item_not_found, "Could not find a component with ID #{component.id}", nil, component.id)
end
end
end
describe '#execute_global_command' do
@@ -281,11 +282,11 @@
end
it 'should instruct the call to send a dial' do
mock_call = stub('Asterisk::Call').as_null_object
Asterisk::Call.should_receive(:new_link).once.and_return mock_call
- mock_call.should_receive(:dial!).once.with command
+ mock_call.async.should_receive(:dial).once.with command
subject.execute_global_command command
end
end
context 'with an AMI action' do
@@ -295,11 +296,11 @@
let(:mock_action) { stub('Asterisk::Component::Asterisk::AMIAction').as_null_object }
it 'should create a component actor and execute it asynchronously' do
Asterisk::Component::Asterisk::AMIAction.should_receive(:new).once.with(command, subject).and_return mock_action
- mock_action.should_receive(:execute!).once
+ mock_action.async.should_receive(:execute).once
subject.execute_global_command command
end
it 'registers the component' do
Asterisk::Component::Asterisk::AMIAction.should_receive(:new).once.with(command, subject).and_return mock_action
@@ -420,11 +421,11 @@
it 'should instruct the call to send an offer' do
mock_call = stub('Asterisk::Call').as_null_object
Asterisk::Call.should_receive(:new).once.and_return mock_call
subject.wrapped_object.should_receive(:link)
- mock_call.should_receive(:send_offer!).once
+ mock_call.async.should_receive(:send_offer).once
subject.handle_ami_event ami_event
end
context 'if a call already exists for a matching channel' do
let(:call) { Asterisk::Call.new "SIP/1234-00000000", subject }
@@ -552,11 +553,11 @@
before do
subject.register_call call
end
it 'sends the AMI event to the call and to the connection as a PB event' do
- call.should_receive(:process_ami_event!).once.with ami_event
+ call.async.should_receive(:process_ami_event).once.with ami_event
subject.handle_ami_event ami_event
end
context 'with a Channel1 and Channel2 specified on the event' do
let :ami_event do
@@ -574,12 +575,12 @@
end
before { subject.register_call call2 }
it 'should send the event to both calls and to the connection once as a PB event' do
- call.should_receive(:process_ami_event!).once.with ami_event
- call2.should_receive(:process_ami_event!).once.with ami_event
+ call.async.should_receive(:process_ami_event).once.with ami_event
+ call2.async.should_receive(:process_ami_event).once.with ami_event
subject.handle_ami_event ami_event
end
end
end
end
@@ -610,16 +611,16 @@
before do
subject.register_call call
end
it 'sends the AMI event to the call and to the connection as a PB event if it is an allowed event' do
- call.should_receive(:process_ami_event!).once.with ami_event
+ call.async.should_receive(:process_ami_event).once.with ami_event
subject.handle_ami_event ami_event
end
it 'does not send the AMI event to a bridged channel if it is not allowed' do
- call.should_receive(:process_ami_event!).never.with ami_event2
+ call.async.should_receive(:process_ami_event).never.with ami_event2
subject.handle_ami_event ami_event2
end
end
end#handle_ami_event
@@ -630,10 +631,12 @@
subject.send_ami_action 'foo', :foo => :bar
end
end
describe '#run_at_fully_booted' do
+ let(:broken_path) { "/this/is/not/a/valid/path" }
+
let(:passed_show) do
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. =-"})
end
let(:failed_show) do
@@ -656,25 +659,24 @@
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}"
ami_client.should_receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}").and_yield(failed_show)
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.")
subject.run_at_fully_booted
end
+
+ it 'should check the recording directory for existence' do
+ stub_const('Punchblock::Translator::Asterisk::Component::Record::RECORDING_BASE_PATH', broken_path)
+ 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}"
+ ami_client.should_receive(:send_action).once.with('Command', 'Command' => "dialplan show #{Asterisk::REDIRECT_CONTEXT}")
+ 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")
+ subject.run_at_fully_booted
+ end
end
describe '#check_recording_directory' do
let(:broken_path) { "/this/is/not/a/valid/path" }
- before do
- @new_constant = broken_path
- @old_constant = Punchblock::Translator::Asterisk::Component::Record::RECORDING_BASE_PATH
- Punchblock::Translator::Asterisk::Component::Record.__send__(:remove_const,'RECORDING_BASE_PATH')
- Punchblock::Translator::Asterisk::Component::Record.const_set('RECORDING_BASE_PATH', @new_constant)
- end
- after do
- Punchblock::Translator::Asterisk::Component::Record.__send__(:remove_const,'RECORDING_BASE_PATH')
- Punchblock::Translator::Asterisk::Component::Record.const_set('RECORDING_BASE_PATH', @old_constant)
- end
it 'logs a warning if the recording directory does not exist' do
- 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")
+ stub_const('Punchblock::Translator::Asterisk::Component::Record::RECORDING_BASE_PATH', broken_path)
+ 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")
subject.check_recording_directory
end
end
end
end