adhearsion 2.0.0.alpha1 → 2.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.gitignore +2 -0
  2. data/.travis.yml +12 -0
  3. data/CHANGELOG.md +17 -0
  4. data/adhearsion.gemspec +4 -3
  5. data/features/app_generator.feature +3 -1
  6. data/features/cli.feature +7 -7
  7. data/features/support/env.rb +46 -0
  8. data/lib/adhearsion.rb +1 -2
  9. data/lib/adhearsion/call.rb +59 -19
  10. data/lib/adhearsion/call_controller.rb +20 -24
  11. data/lib/adhearsion/call_controller/dial.rb +18 -18
  12. data/lib/adhearsion/cli_commands.rb +26 -9
  13. data/lib/adhearsion/configuration.rb +39 -10
  14. data/lib/adhearsion/console.rb +61 -42
  15. data/lib/adhearsion/foundation/libc.rb +13 -0
  16. data/lib/adhearsion/generators/app/app_generator.rb +4 -1
  17. data/lib/adhearsion/generators/app/templates/{Gemfile → Gemfile.erb} +1 -1
  18. data/lib/adhearsion/generators/app/templates/Rakefile +3 -22
  19. data/lib/adhearsion/generators/app/templates/gitignore +7 -0
  20. data/lib/adhearsion/generators/app/templates/lib/simon_game.rb +1 -0
  21. data/lib/adhearsion/generators/app/templates/script/ahn +1 -0
  22. data/lib/adhearsion/initializer.rb +24 -12
  23. data/lib/adhearsion/linux_proc_name.rb +41 -0
  24. data/lib/adhearsion/outbound_call.rb +10 -5
  25. data/lib/adhearsion/plugin.rb +29 -132
  26. data/lib/adhearsion/process.rb +4 -1
  27. data/lib/adhearsion/punchblock_plugin.rb +14 -5
  28. data/lib/adhearsion/punchblock_plugin/initializer.rb +8 -1
  29. data/lib/adhearsion/router/route.rb +1 -3
  30. data/lib/adhearsion/tasks.rb +6 -12
  31. data/lib/adhearsion/tasks/configuration.rb +7 -24
  32. data/lib/adhearsion/tasks/environment.rb +12 -0
  33. data/lib/adhearsion/tasks/plugins.rb +9 -14
  34. data/lib/adhearsion/version.rb +1 -1
  35. data/spec/adhearsion/call_controller/dial_spec.rb +46 -22
  36. data/spec/adhearsion/call_controller_spec.rb +48 -13
  37. data/spec/adhearsion/call_spec.rb +144 -23
  38. data/spec/adhearsion/calls_spec.rb +8 -4
  39. data/spec/adhearsion/console_spec.rb +24 -0
  40. data/spec/adhearsion/initializer/logging_spec.rb +0 -3
  41. data/spec/adhearsion/initializer_spec.rb +52 -37
  42. data/spec/adhearsion/logging_spec.rb +0 -3
  43. data/spec/adhearsion/outbound_call_spec.rb +12 -2
  44. data/spec/adhearsion/plugin_spec.rb +74 -184
  45. data/spec/adhearsion/process_spec.rb +59 -26
  46. data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +3 -4
  47. data/spec/adhearsion/punchblock_plugin_spec.rb +11 -0
  48. data/spec/adhearsion/router/route_spec.rb +37 -6
  49. data/spec/adhearsion_spec.rb +31 -8
  50. data/spec/spec_helper.rb +14 -0
  51. data/spec/support/call_controller_test_helpers.rb +2 -2
  52. data/spec/support/logging_helpers.rb +2 -0
  53. metadata +85 -68
  54. data/lib/adhearsion/dialplan_controller.rb +0 -9
  55. data/lib/adhearsion/foundation/synchronized_hash.rb +0 -93
  56. data/lib/adhearsion/plugin/methods_container.rb +0 -6
  57. data/spec/adhearsion/dialplan_controller_spec.rb +0 -26
@@ -4,11 +4,15 @@ module Adhearsion
4
4
  describe Calls do
5
5
  before { Adhearsion.active_calls.clear! }
6
6
 
7
- let(:call) { Adhearsion::Call.new mock_offer }
7
+ let(:call) { Adhearsion::Call.new new_offer }
8
+
9
+ def new_offer(call_id = nil, headers = {})
10
+ Punchblock::Event::Offer.new :call_id => call_id || rand, :headers => headers
11
+ end
8
12
 
9
13
  it 'can create a call and add it to the active calls' do
10
14
  Adhearsion.active_calls.any?.should == false
11
- call = Adhearsion.active_calls.from_offer mock_offer
15
+ call = Adhearsion.active_calls.from_offer new_offer
12
16
  call.should be_a Adhearsion::Call
13
17
  Adhearsion.active_calls.size.should == 1
14
18
  end
@@ -21,7 +25,7 @@ module Adhearsion
21
25
 
22
26
  it '#remove_inactive_call should delete the call in the Hash' do
23
27
  number_of_calls = 10
24
- calls = Array.new(number_of_calls) { Adhearsion::Call.new mock_offer }
28
+ calls = Array.new(number_of_calls) { Adhearsion::Call.new new_offer }
25
29
  calls.each { |call| subject << call }
26
30
 
27
31
  deleted_call = calls[number_of_calls / 2]
@@ -35,7 +39,7 @@ module Adhearsion
35
39
  end
36
40
 
37
41
  it "finding calls by a tag" do
38
- calls = Array.new(3) { Adhearsion::Call.new mock_offer }
42
+ calls = Array.new(3) { Adhearsion::Call.new new_offer }
39
43
  calls.each { |call| subject << call }
40
44
 
41
45
  tagged_call = calls.last
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ module Adhearsion
4
+ describe Console do
5
+ describe "providing hooks to include console functionality" do
6
+ it "should allow mixing in a module globally on all CallController classes" do
7
+ Adhearsion::Console.mixin TestBiscuit
8
+ Adhearsion::Console.throwadogabone.should be true
9
+ end
10
+ end
11
+
12
+ describe 'testing for libedit vs. readline' do
13
+ it 'should return true when detecting readline' do
14
+ flexmock(Readline).should_receive(:emacs_editing_mode).once.and_return true
15
+ Adhearsion::Console.libedit?.should be false
16
+ end
17
+
18
+ it 'should return false when detecting libedit' do
19
+ flexmock(Readline).should_receive(:emacs_editing_mode).once.and_raise NotImplementedError
20
+ Adhearsion::Console.libedit?.should be true
21
+ end
22
+ end
23
+ end
24
+ end
@@ -39,9 +39,6 @@ describe Adhearsion::Initializer::Logging do
39
39
  ::Logging.logger.root.level.should eql(::Logging::LEVELS["debug"])
40
40
  end
41
41
 
42
- Foo = Class.new
43
- Foo::Bar = Class.new Foo
44
-
45
42
  it "should create only a Logging object per Class (reuse per all the instances)" do
46
43
  _logger = Foo.new.logger
47
44
  10.times do
@@ -118,6 +118,21 @@ describe Adhearsion::Initializer do
118
118
  flexmock(Dir).should_receive(:mkdir).with("log/test/").once
119
119
  ahn.initialize_log_paths
120
120
  end
121
+
122
+ it "should set the adhearsion proc name" do
123
+ ahn = stub_behavior_for_initializer_with_no_path_changing_behavior do
124
+ flexmock(File).should_receive(:open).with(File.join(path, 'adhearsion.pid'), 'w', Proc).at_least.once
125
+ flexmock(Adhearsion::LinuxProcName).should_receive(:set_proc_name).with(Adhearsion.config.platform.process_name)
126
+ Adhearsion::Initializer.start :pid_file => true
127
+ end
128
+ end
129
+
130
+ it "should update the adhearsion proc name" do
131
+ ahn = stub_behavior_for_initializer_with_no_path_changing_behavior do
132
+ Adhearsion::Initializer.start :pid_file => true
133
+ end
134
+ $0.should == Adhearsion.config.platform.process_name
135
+ end
121
136
  end
122
137
 
123
138
  describe "Initializing logger" do
@@ -183,8 +198,14 @@ describe "Updating RAILS_ENV variable" do
183
198
  Adhearsion.config = nil
184
199
  end
185
200
 
186
- after do
201
+ before do
202
+ ENV['RAILS_ENV'] = nil
203
+ ENV['AHN_ENV'] = nil
204
+ end
205
+
206
+ after :all do
187
207
  ENV['RAILS_ENV'] = nil
208
+ ENV['AHN_ENV'] = nil
188
209
  end
189
210
 
190
211
  describe "when neither RAILS_ENV nor AHN_ENV are set" do
@@ -199,51 +220,45 @@ describe "Updating RAILS_ENV variable" do
199
220
  ENV['RAILS_ENV'].should == env.to_s
200
221
  end
201
222
  end
223
+ end
202
224
 
203
- context "when RAILS_ENV is set" do
204
-
205
- after do
206
- ENV['RAILS_ENV'] = nil
207
- ENV['AHN_ENV'] = nil
208
- end
225
+ context "when RAILS_ENV is set" do
226
+ before do
227
+ ENV['RAILS_ENV'] = "test"
228
+ end
209
229
 
210
- it "should preserve the RAILS_ENV value if AHN_ENV is unset" do
211
- ENV['RAILS_ENV'] = "test"
212
- ahn = nil
213
- stub_behavior_for_initializer_with_no_path_changing_behavior do
214
- ahn = Adhearsion::Initializer.start
215
- end
216
- ahn.update_rails_env_var
217
- ENV['RAILS_ENV'].should == "test"
230
+ it "should preserve the RAILS_ENV value if AHN_ENV is unset" do
231
+ ahn = nil
232
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
233
+ ahn = Adhearsion::Initializer.start
218
234
  end
235
+ ahn.update_rails_env_var
236
+ ENV['RAILS_ENV'].should == "test"
237
+ end
219
238
 
220
- it "should update the RAILS_ENV value with the AHN_ENV value" do
221
- ENV['RAILS_ENV'] = "test"
222
- ENV['AHN_ENV'] = "production"
223
- ahn = nil
224
- stub_behavior_for_initializer_with_no_path_changing_behavior do
225
- ahn = Adhearsion::Initializer.start
226
- end
227
- ahn.update_rails_env_var
228
- ENV['RAILS_ENV'].should == "production"
239
+ it "should update the RAILS_ENV value with the AHN_ENV value" do
240
+ ENV['AHN_ENV'] = "production"
241
+ ahn = nil
242
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
243
+ ahn = Adhearsion::Initializer.start
229
244
  end
245
+ ahn.update_rails_env_var
246
+ ENV['RAILS_ENV'].should == "production"
230
247
  end
248
+ end
231
249
 
232
- context "when RAILS_ENV is unset and AHN_ENV is set" do
233
- after do
234
- ENV['RAILS_ENV'] = nil
235
- ENV['AHN_ENV'] = nil
236
- end
250
+ context "when RAILS_ENV is unset and AHN_ENV is set" do
251
+ before do
252
+ ENV['AHN_ENV'] = "production"
253
+ end
237
254
 
238
- it "should define the RAILS_ENV value with the AHN_ENV value" do
239
- ENV['AHN_ENV'] = "production"
240
- ahn = nil
241
- stub_behavior_for_initializer_with_no_path_changing_behavior do
242
- ahn = Adhearsion::Initializer.start
243
- end
244
- ahn.update_rails_env_var
245
- ENV['RAILS_ENV'].should == "production"
255
+ it "should define the RAILS_ENV value with the AHN_ENV value" do
256
+ ahn = nil
257
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
258
+ ahn = Adhearsion::Initializer.start
246
259
  end
260
+ ahn.update_rails_env_var
261
+ ENV['RAILS_ENV'].should == "production"
247
262
  end
248
263
  end
249
264
 
@@ -1,8 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- Foo = Class.new
4
- Foo::Bar = Class.new
5
-
6
3
  describe Adhearsion::Logging do
7
4
 
8
5
  before do
@@ -18,7 +18,7 @@ module Adhearsion
18
18
  describe ".originate" do
19
19
  let(:to) { 'sip:foo@bar.com' }
20
20
 
21
- let(:mock_call) { OutboundCall.new }
21
+ let(:mock_call) { OutboundCall.new }
22
22
 
23
23
  def mock_dial
24
24
  flexmock(OutboundCall).new_instances.should_receive(:dial).and_return true
@@ -66,7 +66,7 @@ module Adhearsion
66
66
 
67
67
  describe "#dial" do
68
68
  def expect_message_waiting_for_response(message)
69
- flexmock(subject).should_receive(:write_and_await_response).once.with(message).and_return do
69
+ flexmock(subject).should_receive(:write_and_await_response).once.with(message, 60).and_return do
70
70
  message.call_id = call_id
71
71
  message
72
72
  end
@@ -96,6 +96,16 @@ module Adhearsion
96
96
  subject.id.should == call_id
97
97
  end
98
98
 
99
+ it "should set the to from the dial command" do
100
+ subject.dial to, :from => from
101
+ subject.to.should == to
102
+ end
103
+
104
+ it "should set the 'from' from the dial command" do
105
+ subject.dial to, :from => from
106
+ subject.from.should == from
107
+ end
108
+
99
109
  it "should add the call to the active calls registry" do
100
110
  Adhearsion.active_calls.clear!
101
111
  subject.dial to, :from => from
@@ -4,6 +4,10 @@ include InitializerStubs
4
4
 
5
5
  describe Adhearsion::Plugin do
6
6
 
7
+ before :all do
8
+ defined?(FooBar) and Object.send(:remove_const, :"FooBar")
9
+ end
10
+
7
11
  describe "inheritance" do
8
12
  after do
9
13
  defined?(FooBar) and Object.send(:remove_const, :"FooBar")
@@ -28,87 +32,6 @@ describe Adhearsion::Plugin do
28
32
  end
29
33
  end
30
34
 
31
- describe "metaprogramming" do
32
- Adhearsion::Plugin::SCOPE_NAMES.each do |method|
33
- it "should respond to #{method.to_s}" do
34
- Adhearsion::Plugin.should respond_to method
35
- end
36
-
37
- it "should respond to #{method.to_s}_module" do
38
- Adhearsion::Plugin.should respond_to "#{method.to_s}_module"
39
- end
40
- end
41
- end
42
-
43
- [:rpc, :dialplan, :console].each do |method|
44
-
45
- describe "extending an object with #{method.to_s} scope methods" do
46
-
47
- before(:all) do
48
- A = Class.new do
49
- def bar
50
- "bar"
51
- end
52
- end
53
- end
54
-
55
- after(:all) do
56
- defined?(A) and Object.send(:remove_const, :"A")
57
- end
58
-
59
- before do
60
- FooBar = Class.new Adhearsion::Plugin do
61
- self.method(method).call(:foo) do
62
- "foo".concat bar
63
- end
64
-
65
- end
66
- flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
67
- Adhearsion::Plugin.load_plugins
68
- Adhearsion::Plugin.send("#{method.to_s}_module".to_sym).instance_methods.map{|x| x.to_s}.include?("foo").should == true
69
- end
70
-
71
- after do
72
- defined?(FooBar) and Object.send(:remove_const, :"FooBar")
73
- end
74
-
75
- describe "when extending a Class" do
76
- it "should respond to any of the #{method.to_s} scope methods and have visibility to the own instance methods" do
77
-
78
- Adhearsion::Plugin.send("add_#{method}_methods".to_sym, A)
79
- a = A.new
80
- a.should respond_to :foo
81
- a.foo.should == "foobar"
82
- end
83
- end
84
-
85
- describe "when extending an instance" do
86
- it "should respond to any of the scope methods and have visibility to the own instance methods" do
87
-
88
- a = A.new
89
- Adhearsion::Plugin.send("add_#{method}_methods".to_sym, a)
90
- a.should respond_to :foo
91
- a.foo.should == "foobar"
92
- end
93
- end
94
- end
95
- end
96
-
97
- describe "While adding console methods" do
98
-
99
- it "should add a new method to Console" do
100
- FooBar = Class.new Adhearsion::Plugin do
101
- console :config do
102
- Adhearsion.config
103
- end
104
- end
105
- flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
106
- Adhearsion::Plugin.load_plugins
107
- Adhearsion::Console.should respond_to(:config)
108
- Adhearsion::Console.config.should == Adhearsion.config
109
- end
110
- end
111
-
112
35
  describe "While configuring plugins" do
113
36
  after(:each) do
114
37
  defined?(FooBar) and Object.send(:remove_const, :"FooBar")
@@ -181,7 +104,7 @@ describe Adhearsion::Plugin do
181
104
  end
182
105
  end
183
106
 
184
- describe "Adhearsion::Plugin.load_plugins" do
107
+ describe "Adhearsion::Plugin.init_plugins" do
185
108
  before do
186
109
  Adhearsion::Plugin.class_eval do
187
110
  def self.reset_methods_scope
@@ -199,6 +122,7 @@ describe Adhearsion::Plugin do
199
122
 
200
123
  after do
201
124
  Adhearsion::Plugin.initializers.clear
125
+ Adhearsion::Plugin.runners.clear
202
126
  defined?(FooBar) and Object.send(:remove_const, :"FooBar")
203
127
  defined?(FooBarBaz) and Object.send(:remove_const, :"FooBarBaz")
204
128
  defined?(FooBarBazz) and Object.send(:remove_const, :"FooBarBazz")
@@ -211,7 +135,7 @@ describe Adhearsion::Plugin do
211
135
  # 1 => Punchblock. Must be empty once punchblock initializer is an external Plugin
212
136
  Adhearsion::Plugin.initializers.should have(1).initializers
213
137
  flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
214
- Adhearsion::Plugin.load_plugins
138
+ Adhearsion::Plugin.init_plugins
215
139
  end
216
140
 
217
141
  it "should add a initializer when Plugin defines it" do
@@ -226,10 +150,10 @@ describe Adhearsion::Plugin do
226
150
  flexmock(FooBar).should_receive(:log).once
227
151
  Adhearsion::Plugin.initializers.length.should be 1
228
152
  flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
229
- Adhearsion::Plugin.load_plugins
153
+ Adhearsion::Plugin.init_plugins
230
154
  end
231
155
 
232
- it "should initialize all Plugin childs, including deep childs" do
156
+ it "should initialize all Plugin children, including deep childs" do
233
157
  FooBar = Class.new Adhearsion::Plugin do
234
158
  init :foo_bar do
235
159
  FooBar.log "foo bar"
@@ -252,7 +176,7 @@ describe Adhearsion::Plugin do
252
176
 
253
177
  flexmock(FooBar).should_receive(:log).times(3)
254
178
  flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
255
- Adhearsion::Plugin.load_plugins
179
+ Adhearsion::Plugin.init_plugins
256
180
  end
257
181
 
258
182
  it "should allow to include an initializer before another one" do
@@ -303,136 +227,102 @@ describe Adhearsion::Plugin do
303
227
  end
304
228
  end
305
229
 
306
- [:rpc, :dialplan].each do |method|
307
- describe "Plugin subclass with #{method.to_s}_method definition" do
308
- it "should add a method defined using #{method.to_s} method" do
309
- FooBar = Class.new Adhearsion::Plugin do
310
- self.method(method).call(:foo)
311
-
312
- def self.foo(call)
313
- "bar"
314
- end
315
- end
230
+ describe "while registering plugins runners" do
231
+ it "should do nothing with a Plugin that has no run method call" do
232
+ FooBar = Class.new Adhearsion::Plugin
316
233
 
317
- flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
318
- Adhearsion::Plugin.load_plugins
319
- Adhearsion::Plugin.methods_scope[method].instance_methods.map{|x| x.to_s}.include?(:foo.to_s).should be true
320
- end
234
+ # May become 1 if Punchblock defines a runner.
235
+ Adhearsion::Plugin.runners.should have(0).runners
236
+ flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
237
+ Adhearsion::Plugin.run_plugins
238
+ end
321
239
 
322
- it "should add a method defined using #{method.to_s} method with a block" do
323
- FooBar = Class.new Adhearsion::Plugin do
324
- block = lambda{|call| "bar"}
325
- self.method(method).call(:foo, &block)
240
+ it "should add a runner when Plugin defines it" do
241
+ FooBar = Class.new Adhearsion::Plugin do
242
+ run :foo_bar do
243
+ FooBar.log "foo bar"
326
244
  end
327
-
328
- flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
329
- Adhearsion::Plugin.load_plugins
330
- Adhearsion::Plugin.methods_scope[method].instance_methods.map{|x| x.to_s}.include?(:foo.to_s).should be true
331
- end
332
-
333
- it "should add an instance method defined using #{method.to_s} method" do
334
- FooBar = Class.new Adhearsion::Plugin do
335
- self.method(method).call(:foo)
336
- def foo(call)
337
- call
338
- end
245
+ def self.log
339
246
  end
340
-
341
- flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
342
- Adhearsion::Plugin.load_plugins
343
- Adhearsion::Plugin.methods_scope[method].instance_methods.map{|x| x.to_s}.include?(:foo.to_s).should be true
344
247
  end
345
248
 
346
- it "should add an array of methods defined using #{method.to_s} method" do
347
- FooBar = Class.new Adhearsion::Plugin do
348
- self.method(method).call([:foo, :bar])
349
-
350
- def self.foo(call)
351
- call
352
- end
249
+ flexmock(FooBar).should_receive(:log).once
250
+ Adhearsion::Plugin.runners.length.should be 1
251
+ flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
252
+ Adhearsion::Plugin.run_plugins
253
+ end
353
254
 
354
- def self.bar(call)
355
- "foo"
356
- end
255
+ it "should run all Plugin children, including deep childs" do
256
+ FooBar = Class.new Adhearsion::Plugin do
257
+ run :foo_bar do
258
+ FooBar.log "foo bar"
357
259
  end
358
260
 
359
- flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
360
- Adhearsion::Plugin.load_plugins
361
- [:foo, :bar].each do |_method|
362
- Adhearsion::Plugin.methods_scope[method].instance_methods.map{|x| x.to_s}.include?(_method.to_s).should be true
261
+ def self.log
363
262
  end
364
- Adhearsion::Plugin.methods_scope[method].instance_methods.length.should eql 2
365
263
  end
366
264
 
367
- it "should add an array of instance methods defined using #{method.to_s} method" do
368
- FooBar = Class.new Adhearsion::Plugin do
369
- self.method(method).call([:foo, :bar])
370
- def foo(call)
371
- call
372
- end
373
-
374
- def bar(call)
375
- call
376
- end
265
+ FooBarBaz = Class.new FooBar do
266
+ run :foo_bar_baz do
267
+ FooBar.log "foo bar baz"
377
268
  end
378
-
379
- flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
380
- Adhearsion::Plugin.load_plugins
381
- [:foo, :bar].each do |_method|
382
- Adhearsion::Plugin.methods_scope[method].instance_methods.map{|x| x.to_s}.include?(_method.to_s).should be true
269
+ end
270
+ FooBarBazz = Class.new FooBar do
271
+ run :foo_bar_bazz do
272
+ FooBar.log "foo bar bazz"
383
273
  end
384
274
  end
385
275
 
386
- it "should add an array of instance and singleton methods defined using #{method.to_s} method" do
387
- FooBar = Class.new Adhearsion::Plugin do
388
- self.method(method).call([:foo, :bar])
389
- def self.foo(call)
390
- call
391
- end
276
+ flexmock(FooBar).should_receive(:log).times(3)
277
+ flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
278
+ Adhearsion::Plugin.run_plugins
279
+ end
392
280
 
393
- def bar(call)
394
- call
395
- end
281
+ it "should allow to execute one runner before another one" do
282
+ FooBar = Class.new Adhearsion::Plugin do
283
+ run :foo_bar do
284
+ FooBar.log "foo bar"
396
285
  end
397
286
 
398
- flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
399
- Adhearsion::Plugin.load_plugins
400
- [:foo, :bar].each do |_method|
401
- Adhearsion::Plugin.methods_scope[method].instance_methods.map{|x| x.to_s}.include?(_method.to_s).should be true
287
+ def self.log
402
288
  end
403
289
  end
404
290
 
405
- it "should add a method defined using #{method.to_s} method with a specific block" do
406
- FooBar = Class.new Adhearsion::Plugin do
407
- self.method(method).call(:foo) do
408
- "foo"
409
- end
291
+ FooBarBaz = Class.new FooBar do
292
+ run :foo_bar_baz, :before => :foo_bar do
293
+ FooBar.log "foo bar baz"
410
294
  end
411
-
412
- flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
413
- Adhearsion::Plugin.load_plugins
414
- Adhearsion::Plugin.methods_scope[method].instance_methods.map{|x| x.to_s}.include?(:foo.to_s).should be true
415
- Adhearsion::Plugin.send("#{method.to_s}_module".to_sym).instance_methods.map{|x| x.to_s}.include?(:foo.to_s).should be true
416
295
  end
296
+
297
+ Adhearsion::Plugin.runners.tsort.first.name.should eql :foo_bar_baz
298
+ Adhearsion::Plugin.runners.tsort.last.name.should eql :foo_bar
417
299
  end
418
- end
419
300
 
420
- describe "Plugin subclass with rpc_method and dialplan_method definitions" do
421
- it "should add a method defined using rpc and a method defined using dialplan" do
301
+ it "should allow to include an runner after another one" do
422
302
  FooBar = Class.new Adhearsion::Plugin do
423
- rpc :foo
424
- dialplan :foo
303
+ run :foo_bar do
304
+ FooBar.log "foo bar"
305
+ end
425
306
 
426
- def self.foo(call)
427
- "bar"
307
+ def self.log
428
308
  end
429
309
  end
430
310
 
431
- flexmock(Adhearsion::PunchblockPlugin::Initializer).should_receive(:start).and_return true
432
- Adhearsion::Plugin.load_plugins
433
- [:dialplan_module, :rpc_module].each do |_module|
434
- Adhearsion::Plugin.send(_module).instance_methods.map{|x| x.to_s}.include?(:foo.to_s).should be true
311
+ FooBarBaz = Class.new FooBar do
312
+ run :foo_bar_baz, :after => :foo_bar_bazz do
313
+ FooBar.log "foo bar baz"
314
+ end
435
315
  end
316
+
317
+ FooBarBazz = Class.new FooBar do
318
+ run :foo_bar_bazz do
319
+ FooBar.log "foo bar bazz"
320
+ end
321
+ end
322
+
323
+ Adhearsion::Plugin.runners.length.should eql 3
324
+ Adhearsion::Plugin.runners.tsort.first.name.should eql :foo_bar
325
+ Adhearsion::Plugin.runners.tsort.last.name.should eql :foo_bar_baz
436
326
  end
437
327
  end
438
328
  end