adhearsion 1.2.6 → 2.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. data/.gitignore +17 -10
  2. data/CHANGELOG.md +273 -0
  3. data/Gemfile +1 -1
  4. data/Guardfile +17 -0
  5. data/README.markdown +61 -9
  6. data/Rakefile +16 -48
  7. data/adhearsion.gemspec +21 -7
  8. data/bin/ahn +3 -1
  9. data/cucumber.yml +4 -0
  10. data/features/app_generator.feature +42 -0
  11. data/features/cli.feature +108 -0
  12. data/features/step_definitions/app_generator_steps.rb +6 -0
  13. data/features/step_definitions/cli_steps.rb +74 -0
  14. data/features/support/aruba_helper.rb +22 -0
  15. data/features/support/env.rb +37 -0
  16. data/features/support/utils.rb +8 -0
  17. data/lib/adhearsion.rb +85 -41
  18. data/lib/adhearsion/call.rb +176 -0
  19. data/lib/adhearsion/call_controller.rb +134 -0
  20. data/lib/adhearsion/call_controller/dial.rb +70 -0
  21. data/lib/adhearsion/call_controller/input.rb +173 -0
  22. data/lib/adhearsion/call_controller/menu.rb +124 -0
  23. data/lib/adhearsion/call_controller/output.rb +267 -0
  24. data/lib/adhearsion/call_controller/record.rb +42 -0
  25. data/lib/adhearsion/call_controller/utility.rb +60 -0
  26. data/lib/adhearsion/calls.rb +81 -0
  27. data/lib/adhearsion/cli.rb +1 -3
  28. data/lib/adhearsion/cli_commands.rb +142 -0
  29. data/lib/adhearsion/configuration.rb +149 -0
  30. data/lib/adhearsion/console.rb +19 -8
  31. data/lib/adhearsion/dialplan_controller.rb +9 -0
  32. data/lib/adhearsion/events.rb +84 -0
  33. data/lib/adhearsion/foundation/all.rb +0 -7
  34. data/lib/adhearsion/foundation/custom_daemonizer.rb +4 -6
  35. data/lib/adhearsion/foundation/exception_handler.rb +9 -0
  36. data/lib/adhearsion/foundation/object.rb +26 -8
  37. data/lib/adhearsion/foundation/synchronized_hash.rb +3 -6
  38. data/lib/adhearsion/foundation/thread_safety.rb +17 -1
  39. data/lib/adhearsion/generators/app/app_generator.rb +4 -13
  40. data/lib/adhearsion/generators/app/templates/Gemfile +10 -5
  41. data/lib/adhearsion/generators/app/templates/Procfile +1 -0
  42. data/lib/adhearsion/generators/app/templates/README.md +28 -0
  43. data/lib/adhearsion/generators/app/templates/config/adhearsion.rb +41 -0
  44. data/lib/adhearsion/generators/app/templates/{components/simon_game → lib}/simon_game.rb +6 -18
  45. data/lib/adhearsion/generators/app/templates/script/ahn +2 -2
  46. data/lib/adhearsion/initializer.rb +151 -293
  47. data/lib/adhearsion/initializer/logging.rb +33 -0
  48. data/lib/adhearsion/logging.rb +65 -69
  49. data/lib/adhearsion/menu_dsl.rb +15 -0
  50. data/lib/adhearsion/menu_dsl/calculated_match.rb +39 -0
  51. data/lib/adhearsion/menu_dsl/calculated_match_collection.rb +41 -0
  52. data/lib/adhearsion/menu_dsl/fixnum_match_calculator.rb +18 -0
  53. data/lib/adhearsion/menu_dsl/match_calculator.rb +36 -0
  54. data/lib/adhearsion/{voip/menu_state_machine/menu_class.rb → menu_dsl/menu.rb} +38 -40
  55. data/lib/adhearsion/menu_dsl/menu_builder.rb +69 -0
  56. data/lib/adhearsion/menu_dsl/range_match_calculator.rb +55 -0
  57. data/lib/adhearsion/menu_dsl/string_match_calculator.rb +21 -0
  58. data/lib/adhearsion/outbound_call.rb +64 -0
  59. data/lib/adhearsion/plugin.rb +319 -0
  60. data/lib/adhearsion/plugin/collection.rb +19 -0
  61. data/lib/adhearsion/plugin/initializer.rb +37 -0
  62. data/lib/adhearsion/plugin/methods_container.rb +6 -0
  63. data/lib/adhearsion/process.rb +94 -0
  64. data/lib/adhearsion/punchblock_plugin.rb +29 -0
  65. data/lib/adhearsion/punchblock_plugin/initializer.rb +137 -0
  66. data/lib/adhearsion/router.rb +30 -0
  67. data/lib/adhearsion/router/route.rb +42 -0
  68. data/lib/adhearsion/script_ahn_loader.rb +2 -2
  69. data/lib/adhearsion/tasks.rb +14 -9
  70. data/lib/adhearsion/tasks/configuration.rb +26 -0
  71. data/lib/adhearsion/tasks/plugins.rb +17 -0
  72. data/lib/adhearsion/version.rb +8 -14
  73. data/spec/adhearsion/call_controller/dial_spec.rb +138 -0
  74. data/spec/adhearsion/call_controller/input_spec.rb +278 -0
  75. data/spec/adhearsion/call_controller/menu_spec.rb +120 -0
  76. data/spec/adhearsion/call_controller/output_spec.rb +466 -0
  77. data/spec/adhearsion/call_controller/record_spec.rb +125 -0
  78. data/spec/adhearsion/call_controller_spec.rb +395 -0
  79. data/spec/adhearsion/call_spec.rb +438 -0
  80. data/spec/adhearsion/calls_spec.rb +47 -0
  81. data/spec/adhearsion/configuration_spec.rb +308 -0
  82. data/spec/adhearsion/dialplan_controller_spec.rb +26 -0
  83. data/spec/adhearsion/events_spec.rb +112 -0
  84. data/spec/adhearsion/initializer/logging_spec.rb +58 -0
  85. data/spec/adhearsion/initializer_spec.rb +209 -122
  86. data/spec/adhearsion/logging_spec.rb +58 -47
  87. data/spec/adhearsion/menu_dsl/calculated_match_collection_spec.rb +56 -0
  88. data/spec/adhearsion/menu_dsl/calculated_match_spec.rb +57 -0
  89. data/spec/adhearsion/menu_dsl/fixnum_match_calculator_spec.rb +33 -0
  90. data/spec/adhearsion/menu_dsl/match_calculator_spec.rb +13 -0
  91. data/spec/adhearsion/menu_dsl/menu_builder_spec.rb +118 -0
  92. data/spec/adhearsion/menu_dsl/menu_spec.rb +210 -0
  93. data/spec/adhearsion/menu_dsl/range_match_calculator_spec.rb +28 -0
  94. data/spec/adhearsion/menu_dsl/string_match_calculator_spec.rb +36 -0
  95. data/spec/adhearsion/menu_dsl_spec.rb +12 -0
  96. data/spec/adhearsion/outbound_call_spec.rb +174 -0
  97. data/spec/adhearsion/plugin_spec.rb +489 -0
  98. data/spec/adhearsion/process_spec.rb +34 -0
  99. data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +294 -0
  100. data/spec/adhearsion/router/route_spec.rb +99 -0
  101. data/spec/adhearsion/router_spec.rb +106 -0
  102. data/spec/adhearsion_spec.rb +46 -0
  103. data/spec/spec_helper.rb +14 -14
  104. data/spec/support/call_controller_test_helpers.rb +48 -0
  105. data/spec/support/initializer_stubs.rb +8 -13
  106. data/spec/support/punchblock_mocks.rb +6 -0
  107. metadata +255 -253
  108. data/CHANGELOG +0 -174
  109. data/bin/ahnctl +0 -68
  110. data/bin/jahn +0 -43
  111. data/examples/asterisk_manager_interface/standalone.rb +0 -51
  112. data/lib/adhearsion/commands.rb +0 -302
  113. data/lib/adhearsion/component_manager.rb +0 -278
  114. data/lib/adhearsion/component_manager/component_tester.rb +0 -54
  115. data/lib/adhearsion/component_manager/spec_framework.rb +0 -18
  116. data/lib/adhearsion/events_support.rb +0 -65
  117. data/lib/adhearsion/foundation/blank_slate.rb +0 -3
  118. data/lib/adhearsion/foundation/event_socket.rb +0 -205
  119. data/lib/adhearsion/foundation/future_resource.rb +0 -36
  120. data/lib/adhearsion/foundation/metaprogramming.rb +0 -17
  121. data/lib/adhearsion/foundation/numeric.rb +0 -13
  122. data/lib/adhearsion/foundation/pseudo_guid.rb +0 -10
  123. data/lib/adhearsion/foundation/relationship_properties.rb +0 -42
  124. data/lib/adhearsion/foundation/string.rb +0 -26
  125. data/lib/adhearsion/generators/app/templates/.ahnrc +0 -34
  126. data/lib/adhearsion/generators/app/templates/README +0 -8
  127. data/lib/adhearsion/generators/app/templates/components/ami_remote/ami_remote.rb +0 -15
  128. data/lib/adhearsion/generators/app/templates/components/disabled/HOW_TO_ENABLE +0 -7
  129. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/README.markdown +0 -47
  130. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.rb +0 -34
  131. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.yml +0 -12
  132. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/README.markdown +0 -3
  133. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.rb +0 -11
  134. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.yml +0 -0
  135. data/lib/adhearsion/generators/app/templates/config/startup.rb +0 -81
  136. data/lib/adhearsion/generators/app/templates/dialplan.rb +0 -3
  137. data/lib/adhearsion/generators/app/templates/events.rb +0 -33
  138. data/lib/adhearsion/host_definitions.rb +0 -67
  139. data/lib/adhearsion/initializer/asterisk.rb +0 -86
  140. data/lib/adhearsion/initializer/configuration.rb +0 -324
  141. data/lib/adhearsion/initializer/database.rb +0 -60
  142. data/lib/adhearsion/initializer/drb.rb +0 -31
  143. data/lib/adhearsion/initializer/freeswitch.rb +0 -22
  144. data/lib/adhearsion/initializer/ldap.rb +0 -57
  145. data/lib/adhearsion/initializer/rails.rb +0 -41
  146. data/lib/adhearsion/initializer/xmpp.rb +0 -42
  147. data/lib/adhearsion/tasks/components.rb +0 -32
  148. data/lib/adhearsion/tasks/database.rb +0 -5
  149. data/lib/adhearsion/tasks/deprecations.rb +0 -59
  150. data/lib/adhearsion/tasks/generating.rb +0 -20
  151. data/lib/adhearsion/tasks/lint.rb +0 -4
  152. data/lib/adhearsion/voip/asterisk.rb +0 -4
  153. data/lib/adhearsion/voip/asterisk/agi_server.rb +0 -121
  154. data/lib/adhearsion/voip/asterisk/commands.rb +0 -1966
  155. data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +0 -140
  156. data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +0 -102
  157. data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +0 -250
  158. data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +0 -240
  159. data/lib/adhearsion/voip/asterisk/config_manager.rb +0 -64
  160. data/lib/adhearsion/voip/asterisk/manager_interface.rb +0 -697
  161. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +0 -1681
  162. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +0 -341
  163. data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +0 -78
  164. data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +0 -87
  165. data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +0 -80
  166. data/lib/adhearsion/voip/call.rb +0 -521
  167. data/lib/adhearsion/voip/call_routing.rb +0 -64
  168. data/lib/adhearsion/voip/commands.rb +0 -17
  169. data/lib/adhearsion/voip/constants.rb +0 -39
  170. data/lib/adhearsion/voip/conveniences.rb +0 -18
  171. data/lib/adhearsion/voip/dial_plan.rb +0 -252
  172. data/lib/adhearsion/voip/dsl/dialing_dsl.rb +0 -151
  173. data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +0 -37
  174. data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +0 -27
  175. data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +0 -124
  176. data/lib/adhearsion/voip/dsl/dialplan/parser.rb +0 -69
  177. data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +0 -16
  178. data/lib/adhearsion/voip/dsl/numerical_string.rb +0 -128
  179. data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +0 -48
  180. data/lib/adhearsion/voip/freeswitch/event_handler.rb +0 -58
  181. data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +0 -129
  182. data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +0 -38
  183. data/lib/adhearsion/voip/freeswitch/oes_server.rb +0 -195
  184. data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +0 -80
  185. data/lib/adhearsion/voip/menu_state_machine/matchers.rb +0 -123
  186. data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +0 -57
  187. data/lib/adhearsion/xmpp/connection.rb +0 -61
  188. data/lib/theatre.rb +0 -147
  189. data/lib/theatre/README.markdown +0 -64
  190. data/lib/theatre/callback_definition_loader.rb +0 -86
  191. data/lib/theatre/guid.rb +0 -23
  192. data/lib/theatre/invocation.rb +0 -131
  193. data/lib/theatre/namespace_manager.rb +0 -153
  194. data/lib/theatre/version.rb +0 -2
  195. data/spec/adhearsion/cli_spec.rb +0 -306
  196. data/spec/adhearsion/component_manager_spec.rb +0 -292
  197. data/spec/adhearsion/constants_spec.rb +0 -8
  198. data/spec/adhearsion/drb_spec.rb +0 -65
  199. data/spec/adhearsion/fixtures/dialplan.rb +0 -3
  200. data/spec/adhearsion/foundation/event_socket_spec.rb +0 -168
  201. data/spec/adhearsion/host_definitions_spec.rb +0 -79
  202. data/spec/adhearsion/initializer/configuration_spec.rb +0 -291
  203. data/spec/adhearsion/initializer/loading_spec.rb +0 -154
  204. data/spec/adhearsion/initializer/paths_spec.rb +0 -74
  205. data/spec/adhearsion/relationship_properties_spec.rb +0 -54
  206. data/spec/adhearsion/voip/asterisk/agi_server_spec.rb +0 -473
  207. data/spec/adhearsion/voip/asterisk/ami/ami_spec.rb +0 -550
  208. data/spec/adhearsion/voip/asterisk/ami/lexer/ami_fixtures.yml +0 -30
  209. data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story +0 -291
  210. data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story.rb +0 -241
  211. data/spec/adhearsion/voip/asterisk/ami/lexer/story_helper.rb +0 -124
  212. data/spec/adhearsion/voip/asterisk/commands_spec.rb +0 -3241
  213. data/spec/adhearsion/voip/asterisk/config_file_generators/agents_spec.rb +0 -251
  214. data/spec/adhearsion/voip/asterisk/config_file_generators/queues_spec.rb +0 -323
  215. data/spec/adhearsion/voip/asterisk/config_file_generators/voicemail_spec.rb +0 -306
  216. data/spec/adhearsion/voip/asterisk/config_manager_spec.rb +0 -127
  217. data/spec/adhearsion/voip/asterisk/menu_command/calculated_match_spec.rb +0 -109
  218. data/spec/adhearsion/voip/asterisk/menu_command/matchers_spec.rb +0 -97
  219. data/spec/adhearsion/voip/call_routing_spec.rb +0 -125
  220. data/spec/adhearsion/voip/dialplan_manager_spec.rb +0 -468
  221. data/spec/adhearsion/voip/dsl/dialing_dsl_spec.rb +0 -270
  222. data/spec/adhearsion/voip/dsl/dispatcher_spec.rb +0 -82
  223. data/spec/adhearsion/voip/dsl/dispatcher_spec_helper.rb +0 -45
  224. data/spec/adhearsion/voip/dsl/parser_spec.rb +0 -69
  225. data/spec/adhearsion/voip/freeswitch/basic_connection_manager_spec.rb +0 -39
  226. data/spec/adhearsion/voip/freeswitch/inbound_connection_manager_spec.rb +0 -39
  227. data/spec/adhearsion/voip/freeswitch/oes_server_spec.rb +0 -9
  228. data/spec/adhearsion/voip/numerical_string_spec.rb +0 -61
  229. data/spec/adhearsion/voip/phone_number_spec.rb +0 -45
  230. data/spec/support/the_following_code.rb +0 -3
  231. data/spec/theatre/dsl_examples/simple_before_call.rb +0 -7
  232. data/spec/theatre/dsl_spec.rb +0 -69
  233. data/spec/theatre/invocation_spec.rb +0 -182
  234. data/spec/theatre/namespace_spec.rb +0 -125
  235. data/spec/theatre/spec_helper_spec.rb +0 -28
  236. data/spec/theatre/theatre_class_spec.rb +0 -148
@@ -1,270 +0,0 @@
1
- require 'spec_helper'
2
- require 'adhearsion/voip/dsl/dialing_dsl'
3
-
4
- # Keep the monkey patches in a module and load that into Regexp
5
- # eigenclasses during a before(:all) block?
6
-
7
- describe "RouteRule Regexp assembling" do
8
-
9
- it "should compile two Regexps" do
10
- first, last = /jay/, /phillips/
11
- r = first | last
12
- r.patterns.should == [first, last]
13
- end
14
-
15
- it "should compile three or more Regexps" do
16
- first, second, third = /lorem/, /ipsum/, /dolar/
17
- r = first | second | third
18
- r.patterns.should == [first, second, third]
19
- end
20
-
21
- end
22
-
23
- describe "RouteRule assembling with one provider definition" do
24
-
25
- before :each do
26
- @provider = Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new(:icanhascheezburger?)
27
- end
28
-
29
- it "should store one pattern properly" do
30
- pattern = /lorem/
31
- route = pattern >> @provider
32
- route.patterns.should == [pattern]
33
- end
34
-
35
- it "should store three patterns properly" do
36
- first, second, third = /lorem/, /ipsum/, /dolar/
37
- route = first | second | third >> @provider
38
- route.patterns.should == [first, second, third]
39
- route.providers.should == [@provider]
40
- end
41
-
42
- end
43
-
44
- describe "RouteRule assembling with multiple patterns and multiple provider definitions" do
45
-
46
- before(:each) do
47
- 1.upto 3 do |i|
48
- instance_variable_set "@prov_#{i}",
49
- Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new("prov_#{i}")
50
- instance_variable_set "@pattern_#{i}", /^#{i * 100}$/
51
- end
52
- end
53
-
54
- it "should store the patterns properly" do
55
- route_1 = @pattern_1 | @pattern_2 | @pattern_3 >> @prov_1 >> @prov_2 >> @prov_3
56
- route_1.patterns.should == [@pattern_1, @pattern_2, @pattern_3]
57
-
58
- route_2 = @pattern_2 | @pattern_3 | @pattern_1 >> @prov_3 >> @prov_2 >> @prov_1
59
- route_2.patterns.should == [@pattern_2, @pattern_3, @pattern_1]
60
- end
61
-
62
- it "should store the providers properly" do
63
- route_1 = @pattern_1 | @pattern_2 | @pattern_3 >> @prov_1 >> @prov_2 >> @prov_3
64
- route_1.providers.should == [@prov_1, @prov_2, @prov_3]
65
-
66
- route_2 = @pattern_2 | @pattern_3 | @pattern_1 >> @prov_3 >> @prov_2 >> @prov_1
67
- route_2.patterns.should == [@pattern_2, @pattern_3, @pattern_1]
68
- end
69
- end
70
-
71
- describe "The DialingDSL class internals" do
72
-
73
- it "should allow Asterisk-like patterns" do
74
- Adhearsion::VoIP::DSL::DialingDSL.class_eval do
75
- _('23XX')
76
- end.should be_an_instance_of Regexp
77
- end
78
-
79
- it "should define all of the VoIP constants" do
80
- lambda do
81
- Adhearsion::VoIP::Constants.constants.each do |constant|
82
- eval "Adhearsion::VoIP::DSL::DialingDSL::#{constant}"
83
- end
84
- end.should_not raise_error NameError
85
- end
86
-
87
- # it "should define a DUNDI constant"
88
-
89
- it "should synchronize access to the trunking information for Thread safety"
90
-
91
- end
92
-
93
- describe "The provider DSL's 'provider' macro" do
94
-
95
- it "should make the providers available in the order they were received" do
96
- provider_holder = Class.new Adhearsion::VoIP::DSL::DialingDSL
97
- provider_holder.class_eval do
98
- provider(:tweedledee) {}
99
- provider(:tweedledum) {}
100
- end
101
- provider_holder.providers.map { |x| x.name }.should == [:tweedledee, :tweedledum]
102
- end
103
- it "should define a singleton method for the provider name given" do
104
- dsl_class = Class.new(Adhearsion::VoIP::DSL::DialingDSL)
105
- dsl_class.class_eval do
106
- class_variable_get(:@@providers).size.should == 0
107
-
108
- provider(:icanhascheezburger?) {}
109
-
110
- class_variable_get(:@@providers).size.should == 1
111
- end
112
- dsl_class.should respond_to(:icanhascheezburger?)
113
- end
114
- it "should not define a class-wide method for the provider name given" do
115
- dsl_class = Class.new(Adhearsion::VoIP::DSL::DialingDSL)
116
- dsl_class.class_eval do
117
- provider(:icanhascheezburger?) {}
118
- end
119
- Adhearsion::VoIP::DSL::DialingDSL.class_eval do
120
- class_variable_defined?(:@@providers).should == false
121
- end
122
- Adhearsion::VoIP::DSL::DialingDSL.should_not respond_to(:icanhascheezburger?)
123
- end
124
- it "should yield a ProviderDefinition object" do
125
- possible_provider_definition = nil
126
- Class.new(Adhearsion::VoIP::DSL::DialingDSL).class_eval do
127
- provider(:blah) { |pd| possible_provider_definition = pd }
128
- end
129
- possible_provider_definition.should be_a_kind_of(Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition)
130
- end
131
- it "should raise an error when no block is given" do
132
- the_following_code do
133
- Class.new(Adhearsion::VoIP::DSL::DialingDSL).class_eval do
134
- provider :explode
135
- end
136
- end.should raise_error ArgumentError
137
- end
138
- end
139
-
140
- describe "The provider DSL's monkey patches to Regexp" do
141
- it "should return a RouteRule when using Regexp#| with another Regexp" do
142
- (// | //).should be_a_kind_of(Adhearsion::VoIP::DSL::DialingDSL::RouteRule)
143
- end
144
- it "should return a RouteRule when chaining three Regexp's with the | operator" do
145
- (// | // | //).should be_a_kind_of(Adhearsion::VoIP::DSL::DialingDSL::RouteRule)
146
- end
147
- it "should return a RouteRule when Regexp#| is given a RouteRule" do
148
- route_rule = Adhearsion::VoIP::DSL::DialingDSL::RouteRule.new :patterns => //
149
- (// | route_rule).should be_a_kind_of(Adhearsion::VoIP::DSL::DialingDSL::RouteRule)
150
- end
151
- it "should return a RouteRule when Regexp#>> is given a ProviderDefinition" do
152
- (/1/ >> Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new(:foo)).
153
- should be_a_kind_of(Adhearsion::VoIP::DSL::DialingDSL::RouteRule)
154
- end
155
- it "should return a RouteRule when Regexp#>>() receives a ProviderDefinition" do
156
- definition = Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new(:london)
157
- (/foo/ >> definition).should be_a_kind_of(Adhearsion::VoIP::DSL::DialingDSL::RouteRule)
158
- end
159
- it "should raise an exception when Regexp#| receives something other than a RouteRule" do
160
- bad_args = [ 0..100, 20, 45.55, {}, [] ]
161
- bad_args.each do |arg|
162
- the_following_code { /foo/ | arg }.should raise_error ArgumentError
163
- end
164
- end
165
- it "should raise an exception when Regexp#>>() receives anything other than a ProviderDefintion or RouteRule" do
166
- bad_args = [ 0..100, 20, 45.55, {}, [] ]
167
- bad_args.each do |arg|
168
- the_following_code { /foo/ >> arg }.should raise_error ArgumentError
169
- end
170
- end
171
- end
172
-
173
- describe "A RouteRule" do
174
- it "should expose chained ProviderDefinitions properly" do
175
- one, two, three = definitions = %w"foo bar qaz".map do |name|
176
- Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new name
177
- end
178
- route = /^911$/ >> one >> two >> three
179
- route.should be_a_kind_of(Adhearsion::VoIP::DSL::DialingDSL::RouteRule)
180
- route.providers.should == definitions
181
- end
182
- it "should define attr_readers for providers and patterns" do
183
- route = Adhearsion::VoIP::DSL::DialingDSL::RouteRule.new
184
- route.should respond_to(:patterns)
185
- route.should respond_to(:providers)
186
- end
187
- end
188
-
189
- describe "The provider order modifiers" do
190
- it "should support randomizing trunks", :ignore => true do
191
- dsl = Class.new Adhearsion::VoIP::DSL::DialingDSL
192
- dsl.class_eval do
193
- provider(:l33thost) {}
194
- provider(:h4xxhost) {}
195
- route /\d+\*548/ >> random(l33thost, h4xxhost)
196
- end
197
- dsl.routes.first.provider_definitions.first.should be_a_kind_of(
198
- Adhearsion::VoIP::DSL::DialingDSL::RandomRouteRule
199
- )
200
- end
201
- end
202
-
203
- describe "The provider DSL's 'route' builder" do
204
- it "should register routes in the order received" do
205
- dsl = Class.new Adhearsion::VoIP::DSL::DialingDSL
206
- dsl.class_eval do
207
- provider(:kewlphone) {}
208
- [/1?4445556666/, /123/, /\d+\*548/].each do |r|
209
- route r >> kewlphone
210
- end
211
- end
212
- dsl.routes.map { |x| x.patterns }.flatten.should == [/1?4445556666/, /123/, /\d+\*548/]
213
- end
214
- end
215
-
216
- describe "A ProviderDefinition" do
217
- it "should store any arbitrary property" do
218
- definition = Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new :foo
219
- definition.qaz = :something
220
- definition.qaz.should == :something
221
- end
222
- it "should define a >>() method" do
223
- Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new(:arghh).should respond_to(:>>)
224
- end
225
-
226
- it "should format numbers properly" do
227
- definition = Adhearsion::VoIP::DSL::DialingDSL::ProviderDefinition.new(:arghh)
228
- definition.protocol = "SIP"
229
- definition.format_number_for_platform("14445556666", :asterisk).should == "SIP/arghh/14445556666"
230
- definition.protocol = "SCCP"
231
- definition.format_number_for_platform("16663331111", :asterisk).should == "SCCP/arghh/16663331111"
232
-
233
- end
234
- end
235
-
236
- describe "Routing with the interpreted route definitions" do
237
- it "should use the first matching regular expression" do
238
- dsl = Class.new Adhearsion::VoIP::DSL::DialingDSL
239
- dsl.class_eval do
240
- provider(:bad) {}
241
- provider(:good) {}
242
- route /^111$/ | /^222$/ | /^333$/ >> good >> bad
243
- end
244
-
245
- found = dsl.calculate_routes_for(333)
246
-
247
- 1.should be found.size
248
- found.first.size.should be 2
249
- end
250
-
251
- end
252
-
253
- # @example = Class.new Adhearsion::VoIP::DSL::DialingDSL
254
- # @example.class_eval do
255
- #
256
- # provider:kewlphone do |trunk|
257
- # trunk.protocol :sip
258
- # trunk.host "voip.nufone.com"
259
- # trunk.username "phonedude"
260
- # trunk.password "secret"
261
- # trunk.enters :internal
262
- # end
263
- #
264
- # route US_NUMBER | US_LOCAL_NUMBER >> voip_ms >> nufone
265
- #
266
- # route INTL_NUMBER >> random(voip_ms, nufone)
267
- #
268
- # # route _('NXX') >> DUNDI
269
- #
270
- # end
@@ -1,82 +0,0 @@
1
- require File.dirname(__FILE__) + '/dispatcher_spec_helper'
2
- require 'adhearsion/voip/dsl/dialplan/dispatcher'
3
-
4
-
5
- describe "A EventCommand" do
6
-
7
- it "should allow a block that's set to response_block()" do
8
- block = lambda {}
9
- cmd = Adhearsion::VoIP::DSL::Dialplan::EventCommand.new "foo", &block
10
- cmd.response_block.should be(block)
11
- end
12
-
13
- it "should return specified return type with returns()" do
14
- return_type = Numeric
15
- cmd = Adhearsion::VoIP::DSL::Dialplan::EventCommand.new "foo", :returns => return_type
16
- cmd.returns.should be(return_type)
17
- end
18
-
19
- end
20
-
21
- describe "The abstract CommandDispatcher" do
22
-
23
- it "should make an attribute reader for context()" do
24
- context = "foo"
25
- d = Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher.new String, context
26
- d.context.should be(context)
27
- end
28
-
29
- it "should instantiate a new instance of the specified factory" do
30
- d = Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher.new Hash
31
- d.factory.should be_a_kind_of(Hash)
32
- end
33
-
34
- it "should pass the context to the factory when instantiating it" do
35
- context = "shazbot"
36
- klass = flexmock "a class that has one argument in its constructor"
37
- klass.should_receive(:new).with(context)
38
- d = Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher.new klass, context
39
- end
40
-
41
- it "should not allow calling dispatch!() directly" do
42
- dispatcher = Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher.new MyFactory
43
- lambda do
44
- dispatcher.dispatch! nil
45
- end.should raise_error(NotImplementedError)
46
- end
47
-
48
- it "should pass a method and any args onto its CommandFactory" do
49
-
50
- weird_args = [1, 2, ["foo", nil], Object.new, 12.3..13.4]
51
-
52
- bogus_command = Adhearsion::VoIP::DSL::Dialplan::EventCommand.new "123"
53
-
54
- dispatcher = NilDispatcher.new MyFactory
55
- flexmock(dispatcher.factory).should_receive(:monkey).with(*weird_args).and_return bogus_command
56
- dispatcher.monkey(*weird_args)
57
-
58
- end
59
-
60
- it "should continue executing response_blocks until nil is returned" do
61
- actual_executions, target_executions = 0, 5
62
- response = Adhearsion::VoIP::DSL::Dialplan::EventCommand.new "1" do |response|
63
- if response > target_executions
64
- nil
65
- else
66
- actual_executions += 1
67
- Adhearsion::VoIP::DSL::Dialplan::EventCommand.new(response + 1)
68
- end
69
- end
70
- mock_factory_class = Class.new do
71
- def initialize(*args)
72
- end
73
- def testplz
74
- response
75
- end
76
- end
77
- dispatcher = EvalDispatcher.new(mock_factory_class)
78
- flexmock(dispatcher.factory).should_receive(:testplz).and_return(response)
79
- dispatcher.testplz
80
- actual_executions.should be(target_executions)
81
- end
82
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'adhearsion/voip/dsl/dialplan/dispatcher'
4
-
5
- module StandardDispatcherBehavior
6
- def xtest_standard_dispatcher_behavior
7
- #"This it looks bogus. Not finished? Let's not check in failing specs ever if we can help it."
8
- returned_event_command = Adhearsion::VoIP::DSL::Dialplan::EventCommand.new "ilikesexypants"
9
- linking_event_command = Adhearsion::VoIP::DSL::Dialplan::EventCommand.new "ihavesexypants" do
10
- returned_event_command
11
- end
12
-
13
- dispatcher = @dispatcher_class.new MyFactory
14
- dispatcher.should_receive(:dispatch!).with(linking_event_command, returned_event_command).and_return(linking_event_command, returned_event_command)
15
- # returned_event_command.should_receive(:command_block).and_return nil
16
- dispatcher.dispatch! linking_event_command
17
- end
18
- end
19
-
20
- class NilDispatcher < Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher
21
- def dispatch!(string)
22
- # Would send it off to the PBX here (or prepend something to the String)
23
- end
24
- end
25
-
26
- class EvalDispatcher < Adhearsion::VoIP::DSL::Dialplan::CommandDispatcher
27
- def dispatch!(event)
28
- eval event.app.to_s
29
- end
30
- end
31
-
32
- class MyFactory
33
-
34
- def initialize(context)
35
- @context = context
36
- end
37
-
38
- def sequence
39
- all = []
40
- EventCommand.new("2", :response => Numeric) do |response|
41
- all << response
42
- all.size > 3 ? all : nil
43
- end
44
- end
45
- end
@@ -1,69 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'adhearsion/voip/dsl/dialplan/parser'
4
-
5
- describe "The Adhearsion VoIP dialplan parser" do
6
-
7
- it "should return a list of dialplans properly from dialplan code" do
8
- file = "foobar.rb"
9
- flexstub(Adhearsion::AHN_CONFIG).should_receive(:files_from_setting).once.with("paths", "dialplan").and_return [file]
10
-
11
- flexmock(File).should_receive(:exists?).with(file).and_return true
12
- flexmock(File).should_receive(:read).once.with(file).and_return <<-DIALPLAN
13
- internal {
14
- play "hello-world"
15
- }
16
- monkeys {
17
- play "tt-monkeys"
18
- }
19
- DIALPLAN
20
- contexts = Adhearsion::VoIP::DSL::Dialplan::DialplanParser.get_contexts
21
- contexts.keys.size.should be(2)
22
- contexts.keys.should include(:internal)
23
- contexts.keys.should include(:monkeys)
24
- contexts.each_pair do |context, struct|
25
- struct.should be_a_kind_of(OpenStruct)
26
- %w"file name block".each do |method|
27
- struct.should respond_to(method)
28
- end
29
- end
30
- end
31
-
32
- it "should warn when no dialplan paths were in the .ahnrc file" do
33
- flexmock(Adhearsion::AHN_CONFIG).should_receive(:files_from_setting).once.with("paths", "dialplan").and_return []
34
- flexmock(ahn_log.dialplan).should_receive(:warn).once.with(String)
35
-
36
- # Not loading it here is the same as it not existing in the "paths" sub-Hash
37
- Adhearsion::VoIP::DSL::Dialplan::DialplanParser.get_contexts
38
- end
39
-
40
- end
41
-
42
- describe "The Adhearsion VoIP dialplan interpreter" do
43
-
44
- it "should make dialplan contexts available within the context's block" do
45
- file = "contexts_from_code_helper_pseudo_dialplan.rb"
46
- flexstub(Adhearsion::AHN_CONFIG).should_receive(:files_from_setting).once.with("paths", "dialplan").and_return [file]
47
-
48
- flexmock(File).should_receive(:exists?).with(file).and_return true
49
- flexmock(File).should_receive(:read).with(file).and_return "foo { cool_method }"
50
-
51
- contexts = Adhearsion::VoIP::DSL::Dialplan::DialplanParser.get_contexts
52
-
53
- contexts.each_pair do |name, struct|
54
- contexts.meta_def(name) { struct.code }
55
- end
56
-
57
- # Simulate incoming request
58
- contexts = contexts.clone
59
-
60
- call_variables = { "callerid" => "14445556666", "context" => "foo" }
61
-
62
- call_variables.each_pair do |key, value|
63
- contexts.meta_def(key) { value }
64
- contexts.instance_variable_set "@#{key}", value
65
- end
66
-
67
- end
68
-
69
- end