adhearsion-asterisk 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a687c0732e8408239c867b8480924c6206084bf4
4
+ data.tar.gz: 3baa0d3876880a58b2ad5376af3d2614cb47a418
5
+ SHA512:
6
+ metadata.gz: d8dff1e952c3ae79c2c71713b98b4bf9cebfad82a5e917cf5d0491983051157b8e8ac96b7acbcda8a73030a322fbfe401cce664b13773c68846dfb4a17ba9c8f
7
+ data.tar.gz: fba213383d1700cdd1915a44d3c6649ef6f441b35e48087924d224da7a3c446aa4367200ae644c3a98c64bccda5a767cd6a756b22d1b0826b682f2b8638c8302
data/.gitignore CHANGED
@@ -8,3 +8,4 @@ coverage
8
8
  vendor/bundle
9
9
  tags
10
10
  .rbenv-version
11
+ tmp
@@ -1,5 +1,8 @@
1
1
  # develop
2
2
 
3
+ # v1.4.0
4
+ * Feature: Add `#goto`, which will pass a call to another context/extension/priority and disconnect from Adhearsion
5
+
3
6
  # v1.3.1
4
7
  * Bugfix: Fixed `#execute` to concatenate multiple arguments correctly
5
8
 
@@ -19,19 +19,16 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_runtime_dependency %q<adhearsion>, ["~> 2.0"]
22
- s.add_runtime_dependency %q<activesupport>, [">= 3.0.10"]
22
+ s.add_runtime_dependency %q<activesupport>, ["~> 3.0"]
23
23
  s.add_runtime_dependency %q<jruby-openssl> if RUBY_PLATFORM == 'java'
24
24
 
25
- s.add_development_dependency %q<bundler>, [">= 1.0.0"]
26
- s.add_development_dependency %q<rspec>, [">= 2.5.0"]
27
- s.add_development_dependency %q<ci_reporter>, [">= 1.6.3"]
25
+ s.add_development_dependency %q<bundler>, ["~> 1.0"]
26
+ s.add_development_dependency %q<rspec>, ["~> 2.5"]
27
+ s.add_development_dependency %q<ci_reporter>, ["~> 1.6"]
28
28
  s.add_development_dependency %q<simplecov>, [">= 0"]
29
29
  s.add_development_dependency %q<simplecov-rcov>, [">= 0"]
30
- s.add_development_dependency %q<yard>, [">= 0.6.0"]
30
+ s.add_development_dependency %q<yard>, ["~> 0.6"]
31
31
  s.add_development_dependency %q<rake>, [">= 0"]
32
- s.add_development_dependency %q<mocha>, [">= 0"]
33
- s.add_development_dependency %q<bones>
34
32
  s.add_development_dependency %q<guard-rspec>
35
33
  s.add_development_dependency %q<ruby_gntp>
36
- s.add_development_dependency %q<thor>, ["~> 0.14.0"]
37
34
  end
@@ -412,6 +412,19 @@ module Adhearsion
412
412
  GenerateSilenceProxy.proxy_for(self, &block) if block_given?
413
413
  end
414
414
 
415
+ #
416
+ # Go to a specified context, extension and priority
417
+ # This requires us to relinquish control of the call.
418
+ # Execution will continue until the user hangs up, but the channel will be no longer available
419
+ #
420
+ def goto(context, extension = :nothing, priority = :nothing)
421
+ call[:ahn_prevent_hangup] = true
422
+ args = ['Goto', context, extension, priority].reject { |v| v == :nothing }
423
+ execute *args
424
+ set_variable 'PUNCHBLOCK_END_ON_ASYNCAGI_BREAK', 'true'
425
+ agi "ASYNCAGI BREAK"
426
+ end
427
+
415
428
  class GenerateSilenceProxy
416
429
  def self.proxy_for(target, &block)
417
430
  proxy = new(target)
@@ -1,5 +1,5 @@
1
1
  module Adhearsion
2
2
  module Asterisk
3
- VERSION = "1.3.1"
3
+ VERSION = "1.4.0"
4
4
  end
5
5
  end
@@ -4,7 +4,9 @@ module Adhearsion::Asterisk
4
4
  describe CallControllerMethods do
5
5
  describe "mixed in to a CallController" do
6
6
 
7
- subject { Adhearsion::CallController.new mock('Call') }
7
+ let(:call) { mock('Call') }
8
+
9
+ subject { Adhearsion::CallController.new call }
8
10
 
9
11
  before { Adhearsion::CallController.mixin CallControllerMethods }
10
12
 
@@ -19,10 +21,10 @@ module Adhearsion::Asterisk
19
21
  end
20
22
  end
21
23
 
22
- before { Punchblock::Component::Asterisk::AGI::Command.any_instance.stubs :complete_event => complete_event }
24
+ before { Punchblock::Component::Asterisk::AGI::Command.any_instance.stub :complete_event => complete_event }
23
25
 
24
26
  it 'should execute an AGI command with the specified name and parameters and return the response code, response and data' do
25
- subject.expects(:execute_component_and_await_completion).once.with expected_agi_command
27
+ subject.should_receive(:execute_component_and_await_completion).once.with expected_agi_command
26
28
  values = subject.agi 'Dial', '4044754842', 15
27
29
  values.should == [200, 1, 'foobar']
28
30
  end
@@ -35,7 +37,7 @@ module Adhearsion::Asterisk
35
37
  end
36
38
 
37
39
  it 'should raise Adhearsion::Call::Hangup' do
38
- subject.expects(:execute_component_and_await_completion).once.with expected_agi_command
40
+ subject.should_receive(:execute_component_and_await_completion).once.with expected_agi_command
39
41
  lambda { subject.agi 'Dial', '4044754842', 15 }.should raise_error(Adhearsion::Call::Hangup)
40
42
  end
41
43
  end
@@ -43,21 +45,21 @@ module Adhearsion::Asterisk
43
45
 
44
46
  describe '#execute' do
45
47
  it 'calls #agi and prefixes the command with EXEC' do
46
- subject.expects(:agi).once.with 'EXEC Dial', '4044754842,15'
48
+ subject.should_receive(:agi).once.with 'EXEC Dial', '4044754842,15'
47
49
  subject.execute 'Dial', '4044754842', 15
48
50
  end
49
51
  end
50
52
 
51
53
  describe '#verbose' do
52
54
  it 'executes the VERBOSE AGI command' do
53
- subject.expects(:agi).once.with 'VERBOSE', 'Foo Bar!', 15
55
+ subject.should_receive(:agi).once.with 'VERBOSE', 'Foo Bar!', 15
54
56
  subject.verbose 'Foo Bar!', 15
55
57
  end
56
58
  end
57
59
 
58
60
  describe '#enable_feature' do
59
61
  it 'it should fetch the variable for DYNAMIC_FEATURES at first' do
60
- subject.expects(:variable).once.with("DYNAMIC_FEATURES").throws(:got_variable)
62
+ subject.should_receive(:variable).once.with("DYNAMIC_FEATURES").and_throw(:got_variable)
61
63
  expect {
62
64
  subject.enable_feature :foobar
63
65
  }.to throw_symbol :got_variable
@@ -73,13 +75,13 @@ module Adhearsion::Asterisk
73
75
 
74
76
  # I had to do this ugly hack because of a bug in Flexmock which prevented me from mocking out Hash#[] :(
75
77
  # FIXME: mock Hash
76
- # ...DYNAMIC_FEATURE_EXTENSIONS.expects(feature_name => assertion)
78
+ # ...DYNAMIC_FEATURE_EXTENSIONS.should_receive(feature_name => assertion)
77
79
 
78
80
  old_hash_feature_extension = Adhearsion::Asterisk::CallControllerMethods::DYNAMIC_FEATURE_EXTENSIONS[feature_name]
79
81
  begin
80
82
  Adhearsion::Asterisk::CallControllerMethods::DYNAMIC_FEATURE_EXTENSIONS[feature_name] = assertion
81
83
 
82
- subject.expects(:enable_feature).once.with(feature_name, :this_is_the_right_arg).throws :inside_assertion!
84
+ subject.should_receive(:enable_feature).once.with(feature_name, :this_is_the_right_arg).and_throw :inside_assertion!
83
85
  expect { subject.enable_feature(feature_name, :this_is_the_right_arg)}.to throw_symbol :inside_assertion!
84
86
  ensure
85
87
  Adhearsion::Asterisk::CallControllerMethods::DYNAMIC_FEATURE_EXTENSIONS[feature_name] = old_hash_feature_extension
@@ -87,13 +89,13 @@ module Adhearsion::Asterisk
87
89
  end
88
90
 
89
91
  it 'should separate enabled features with a "#"' do
90
- subject.expects(:variable).once.with("DYNAMIC_FEATURES").returns("one")
91
- subject.expects(:variable).once.with("DYNAMIC_FEATURES" => 'one#bar')
92
+ subject.should_receive(:variable).once.with("DYNAMIC_FEATURES").and_return("one")
93
+ subject.should_receive(:variable).once.with("DYNAMIC_FEATURES" => 'one#bar')
92
94
  subject.enable_feature "bar"
93
95
  end
94
96
 
95
97
  it 'should not add duplicate enabled dynamic features' do
96
- subject.expects(:variable).once.returns('eins#zwei')
98
+ subject.should_receive(:variable).once.and_return('eins#zwei')
97
99
  subject.enable_feature "eins"
98
100
  end
99
101
 
@@ -104,63 +106,63 @@ module Adhearsion::Asterisk
104
106
  end
105
107
 
106
108
  it 'enabling :attended_transfer should actually enable the atxfer feature' do
107
- subject.expects(:variable).once.with("DYNAMIC_FEATURES").returns ''
108
- subject.expects(:variable).once.with("DYNAMIC_FEATURES" => 'atxfer')
109
+ subject.should_receive(:variable).once.with("DYNAMIC_FEATURES").and_return ''
110
+ subject.should_receive(:variable).once.with("DYNAMIC_FEATURES" => 'atxfer')
109
111
  subject.enable_feature :attended_transfer
110
112
  end
111
113
 
112
114
  it 'the :context optional option when enabling :attended_transfer should set the TRANSFER_CONTEXT variable to the String supplied as a Hash value' do
113
115
  context_name = "direct_dial"
114
- subject.expects(:variable).once.with("DYNAMIC_FEATURES").returns ''
115
- subject.expects(:variable).once.with("DYNAMIC_FEATURES" => 'atxfer')
116
- subject.expects(:variable).once.with("TRANSFER_CONTEXT" => context_name)
116
+ subject.should_receive(:variable).once.with("DYNAMIC_FEATURES").and_return ''
117
+ subject.should_receive(:variable).once.with("DYNAMIC_FEATURES" => 'atxfer')
118
+ subject.should_receive(:variable).once.with("TRANSFER_CONTEXT" => context_name)
117
119
  subject.enable_feature :attended_transfer, :context => context_name
118
120
  end
119
121
 
120
122
  it 'enabling :attended_transfer should not add a duplicate if atxfer has been enabled, but it should still set the TRANSFER_CONTEXT variable' do
121
123
  context_name = 'blah'
122
- subject.expects(:variable).once.with('DYNAMIC_FEATURES').returns 'atxfer'
123
- subject.expects(:variable).once.with('TRANSFER_CONTEXT' => context_name)
124
+ subject.should_receive(:variable).once.with('DYNAMIC_FEATURES').and_return 'atxfer'
125
+ subject.should_receive(:variable).once.with('TRANSFER_CONTEXT' => context_name)
124
126
  subject.enable_feature :attended_transfer, :context => context_name
125
127
  end
126
128
  end
127
129
 
128
130
  describe '#disable_feature' do
129
131
  it "should properly remove the feature from the DYNAMIC_FEATURES variable" do
130
- subject.expects(:variable).once.with('DYNAMIC_FEATURES').returns 'foobar#qaz'
131
- subject.expects(:variable).once.with('DYNAMIC_FEATURES' => 'qaz')
132
+ subject.should_receive(:variable).once.with('DYNAMIC_FEATURES').and_return 'foobar#qaz'
133
+ subject.should_receive(:variable).once.with('DYNAMIC_FEATURES' => 'qaz')
132
134
  subject.disable_feature "foobar"
133
135
  end
134
136
 
135
137
  it "should not re-set the variable if the feature wasn't enabled in the first place" do
136
- subject.expects(:variable).once.with('DYNAMIC_FEATURES').returns 'atxfer'
137
- subject.expects(:variable).never
138
+ subject.should_receive(:variable).once.with('DYNAMIC_FEATURES').and_return 'atxfer'
139
+ subject.should_receive(:variable).never
138
140
  subject.disable_feature "jay"
139
141
  end
140
142
  end
141
143
 
142
144
  describe "#variable" do
143
145
  it "should call set_variable when Hash argument given" do
144
- subject.expects(:set_variable).once.with :ohai, "ur_home_erly"
146
+ subject.should_receive(:set_variable).once.with :ohai, "ur_home_erly"
145
147
  subject.variable :ohai => 'ur_home_erly'
146
148
  end
147
149
 
148
150
  it "should call set_variable for every Hash-key given" do
149
151
  many_args = { :a => :b, :c => :d, :e => :f, :g => :h}
150
- subject.expects(:set_variable).times(many_args.size)
152
+ subject.should_receive(:set_variable).exactly(many_args.size).times
151
153
  subject.variable many_args
152
154
  end
153
155
 
154
156
  it "should call get_variable for every String given" do
155
157
  variables = ["foo", "bar", :qaz, :qwerty, :baz]
156
158
  variables.each do |var|
157
- subject.expects(:get_variable).once.with(var).returns("X")
159
+ subject.should_receive(:get_variable).once.with(var).and_return("X")
158
160
  end
159
161
  subject.variable(*variables).should == ["X"] * variables.size
160
162
  end
161
163
 
162
164
  it "should NOT return an Array when just one arg is given" do
163
- subject.expects(:get_variable).once.returns "lol"
165
+ subject.should_receive(:get_variable).once.and_return "lol"
164
166
  subject.variable(:foo).should_not be_a Array
165
167
  end
166
168
 
@@ -173,21 +175,21 @@ module Adhearsion::Asterisk
173
175
 
174
176
  describe "#set_variable" do
175
177
  it "uses SET VARIABLE" do
176
- subject.expects(:agi).once.with 'SET VARIABLE', 'foo', 'i can " has ruby?'
178
+ subject.should_receive(:agi).once.with 'SET VARIABLE', 'foo', 'i can " has ruby?'
177
179
  subject.set_variable 'foo', 'i can " has ruby?'
178
180
  end
179
181
  end
180
182
 
181
183
  describe '#get_variable' do
182
184
  it 'uses GET VARIABLE and extracts the value from the data' do
183
- subject.expects(:agi).once.with('GET VARIABLE', 'foo').returns [200, 1, 'bar']
185
+ subject.should_receive(:agi).once.with('GET VARIABLE', 'foo').and_return [200, 1, 'bar']
184
186
  subject.get_variable('foo').should == 'bar'
185
187
  end
186
188
  end
187
189
 
188
190
  describe "#sip_add_header" do
189
191
  it "executes SIPAddHeader" do
190
- subject.expects(:execute).once.with 'SIPAddHeader', 'x-ahn-header: rubyrox'
192
+ subject.should_receive(:execute).once.with 'SIPAddHeader', 'x-ahn-header: rubyrox'
191
193
  subject.sip_add_header "x-ahn-header", "rubyrox"
192
194
  end
193
195
  end
@@ -195,7 +197,7 @@ module Adhearsion::Asterisk
195
197
  describe "#sip_get_header" do
196
198
  it "uses #get_variable to get the header value" do
197
199
  value = 'jason-was-here'
198
- subject.expects(:get_variable).once.with('SIP_HEADER(x-ahn-header)').returns value
200
+ subject.should_receive(:get_variable).once.with('SIP_HEADER(x-ahn-header)').and_return value
199
201
  subject.sip_get_header("x-ahn-header").should == value
200
202
  end
201
203
  end
@@ -203,25 +205,25 @@ module Adhearsion::Asterisk
203
205
  describe '#join' do
204
206
  it "should pass the 'd' flag when no options are given" do
205
207
  conference_id = "123"
206
- subject.expects(:execute).once.with("MeetMe", conference_id, "d", nil)
208
+ subject.should_receive(:execute).once.with("MeetMe", conference_id, "d", nil)
207
209
  subject.meetme conference_id
208
210
  end
209
211
 
210
212
  it "should pass through any given flags with 'd' appended to it if necessary" do
211
213
  conference_id, flags = "1000", "zomgs"
212
- subject.expects(:execute).once.with("MeetMe", conference_id, flags + "d", nil)
214
+ subject.should_receive(:execute).once.with("MeetMe", conference_id, flags + "d", nil)
213
215
  subject.meetme conference_id, :options => flags
214
216
  end
215
217
 
216
218
  it "should NOT pass the 'd' flag when requiring static conferences" do
217
219
  conference_id, options = "1000", {:use_static_conf => true}
218
- subject.expects(:execute).once.with("MeetMe", conference_id, "", nil)
220
+ subject.should_receive(:execute).once.with("MeetMe", conference_id, "", nil)
219
221
  subject.meetme conference_id, options
220
222
  end
221
223
 
222
224
  it "should raise an ArgumentError when the pin is not numerical" do
223
225
  lambda {
224
- subject.expects(:execute).never
226
+ subject.should_receive(:execute).never
225
227
  subject.meetme 3333, :pin => "letters are bad, mkay?!1"
226
228
  }.should raise_error ArgumentError
227
229
  end
@@ -229,7 +231,7 @@ module Adhearsion::Asterisk
229
231
  it "should strip out illegal characters from a conference name" do
230
232
  bizarre_conference_name = "a- bc!d&&e--`"
231
233
  normal_conference_name = "abcde"
232
- subject.expects(:execute).twice.with("MeetMe", normal_conference_name, "d", nil)
234
+ subject.should_receive(:execute).twice.with("MeetMe", normal_conference_name, "d", nil)
233
235
 
234
236
  subject.meetme bizarre_conference_name
235
237
  subject.meetme normal_conference_name
@@ -237,7 +239,7 @@ module Adhearsion::Asterisk
237
239
 
238
240
  it "should allow textual conference names" do
239
241
  lambda {
240
- subject.expects(:execute).once
242
+ subject.should_receive(:execute).once
241
243
  subject.meetme "david bowie's pants"
242
244
  }.should_not raise_error
243
245
  end
@@ -245,28 +247,28 @@ module Adhearsion::Asterisk
245
247
 
246
248
  describe '#voicemail' do
247
249
  it 'should not send the context name when none is given' do
248
- subject.expects(:execute).once.with('voicemail', 123, '').throws :sent_voicemail!
250
+ subject.should_receive(:execute).once.with('voicemail', 123, '').and_throw :sent_voicemail!
249
251
  lambda { subject.voicemail 123 }.should throw_symbol(:sent_voicemail!)
250
252
  end
251
253
 
252
254
  it 'should send the context name when one is given' do
253
255
  mailbox_number, context_name = 333, 'doesntmatter'
254
- subject.expects(:execute).once.with('voicemail', "#{mailbox_number}@#{context_name}", '').throws :sent_voicemail!
256
+ subject.should_receive(:execute).once.with('voicemail', "#{mailbox_number}@#{context_name}", '').and_throw :sent_voicemail!
255
257
  lambda { subject.voicemail(context_name => mailbox_number) }.should throw_symbol(:sent_voicemail!)
256
258
  end
257
259
 
258
260
  it 'should pass in the s option if :skip => true' do
259
261
  mailbox_number = '012'
260
- subject.expects(:execute).once.with('voicemail', mailbox_number, 's').throws :sent_voicemail!
262
+ subject.should_receive(:execute).once.with('voicemail', mailbox_number, 's').and_throw :sent_voicemail!
261
263
  lambda { subject.voicemail(mailbox_number, :skip => true) }.should throw_symbol(:sent_voicemail!)
262
264
  end
263
265
 
264
266
  it 'should combine mailbox numbers with the context name given when both are given' do
265
- subject.expects(:variable).with("VMSTATUS").returns 'SUCCESS'
267
+ subject.should_receive(:variable).with("VMSTATUS").and_return 'SUCCESS'
266
268
  context = "lolcats"
267
269
  mailboxes = [1,2,3,4,5]
268
270
  mailboxes_with_context = mailboxes.map { |mailbox| [mailbox, context].join '@' }
269
- subject.expects(:execute).once.with('voicemail', mailboxes_with_context.join('&'), '')
271
+ subject.should_receive(:execute).once.with('voicemail', mailboxes_with_context.join('&'), '')
270
272
  subject.voicemail context => mailboxes
271
273
  end
272
274
 
@@ -296,13 +298,13 @@ module Adhearsion::Asterisk
296
298
 
297
299
  it 'should pass in the u option if :greeting => :unavailable' do
298
300
  mailbox_number = '776'
299
- subject.expects(:execute).once.with('voicemail', mailbox_number, 'u').throws :sent_voicemail!
301
+ subject.should_receive(:execute).once.with('voicemail', mailbox_number, 'u').and_throw :sent_voicemail!
300
302
  lambda { subject.voicemail(mailbox_number, :greeting => :unavailable) }.should throw_symbol(:sent_voicemail!)
301
303
  end
302
304
 
303
305
  it 'should pass in both the skip and greeting options if both are supplied' do
304
306
  mailbox_number = '4'
305
- subject.expects(:execute).once.with('voicemail', mailbox_number, 'u').throws :sent_voicemail!
307
+ subject.should_receive(:execute).once.with('voicemail', mailbox_number, 'u').and_throw :sent_voicemail!
306
308
  lambda { subject.voicemail(mailbox_number, :greeting => :unavailable) }.should throw_symbol(:sent_voicemail!)
307
309
  end
308
310
 
@@ -318,25 +320,25 @@ module Adhearsion::Asterisk
318
320
 
319
321
  it 'should pass in the b option if :gretting => :busy' do
320
322
  mailbox_number = '1'
321
- subject.expects(:execute).once.with('voicemail', mailbox_number, 'b').throws :sent_voicemail!
323
+ subject.should_receive(:execute).once.with('voicemail', mailbox_number, 'b').and_throw :sent_voicemail!
322
324
  lambda { subject.voicemail(mailbox_number, :greeting => :busy) }.should throw_symbol(:sent_voicemail!)
323
325
  end
324
326
 
325
327
  it 'should return true if VMSTATUS == "SUCCESS"' do
326
- subject.expects(:execute).once
327
- subject.expects(:variable).once.with('VMSTATUS').returns "SUCCESS"
328
+ subject.should_receive(:execute).once
329
+ subject.should_receive(:variable).once.with('VMSTATUS').and_return "SUCCESS"
328
330
  subject.voicemail(3).should be true
329
331
  end
330
332
 
331
333
  it 'should return false if VMSTATUS == "USEREXIT"' do
332
- subject.expects(:execute).once
333
- subject.expects(:variable).once.with('VMSTATUS').returns "USEREXIT"
334
+ subject.should_receive(:execute).once
335
+ subject.should_receive(:variable).once.with('VMSTATUS').and_return "USEREXIT"
334
336
  subject.voicemail(2).should be false
335
337
  end
336
338
 
337
339
  it 'should return nil if VMSTATUS == "FAILED"' do
338
- subject.expects(:execute).once
339
- subject.expects(:variable).once.with('VMSTATUS').returns "FAILED"
340
+ subject.should_receive(:execute).once
341
+ subject.should_receive(:variable).once.with('VMSTATUS').and_return "FAILED"
340
342
  subject.voicemail(2).should be nil
341
343
  end
342
344
  end
@@ -345,48 +347,48 @@ module Adhearsion::Asterisk
345
347
  it "the :folder Hash key argument should wrap the value in a()" do
346
348
  folder = "foobar"
347
349
  mailbox = 81
348
- subject.expects(:execute).once.with("VoiceMailMain", "#{mailbox}","a(#{folder})")
350
+ subject.should_receive(:execute).once.with("VoiceMailMain", "#{mailbox}","a(#{folder})")
349
351
  subject.voicemail_main :mailbox => mailbox, :folder => folder
350
352
  end
351
353
 
352
354
  it ':authenticate should pass in the "s" option if given false' do
353
355
  mailbox = 333
354
- subject.expects(:execute).once.with("VoiceMailMain", "#{mailbox}","s")
356
+ subject.should_receive(:execute).once.with("VoiceMailMain", "#{mailbox}","s")
355
357
  subject.voicemail_main :mailbox => mailbox, :authenticate => false
356
358
  end
357
359
 
358
360
  it ':authenticate should pass in the s option if given false' do
359
361
  mailbox = 55
360
- subject.expects(:execute).once.with("VoiceMailMain", "#{mailbox}")
362
+ subject.should_receive(:execute).once.with("VoiceMailMain", "#{mailbox}")
361
363
  subject.voicemail_main :mailbox => mailbox, :authenticate => true
362
364
  end
363
365
 
364
366
  it 'should not pass any flags only a mailbox is given' do
365
367
  mailbox = "1"
366
- subject.expects(:execute).once.with("VoiceMailMain", "#{mailbox}")
368
+ subject.should_receive(:execute).once.with("VoiceMailMain", "#{mailbox}")
367
369
  subject.voicemail_main :mailbox => mailbox
368
370
  end
369
371
 
370
372
  it 'when given no mailbox or context an empty string should be passed to execute as the first argument' do
371
- subject.expects(:execute).once.with("VoiceMailMain", "", "s")
373
+ subject.should_receive(:execute).once.with("VoiceMailMain", "", "s")
372
374
  subject.voicemail_main :authenticate => false
373
375
  end
374
376
 
375
377
  it 'should properly concatenate the options when given multiple ones' do
376
378
  folder = "ohai"
377
379
  mailbox = 9999
378
- subject.expects(:execute).once.with("VoiceMailMain", "#{mailbox}", "sa(#{folder})")
380
+ subject.should_receive(:execute).once.with("VoiceMailMain", "#{mailbox}", "sa(#{folder})")
379
381
  subject.voicemail_main :mailbox => mailbox, :authenticate => false, :folder => folder
380
382
  end
381
383
 
382
384
  it 'should not require any arguments' do
383
- subject.expects(:execute).once.with("VoiceMailMain")
385
+ subject.should_receive(:execute).once.with("VoiceMailMain")
384
386
  subject.voicemail_main
385
387
  end
386
388
 
387
389
  it 'should pass in the "@context_name" part in if a :context is given and no mailbox is given' do
388
390
  context_name = "icanhascheezburger"
389
- subject.expects(:execute).once.with("VoiceMailMain", "@#{context_name}")
391
+ subject.should_receive(:execute).once.with("VoiceMailMain", "@#{context_name}")
390
392
  subject.voicemail_main :context => context_name
391
393
  end
392
394
 
@@ -425,17 +427,17 @@ module Adhearsion::Asterisk
425
427
  let(:time_format) { 'IMp' }
426
428
 
427
429
  it "if a Date object is passed in, SayUnixTime is sent with the argument and format" do
428
- subject.expects(:execute).once.with("SayUnixTime", date.to_time.to_i, "", date_format)
430
+ subject.should_receive(:execute).once.with("SayUnixTime", date.to_time.to_i, "", date_format)
429
431
  subject.play_time(date, :format => date_format)
430
432
  end
431
433
 
432
434
  it "if a Time object is passed in, SayUnixTime is sent with the argument and format" do
433
- subject.expects(:execute).once.with("SayUnixTime", time.to_i, "", time_format)
435
+ subject.should_receive(:execute).once.with("SayUnixTime", time.to_i, "", time_format)
434
436
  subject.play_time(time, :format => time_format)
435
437
  end
436
438
 
437
439
  it "if a Time object is passed in alone, SayUnixTime is sent with the argument and the default format" do
438
- subject.expects(:execute).once.with("SayUnixTime", time.to_i, "", "")
440
+ subject.should_receive(:execute).once.with("SayUnixTime", time.to_i, "", "")
439
441
  subject.play_time(time)
440
442
  end
441
443
 
@@ -444,7 +446,7 @@ module Adhearsion::Asterisk
444
446
  describe "#play_numeric" do
445
447
  let(:numeric) { 20 }
446
448
  it "should send the correct command SayNumber playing a numeric argument" do
447
- subject.expects(:execute).once.with("SayNumber", numeric)
449
+ subject.should_receive(:execute).once.with("SayNumber", numeric)
448
450
  subject.play_numeric(numeric)
449
451
  end
450
452
  end
@@ -452,7 +454,7 @@ module Adhearsion::Asterisk
452
454
  describe "#play_digits" do
453
455
  let(:numeric) { 20 }
454
456
  it "should send the correct command SayDigits playing a numeric argument" do
455
- subject.expects(:execute).once.with("SayDigits", numeric)
457
+ subject.should_receive(:execute).once.with("SayDigits", numeric)
456
458
  subject.play_digits(numeric)
457
459
  end
458
460
  end
@@ -460,7 +462,7 @@ module Adhearsion::Asterisk
460
462
  describe "#play_tones" do
461
463
  context "should send the correct command Playtones playing tones" do
462
464
  before do
463
- subject.expects(:execute).once.with("Playtones", "!950/330,!1400/330,!1800/330,0")
465
+ subject.should_receive(:execute).once.with("Playtones", "!950/330,!1400/330,!1800/330,0")
464
466
  end
465
467
 
466
468
  it "given as a string" do
@@ -472,7 +474,7 @@ module Adhearsion::Asterisk
472
474
  end
473
475
 
474
476
  it "and sleep for the duration when instructed" do
475
- subject.expects(:sleep).once.with(0.99)
477
+ subject.should_receive(:sleep).once.with(0.99)
476
478
  subject.play_tones("!950/330,!1400/330,!1800/330,0", true)
477
479
  end
478
480
  end
@@ -481,15 +483,15 @@ module Adhearsion::Asterisk
481
483
  describe "#play_soundfile" do
482
484
  let(:audiofile) { "tt-monkeys" }
483
485
  it "should send the correct command Playback playing an audio file" do
484
- subject.expects(:execute).once.with("Playback", audiofile)
485
- # subject.expects(:execute).once.with("Playback", audiofile).returns([200, 1, nil])
486
- subject.expects(:get_variable).once.with("PLAYBACKSTATUS").returns(PLAYBACK_SUCCESS)
486
+ subject.should_receive(:execute).once.with("Playback", audiofile)
487
+ # subject.should_receive(:execute).once.with("Playback", audiofile).and_return([200, 1, nil])
488
+ subject.should_receive(:get_variable).once.with("PLAYBACKSTATUS").and_return(PLAYBACK_SUCCESS)
487
489
  subject.play_soundfile(audiofile)
488
490
  end
489
491
 
490
492
  it "should return false if playback fails" do
491
- subject.expects(:execute).once.with("Playback", audiofile)
492
- subject.expects(:get_variable).once.with("PLAYBACKSTATUS").returns('FAILED')
493
+ subject.should_receive(:execute).once.with("Playback", audiofile)
494
+ subject.should_receive(:get_variable).once.with("PLAYBACKSTATUS").and_return('FAILED')
493
495
  subject.play_soundfile(audiofile).should == false
494
496
  end
495
497
  end
@@ -498,7 +500,7 @@ module Adhearsion::Asterisk
498
500
  context 'executes Playtones with 0 as an argument if it' do
499
501
  before do
500
502
  command = Punchblock::Component::Asterisk::AGI::Command.new :name => "EXEC Playtones", :params => ["0"]
501
- @expect_command = subject.expects(:execute_component_and_await_completion).with(command)
503
+ @expect_command = subject.should_receive(:execute_component_and_await_completion).with(command)
502
504
  end
503
505
 
504
506
  it 'is not given a block' do
@@ -507,7 +509,7 @@ module Adhearsion::Asterisk
507
509
  end
508
510
 
509
511
  it 'is given a block, which it then yields' do
510
- @expect_command.times(3)
512
+ @expect_command.exactly(3).times
511
513
  expect { |b| subject.generate_silence { b.to_proc.call; run; run } }.to yield_with_no_args
512
514
  end
513
515
 
@@ -542,6 +544,48 @@ module Adhearsion::Asterisk
542
544
  end
543
545
  end
544
546
  end
547
+
548
+ describe "#goto" do
549
+ let(:context) { "foo" }
550
+ let(:extension) { "s" }
551
+ let(:priority) { 1 }
552
+
553
+ it "sets the call to not hangup after execution" do
554
+ call.should_receive(:[]=).with(:ahn_prevent_hangup, true)
555
+ subject.should_receive(:execute).with('Goto', context, extension, priority)
556
+ subject.should_receive(:set_variable).with('PUNCHBLOCK_END_ON_ASYNCAGI_BREAK', 'true').once
557
+ subject.should_receive(:agi).with("ASYNCAGI BREAK").at_most :once
558
+ subject.goto(context, extension, priority)
559
+ end
560
+
561
+ it "releases control of the call using ASYNCAGI BREAK" do
562
+ call.should_receive(:[]=).with(:ahn_prevent_hangup, true).at_most :once
563
+ subject.should_receive(:execute).with('Goto', context, extension, priority).at_most :once
564
+ subject.should_receive(:set_variable).with('PUNCHBLOCK_END_ON_ASYNCAGI_BREAK', 'true').once
565
+ subject.should_receive(:agi).with("ASYNCAGI BREAK").once
566
+ subject.goto(context, extension, priority)
567
+ end
568
+
569
+ context "number of arguments" do
570
+ before :each do
571
+ call.should_receive(:[]=).with(:ahn_prevent_hangup, true).at_most :once
572
+ subject.should_receive(:set_variable).with('PUNCHBLOCK_END_ON_ASYNCAGI_BREAK', 'true').once
573
+ subject.should_receive(:agi).with("ASYNCAGI BREAK").at_most :once
574
+ end
575
+ it "executes Goto with 3 arguments when passed all 3" do
576
+ subject.should_receive(:execute).with('Goto', context, extension, priority)
577
+ subject.goto(context, extension, priority)
578
+ end
579
+ it "executes Goto with 2 arguments when passed 2" do
580
+ subject.should_receive(:execute).with('Goto', context, extension)
581
+ subject.goto(context, extension)
582
+ end
583
+ it "executes Goto with 1 arguments when passed 1" do
584
+ subject.should_receive(:execute).with('Goto', context)
585
+ subject.goto(context)
586
+ end
587
+ end
588
+ end
545
589
  end
546
590
  end#main describe
547
591
  end