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
@@ -0,0 +1,308 @@
1
+ require 'spec_helper'
2
+
3
+ describe Adhearsion::Configuration do
4
+
5
+ describe "when initializing the config instance" do
6
+ subject do
7
+ Adhearsion::Configuration.new
8
+ end
9
+
10
+ it "should have an empty configuration for the platform" do
11
+ subject.should respond_to :platform
12
+ end
13
+
14
+ it "should have a platform configuration object" do
15
+ subject.platform.should be_instance_of Loquacious::Configuration
16
+ end
17
+
18
+ it "should initialize root to nil" do
19
+ subject.platform.root.should be_nil
20
+ end
21
+
22
+ it "should initialize logging to level info" do
23
+ subject.platform.logging.level.should == :info
24
+ end
25
+
26
+ it "should allow to update a config value" do
27
+ subject.platform.automatically_accept_incoming_calls.should == true
28
+ subject.platform.automatically_accept_incoming_calls = false
29
+ subject.platform.automatically_accept_incoming_calls.should == false
30
+ end
31
+
32
+ it "should allow to create new config values" do
33
+ subject.platform.bar = "foo"
34
+ subject.platform.bar.should == "foo"
35
+ end
36
+ end
37
+
38
+ describe "when initializing the config instance with specific values" do
39
+ subject do
40
+ Adhearsion::Configuration.new do
41
+ root "foo", :desc => "Adhearsion application root folder"
42
+ automatically_accept_incoming_calls false, :desc => "Adhearsion will not accept automatically any inbound call"
43
+ end
44
+ end
45
+
46
+ it "should return the root value" do
47
+ subject.platform.root.should == "foo"
48
+ end
49
+
50
+ it "should return the automatically_accept_incoming_calls value" do
51
+ subject.platform.automatically_accept_incoming_calls.should == false
52
+ end
53
+
54
+ it "should return a description for the platform configuration" do
55
+ Adhearsion.config.description(:platform).should be_instance_of String
56
+ end
57
+
58
+ it "should allow to update a config value" do
59
+ subject.platform.automatically_accept_incoming_calls.should == false
60
+ subject.platform.automatically_accept_incoming_calls = true
61
+ subject.platform.automatically_accept_incoming_calls.should == true
62
+ end
63
+
64
+ it "should allow to create new config values" do
65
+ subject.platform.bar = "bazz"
66
+ subject.platform.bar.should == "bazz"
67
+ end
68
+ end
69
+
70
+ describe "when configuring a non existing object" do
71
+ it "should raise a ConfigurationError" do
72
+ lambda {
73
+ Adhearsion.config.foo.bar = "bazz"
74
+ }.should raise_error Adhearsion::ConfigurationError, "Invalid plugin foo"
75
+ end
76
+ end
77
+
78
+ describe "when accessing the platform configuration" do
79
+ after do
80
+ Adhearsion.config = nil
81
+ end
82
+
83
+ subject{ Adhearsion.config[:platform] }
84
+
85
+ it "should return the valid platform configuration object" do
86
+ subject.should be_instance_of ::Loquacious::Configuration
87
+ end
88
+
89
+ it "should allow to retrieve any platform configuration value" do
90
+ subject.automatically_accept_incoming_calls.should == true
91
+ end
92
+
93
+ describe "if configuration has a named environment" do
94
+
95
+ let :config_obj do
96
+ Adhearsion::Configuration.new
97
+ end
98
+
99
+ let :env_values do
100
+ config_obj.valid_environments.inject({}) do |hash, k|
101
+ hash[k] = hash.keys.length
102
+ hash
103
+ end
104
+ end
105
+
106
+ let :config_object do
107
+ config = config_obj do
108
+ my_level -1, :desc => "An index to check the environment value is being retrieved"
109
+ end
110
+ end
111
+
112
+ subject do
113
+ config_object.production do |env|
114
+ env.platform.my_level = 0
115
+ end
116
+ config_object.development do |env|
117
+ env.platform.my_level = 1
118
+ end
119
+ config_object.staging do |env|
120
+ env.platform.my_level = 2
121
+ end
122
+ config_object.test do |env|
123
+ env.platform.my_level = 3
124
+ end
125
+ config_object
126
+ end
127
+
128
+ it "should return by default the development value" do
129
+ subject.platform.my_level.should == 1
130
+ end
131
+
132
+ [:staging, :production, :test].each do |env|
133
+ it "should return the #{env.to_s} value when environment set to #{env.to_s}" do
134
+ config_object.platform.environment = env
135
+ subject.platform.my_level.should == env_values[env]
136
+ end
137
+ end
138
+ end
139
+ end
140
+
141
+ describe "while defining the environment" do
142
+
143
+ after do
144
+ ENV['AHN_ENV'] = nil
145
+ Adhearsion.config = nil
146
+ end
147
+
148
+ it "should return 'development' by default" do
149
+ Adhearsion.config.platform.environment.should == :development
150
+ end
151
+
152
+ [:development, :production, :staging, :test].each do |env|
153
+ it "should respond to #{env.to_s}" do
154
+ Adhearsion.config.should respond_to(env)
155
+ end
156
+ end
157
+
158
+ context "when the ENV value is valid" do
159
+ [:production, :staging, :test].each do |env|
160
+ it "should override the environment value with #{env.to_s} when set in ENV value" do
161
+ ENV['AHN_ENV'] = env.to_s
162
+ Adhearsion.config.platform.environment.should == env.to_s
163
+ end
164
+ end
165
+ end
166
+
167
+ it "should not override the default environment with the ENV value if valid" do
168
+ ENV['AHN_ENV'] = "invalid_value"
169
+ Adhearsion.config.platform.environment.should == :development
170
+ end
171
+
172
+ it "should allow to add a new environment" do
173
+ Adhearsion.config.valid_environment?(:another_environment).should == false
174
+ Adhearsion.environments << :another_environment
175
+ Adhearsion.config.valid_environment?(:another_environment).should == true
176
+ end
177
+
178
+ end
179
+
180
+ describe "while retrieving configuration descriptions" do
181
+ before do
182
+ Adhearsion.config = nil
183
+ end
184
+
185
+ subject { Adhearsion.config }
186
+
187
+ it "should retrieve a string with the platform configuration" do
188
+ desc = subject.description :platform, :show_values => false
189
+ desc.length.should > 0
190
+ desc.should match /^.*automatically_accept_incoming_calls.*$/
191
+ desc.should match /^.*root.*$/
192
+ end
193
+
194
+ it "should retrieve a string with the platform configuration and values" do
195
+ desc = subject.description :platform
196
+ desc.length.should > 0
197
+ desc.should match /^.*automatically_accept_incoming_calls.*true.*$/
198
+ desc.should match /^.*root.*$/
199
+ end
200
+
201
+ describe "if there are plugins installed" do
202
+ before do
203
+ Adhearsion::Logging.silence!
204
+
205
+ Class.new Adhearsion::Plugin do
206
+ config :my_plugin do
207
+ name "user" , :desc => "name to authenticate user"
208
+ password "password" , :desc => "authentication password"
209
+ host "localhost", :desc => "valid IP or hostname"
210
+ end
211
+ end
212
+ end
213
+
214
+ describe "retrieving configuration for the plugin" do
215
+ context "via a method" do
216
+ subject { Adhearsion.config.my_plugin }
217
+
218
+ it "should have the correct values" do
219
+ subject[:name].should == 'user'
220
+ subject[:password].should == 'password'
221
+ subject[:host].should == 'localhost'
222
+ end
223
+ end
224
+
225
+ context "using the hash accessor syntax" do
226
+ subject { Adhearsion.config[:my_plugin] }
227
+
228
+ it "should have the correct values" do
229
+ subject[:name].should == 'user'
230
+ subject[:password].should == 'password'
231
+ subject[:host].should == 'localhost'
232
+ end
233
+ end
234
+
235
+ context "when config has named environments" do
236
+ subject do
237
+ Adhearsion.config do |c|
238
+ c.production do |env|
239
+ env.my_plugin.name = "production"
240
+ end
241
+ c.development do |env|
242
+ env.my_plugin.name = "development"
243
+ end
244
+ c.staging do |env|
245
+ env.my_plugin.name = "staging"
246
+ end
247
+ c.test do |env|
248
+ env.my_plugin.name = "test"
249
+ end
250
+ end
251
+ Adhearsion.config[:my_plugin]
252
+ end
253
+
254
+ it "should return the development value by default" do
255
+ Adhearsion.config # initialize
256
+ subject.name.should == "development"
257
+ end
258
+
259
+ [:development, :staging, :production, :test].each do |env|
260
+ it "should return the #{env.to_s} value when environment is set to #{env.to_s}" do
261
+ Adhearsion.config.platform.environment = env
262
+ subject.name.should == env.to_s
263
+ end
264
+ end
265
+ end
266
+ end
267
+
268
+ it "should retrieve a valid plugin description" do
269
+ desc = subject.description :my_plugin
270
+ desc.length.should > 0
271
+ desc.should match /^.*name.*user.*$/
272
+ desc.should match /^.*password.*password.*$/
273
+ desc.should match /^.*host.*localhost.*$/
274
+ end
275
+
276
+ it "should retrieve a valid plugin description with no values" do
277
+ desc = subject.description :my_plugin, :show_values => false
278
+ desc.length.should > 0
279
+ desc.should match /^.*name.*$/
280
+ desc.should match /^.*password.*$/
281
+ desc.should match /^.*host.*$/
282
+ end
283
+
284
+ it "should retrieve both platform and plugin configuration" do
285
+ desc = subject.description :all
286
+ desc.length.should > 0
287
+ desc.should match /^.*automatically_accept_incoming_calls.*true.*$/
288
+ desc.should match /^.*root.*$/
289
+ desc.should match /^.*name.*user.*$/
290
+ desc.should match /^.*password.*password.*$/
291
+ desc.should match /^.*host.*localhost.*$/
292
+ end
293
+
294
+ it "should retrieve both platform and plugin configuration with no values" do
295
+ desc = subject.description :all, :show_values => false
296
+ desc.length.should > 0
297
+ desc.should match /^.*Configuration for platform.*$/
298
+ desc.should match /^.*automatically_accept_incoming_calls.*$/
299
+ desc.should match /^.*root.*$/
300
+ desc.should match /^.*Configuration for my_plugin.*$/
301
+ desc.should match /^.*name.*$/
302
+ desc.should match /^.*password.*$/
303
+ desc.should match /^.*host.*$/
304
+ end
305
+ end
306
+
307
+ end
308
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ module Adhearsion
4
+ describe DialplanController do
5
+ include CallControllerTestHelpers
6
+
7
+ it { should be_a DialplanController }
8
+ it { should be_a CallController }
9
+
10
+ let :dialplan do
11
+ Proc.new { foo value }
12
+ end
13
+
14
+ before { subject.dialplan = dialplan }
15
+
16
+ its(:dialplan) { should be dialplan }
17
+
18
+ describe "running" do
19
+ it "should execute the dialplan in the context of the controller" do
20
+ flexmock subject, :value => :bar
21
+ subject.should_receive(:foo).once.with(:bar)
22
+ subject.run
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ module Adhearsion
4
+ describe Events do
5
+
6
+ EventClass = Class.new
7
+ ExceptionClass = Class.new StandardError
8
+
9
+ before do
10
+ Events.refresh!
11
+ end
12
+
13
+ it "should have a GirlFriday::Queue to handle events" do
14
+ Events.queue.should be_a GirlFriday::WorkQueue
15
+ end
16
+
17
+ it "should allow adding events to the queue and handle them appropriately" do
18
+ t = nil
19
+ o = nil
20
+ latch = CountDownLatch.new 1
21
+
22
+ flexmock(Events.instance).should_receive(:handle_message).and_return do |message|
23
+ t = message.type
24
+ o = message.object
25
+ latch.countdown!
26
+ end
27
+
28
+ Events.trigger :event, :foo
29
+
30
+ latch.wait(2).should be_true
31
+ t.should == :event
32
+ o.should == :foo
33
+ end
34
+
35
+ it "should allow executing events immediately" do
36
+ t = nil
37
+ o = nil
38
+
39
+ flexmock(Events.instance).should_receive(:handle_message).and_return do |message|
40
+ sleep 0.25
41
+ t = message.type
42
+ o = message.object
43
+ end
44
+
45
+ Events.trigger_immediately :event, :foo
46
+
47
+ t.should == :event
48
+ o.should == :foo
49
+ end
50
+
51
+ it "should handle events using registered guarded handlers" do
52
+ result = nil
53
+
54
+ Events.register_handler :event, EventClass do |event|
55
+ result = :foo
56
+ end
57
+
58
+ Events.trigger_immediately :event, EventClass.new
59
+
60
+ result.should == :foo
61
+
62
+ Events.clear_handlers :event, EventClass
63
+ end
64
+
65
+ it "should handle exceptions in event processing by raising the exception as an event" do
66
+ flexmock(Events.instance).should_receive(:trigger).with(:exception, ExceptionClass).once
67
+
68
+ Events.register_handler :event, EventClass do |event|
69
+ raise ExceptionClass
70
+ end
71
+
72
+ Events.trigger_immediately :event, EventClass.new
73
+ Events.clear_handlers :event, EventClass
74
+ end
75
+
76
+ it "should implicitly pass on all handlers" do
77
+ result = nil
78
+
79
+ Events.register_handler :event, EventClass do |event|
80
+ result = :foo
81
+ end
82
+
83
+ Events.register_handler :event, EventClass do |event|
84
+ result = :bar
85
+ end
86
+
87
+ Events.trigger_immediately :event, EventClass.new
88
+
89
+ result.should == :bar
90
+
91
+ Events.clear_handlers :event, EventClass
92
+ end
93
+
94
+ describe '#draw' do
95
+ it "should allow registering handlers by type" do
96
+ result = nil
97
+ Events.draw do
98
+ event do
99
+ result = :foo
100
+ end
101
+ end
102
+
103
+ Events.trigger_immediately :event
104
+
105
+ result.should == :foo
106
+
107
+ Events.clear_handlers :event
108
+ end
109
+ end
110
+
111
+ end
112
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Adhearsion::Initializer::Logging do
4
+
5
+ before do
6
+ Adhearsion::Initializer::Logging.start
7
+ end
8
+
9
+ after do
10
+ Adhearsion::Logging.reset
11
+ end
12
+
13
+ after(:all) do
14
+ Adhearsion::Initializer::Logging.start
15
+ Adhearsion::Logging.silence!
16
+ end
17
+
18
+ it "initializes properly a Logging object" do
19
+ ::Logging.logger.root.appenders.length.should eql(1)
20
+ ::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::Stdout)}.length.should eql(1)
21
+ end
22
+
23
+ it 'should created the predefined set of log levels' do
24
+ ::Logging::LEVELS.length.should eql(Adhearsion::Logging::LOG_LEVELS.length)
25
+ end
26
+
27
+ it "initializes properly a Logging object with appenders as parameter" do
28
+ Adhearsion::Initializer::Logging.start([::Logging.appenders.stdout, ::Logging.appenders.file('example.log')])
29
+ ::Logging.logger.root.appenders.length.should eql(2)
30
+ ::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::Stdout)}.length.should eql(1)
31
+ ::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::File)}.length.should eql(1)
32
+ end
33
+
34
+ it "initializes properly a Logging object with appenders and log level as parameter" do
35
+ Adhearsion::Initializer::Logging.start([::Logging.appenders.stdout, ::Logging.appenders.file('example.log')], :debug)
36
+ ::Logging.logger.root.appenders.length.should eql(2)
37
+ ::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::Stdout)}.length.should eql(1)
38
+ ::Logging.logger.root.appenders.select{|a| a.is_a?(::Logging::Appenders::File)}.length.should eql(1)
39
+ ::Logging.logger.root.level.should eql(::Logging::LEVELS["debug"])
40
+ end
41
+
42
+ Foo = Class.new
43
+ Foo::Bar = Class.new Foo
44
+
45
+ it "should create only a Logging object per Class (reuse per all the instances)" do
46
+ _logger = Foo.new.logger
47
+ 10.times do
48
+ Foo.new.logger.object_id.should eql(_logger.object_id)
49
+ end
50
+ end
51
+
52
+ it "should reuse a Logging instance in all Class instances but not with child instances" do
53
+ _foo_logger = Foo.new.logger
54
+ _bar_logger = Foo::Bar.new.logger
55
+ _foo_logger.object_id.should_not eql(_bar_logger)
56
+ end
57
+
58
+ end