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,163 +1,250 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Adhearsion::Initializer" do
3
+ describe Adhearsion::Initializer do
4
4
 
5
5
  include InitializerStubs
6
6
  # TODO: create a specification for aliases
7
7
 
8
- before :each do
9
- Adhearsion.send(:remove_const, 'AHN_CONFIG') if Adhearsion.const_defined? 'AHN_CONFIG'
10
- Adhearsion::AHN_CONFIG = Adhearsion::Configuration.new
11
- end
8
+ let(:path) { "#{Dir.pwd}/" }
12
9
 
13
- after :each do
14
- Adhearsion::Events.reinitialize_theatre!
15
- end
10
+ describe "#start" do
11
+ before do
12
+ Adhearsion::Logging.reset
13
+ flexmock(Adhearsion::Initializer::Logging).should_receive(:start).once.and_return('')
14
+ flexmock(::Logging::Appenders::File).should_receive(:assert_valid_logfile).and_return(true)
15
+ flexmock(::Logging::Appenders).should_receive(:file).and_return(nil)
16
+ Adhearsion.config = nil
17
+ end
16
18
 
17
- it "initialization will start with only a path given" do
18
- stub_behavior_for_initializer_with_no_path_changing_behavior do
19
- Adhearsion::Initializer.start path
19
+ after do
20
+ Adhearsion::Events.reinitialize_queue!
20
21
  end
21
- end
22
22
 
23
- it "should create a pid file in the app's path when given 'true' as the pid_file hash key argument" do
24
- stub_behavior_for_initializer_with_no_path_changing_behavior do
25
- flexmock(File).should_receive(:open).with(File.join(path, 'adhearsion.pid'), 'w', Proc).at_least.once
26
- ahn = Adhearsion::Initializer.start path, :pid_file => true
27
- ahn.pid_file[0, path.length].should == path
23
+ after :all do
24
+ Adhearsion::Logging.reset
25
+ Adhearsion::Initializer::Logging.start
26
+ Adhearsion::Logging.silence!
28
27
  end
29
- end
30
28
 
31
- it "should NOT create a pid file in the app's path when given 'false' as the pid_file hash key argument" do
32
- stub_behavior_for_initializer_with_no_path_changing_behavior do
33
- ahn = Adhearsion::Initializer.start path, :pid_file => false
34
- ahn.pid_file.should be nil
29
+ it "initialization will start with no options" do
30
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
31
+ Adhearsion::Initializer.start
32
+ end
35
33
  end
36
- end
37
34
 
38
- it "should create a pid file in the app's path by default when daemonizing" do
39
- stub_behavior_for_initializer_with_no_path_changing_behavior do
40
- flexmock(File).should_receive(:open).once.with(File.join(path, 'adhearsion.pid'), 'w', Proc)
41
- ahn = Adhearsion::Initializer.start path, :mode => :daemon
42
- ahn.pid_file[0, path.size].should == path
35
+ it "should create a pid file in the app's path when given 'true' as the pid_file hash key argument" do
36
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
37
+ flexmock(File).should_receive(:open).with(File.join(path, 'adhearsion.pid'), 'w', Proc).at_least.once
38
+ ahn = Adhearsion::Initializer.start :pid_file => true
39
+ ahn.pid_file[0, path.length].should == path
40
+ end
43
41
  end
44
- end
45
42
 
46
- it "should NOT create a pid file in the app's path when daemonizing and :pid_file is given as false" do
47
- stub_behavior_for_initializer_with_no_path_changing_behavior do
48
- ahn = Adhearsion::Initializer.start path, :daemon => true, :pid_file => false
49
- ahn.pid_file.should be nil
43
+ it "should NOT create a pid file in the app's path when given 'false' as the pid_file hash key argument" do
44
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
45
+ ahn = Adhearsion::Initializer.start :pid_file => false
46
+ ahn.pid_file.should be nil
47
+ end
50
48
  end
51
- end
52
49
 
53
- it "should execute gem when .ahnrc contains gem names" do
54
- stub_behavior_for_initializer_with_no_path_changing_behavior do
55
- ahn_rc = {
56
- "gems" => {
57
- "activerecord" => { "version" => ">= 1.2.0" },
58
- "twitter" => nil
59
- },
60
- # Paths are unnecessary except to make the other part of bootstrap_rc happy.
61
- "paths"=>{"dialplan"=>"dialplan.rb", "init"=>"config/startup.rb", "events"=>"events.rb",
62
- "models"=> "models/*.rb"}
63
- }
64
- ahn = Adhearsion::Initializer.new path
65
- flexmock(Adhearsion::Initializer).should_receive(:get_rules_from).once.and_return ahn_rc
66
- flexmock(ahn).should_receive(:gem).once.with("activerecord", ">= 1.2.0")
67
- flexmock(ahn).should_receive(:gem).once.with("twitter")
68
- ahn.start
50
+ it "should create a pid file in the app's path by default when daemonizing" do
51
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
52
+ flexmock(File).should_receive(:open).once.with(File.join(path, 'adhearsion.pid'), 'w', Proc)
53
+ ahn = Adhearsion::Initializer.start :mode => :daemon
54
+ ahn.pid_file[0, path.size].should == path
55
+ end
69
56
  end
70
- end
71
57
 
72
- it "should require() the lib when .ahnrc contains a require section with one name" do
73
- stub_behavior_for_initializer_with_no_path_changing_behavior do
74
- ahn_rc = {
75
- "gems" => {
76
- "twitter" => {
77
- "require" => "sometwitterstuffs"
78
- }
79
- },
80
- # Paths are unnecessary except to make the other part of bootstrap_rc happy.
81
- "paths"=>{"dialplan"=>"dialplan.rb", "init"=>"config/startup.rb", "events"=>"events.rb",
82
- "models"=>"models/*.rb"}
83
- }
84
- ahn = Adhearsion::Initializer.new path
85
- flexmock(Adhearsion::Initializer).should_receive(:get_rules_from).once.and_return ahn_rc
86
- flexstub(ahn).should_receive(:gem).once.with("twitter")
87
- flexmock(ahn).should_receive(:require).once.with("sometwitterstuffs")
88
- flexmock(ahn).should_receive(:require).at_least.once.with(String)
89
- ahn.start
58
+ it "should NOT create a pid file in the app's path when daemonizing and :pid_file is given as false" do
59
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
60
+ ahn = Adhearsion::Initializer.start :daemon => true, :pid_file => false
61
+ ahn.pid_file.should be nil
62
+ end
90
63
  end
91
- end
92
64
 
93
- it "should create a designated pid file when supplied a String path as :pid_file" do
94
- random_file = "/tmp/AHN_TEST_#{rand 100000}.pid"
95
- stub_behavior_for_initializer_with_no_path_changing_behavior do
96
- ahn = Adhearsion::Initializer.start path, :pid_file => random_file
97
- ahn.pid_file.should be(random_file)
98
- File.exists?(random_file).should be true
99
- File.delete random_file
65
+ it "should create a designated pid file when supplied a String path as :pid_file" do
66
+ random_file = "/tmp/AHN_TEST_#{rand 100000}.pid"
67
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
68
+ ahn = Adhearsion::Initializer.start :pid_file => random_file
69
+ ahn.pid_file.should == random_file
70
+ File.exists?(random_file).should be true
71
+ File.delete random_file
72
+ end
73
+ end
74
+
75
+ it "should resolve the log file path to daemonize" do
76
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
77
+ flexmock(File).should_receive(:open).with(File.join(path, 'adhearsion.pid'), 'w', Proc).at_least.once
78
+ ahn = Adhearsion::Initializer.start :pid_file => true
79
+ ahn.resolve_log_file_path.should == path + Adhearsion.config.platform.logging.outputters[0]
80
+ end
81
+ end
82
+
83
+ it "should resolve the log file path to daemonize when outputters is an Array" do
84
+ Adhearsion.config.platform.logging.outputters = ["log/my_application.log", "log/adhearsion.log"]
85
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
86
+ flexmock(File).should_receive(:open).with(File.join(path, 'adhearsion.pid'), 'w', Proc).at_least.once
87
+ ahn = Adhearsion::Initializer.start :pid_file => true
88
+ ahn.resolve_log_file_path.should == path + Adhearsion.config.platform.logging.outputters[0]
89
+ end
90
+ end
91
+
92
+ it "should return a valid appenders array" do
93
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
94
+ flexmock(File).should_receive(:open).with(File.join(path, 'adhearsion.pid'), 'w', Proc).at_least.once
95
+ ahn = Adhearsion::Initializer.start :pid_file => true
96
+ appenders = ahn.init_get_logging_appenders
97
+ appenders.should have(2).items
98
+ appenders[1].should be_instance_of Logging::Appenders::Stdout
99
+ end
100
+ end
101
+
102
+ it "should initialize properly the log paths" do
103
+ ahn = stub_behavior_for_initializer_with_no_path_changing_behavior do
104
+ flexmock(File).should_receive(:open).with(File.join(path, 'adhearsion.pid'), 'w', Proc).at_least.once
105
+ Adhearsion::Initializer.start :pid_file => true
106
+ end
107
+ flexmock(Dir).should_receive(:mkdir).with("log/")
108
+ ahn.initialize_log_paths
109
+ end
110
+
111
+ it "should initialize properly the log paths when outputters is an array" do
112
+ Adhearsion.config.platform.logging.outputters = ["log/my_application.log", "log/test/adhearsion.log"]
113
+ ahn = stub_behavior_for_initializer_with_no_path_changing_behavior do
114
+ flexmock(File).should_receive(:open).with(File.join(path, 'adhearsion.pid'), 'w', Proc).at_least.once
115
+ Adhearsion::Initializer.start :pid_file => true
116
+ end
117
+ flexmock(Dir).should_receive(:mkdir).with("log/").twice
118
+ flexmock(Dir).should_receive(:mkdir).with("log/test/").once
119
+ ahn.initialize_log_paths
100
120
  end
101
121
  end
102
122
 
103
- it "should initialze events properly" do
104
- require 'theatre'
105
- events_rb = Tempfile.new "events.rb"
106
- initializer = Adhearsion::Initializer.new("/does/not/matter")
107
- flexmock(Adhearsion::AHN_CONFIG).should_receive(:files_from_setting).at_least.once.with("paths", "events").
108
- and_return([events_rb.path])
109
- flexmock(Adhearsion::Events.framework_theatre).should_receive(:load_events_file).once.with events_rb.path
110
- flexmock(Adhearsion::Events.framework_theatre).should_receive(:start!).once
111
-
112
- initializer.send :init_events_subsystem
113
- initializer.send :init_events_file
123
+ describe "Initializing logger" do
124
+ before do
125
+ Adhearsion::Logging.reset
126
+ flexmock(::Logging::Appenders::File).should_receive(:assert_valid_logfile).and_return(true)
127
+ flexmock(::Logging::Appenders).should_receive(:file).and_return(nil)
128
+ Adhearsion.config = nil
129
+ end
130
+
131
+ after :all do
132
+ Adhearsion::Logging.reset
133
+ Adhearsion::Initializer::Logging.start
134
+ Adhearsion::Logging.silence!
135
+ Adhearsion::Events.reinitialize_queue!
136
+ end
137
+
138
+ it "should start logging with valid parameters" do
139
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
140
+ flexmock(File).should_receive(:open).with(File.join(path, 'adhearsion.pid'), 'w', Proc).at_least.once
141
+ flexmock(Adhearsion::Initializer::Logging).should_receive(:start).once.with(Array, :info, nil).and_return('')
142
+ Adhearsion::Initializer.start :pid_file => true
143
+ end
144
+ end
114
145
  end
115
146
 
116
- private
117
- def path
118
- '/any/ole/path'
147
+ describe "#load_lib_folder" do
148
+ before do
149
+ Adhearsion.ahn_root = path
150
+ end
151
+
152
+ it "should load the contents of lib directory" do
153
+ flexmock(Dir).should_receive(:chdir).with(File.join(path, "lib"), Proc).and_return []
154
+ Adhearsion::Initializer.new.load_lib_folder
155
+ end
156
+
157
+ it "should return false if folder does not exist" do
158
+ Adhearsion.config.platform.lib = "my_random_lib_directory"
159
+ Adhearsion::Initializer.new.load_lib_folder.should == false
160
+ end
161
+
162
+ it "should return false and not load any file if config folder is set to nil" do
163
+ Adhearsion.config.platform.lib = nil
164
+ Adhearsion::Initializer.new.load_lib_folder.should == false
119
165
  end
166
+
167
+ it "should load the contents of the preconfigured directory" do
168
+ Adhearsion.config.platform.lib = "foo"
169
+ flexmock(Dir).should_receive(:chdir).with("/any/ole/path/foo", Proc).and_return []
170
+ Adhearsion::Initializer.new.load_lib_folder
171
+ end
172
+ end
120
173
  end
121
174
 
122
- describe "AHN_ROOT" do
175
+ describe "Updating RAILS_ENV variable" do
123
176
  include InitializerStubs
124
- before(:each) do
125
- Object.send(:remove_const, :AHN_ROOT) if defined? AHN_ROOT
126
- end
127
177
 
128
- it "initializing will create the AHN_ROOT" do
129
- stub_behavior_for_initializer_with_no_path_changing_behavior do
130
- ahn = Adhearsion::Initializer.start path
131
- Object.constants.map(&:to_s).include?("AHN_ROOT").should be true
132
- end
178
+ before do
179
+ Adhearsion::Logging.reset
180
+ flexmock(Adhearsion::Initializer::Logging).should_receive(:start).once.and_return('')
181
+ flexmock(::Logging::Appenders::File).should_receive(:assert_valid_logfile).and_return(true)
182
+ flexmock(::Logging::Appenders).should_receive(:file).and_return(nil)
183
+ Adhearsion.config = nil
133
184
  end
134
185
 
135
- it "swapping out the base_path for the duration of the block" do
136
- original_base_path = '.'
137
- temporary_base = '/foo'
186
+ after do
187
+ ENV['RAILS_ENV'] = nil
188
+ end
138
189
 
139
- path = Adhearsion::PathString.new(original_base_path)
140
- path.should == original_base_path
190
+ describe "when neither RAILS_ENV nor AHN_ENV are set" do
191
+ [:development, :production, :staging, :test].each do |env|
192
+ it "should set the RAILS_ENV to #{env.to_s} when Adhearsion environment is set to #{env.to_s}" do
193
+ ahn = nil
194
+ stub_behavior_for_initializer_with_no_path_changing_behavior do
195
+ Adhearsion.config.platform.environment = env
196
+ ahn = Adhearsion::Initializer.start
197
+ end
198
+ ahn.update_rails_env_var
199
+ ENV['RAILS_ENV'].should == env.to_s
200
+ end
201
+ end
141
202
 
142
- path.using_base_path temporary_base do
143
- path.should == temporary_base
203
+ context "when RAILS_ENV is set" do
204
+
205
+ after do
206
+ ENV['RAILS_ENV'] = nil
207
+ ENV['AHN_ENV'] = nil
208
+ end
209
+
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"
218
+ end
219
+
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"
229
+ end
144
230
  end
145
- path.should == original_base_path
146
- end
147
231
 
148
- it "creating the AHN_ROOT will set defaults" do
149
- stub_behavior_for_initializer_with_no_path_changing_behavior do
150
- flexstub(Adhearsion::Initializer).new_instances.should_receive(:load).and_return
151
- ahn = Adhearsion::Initializer.start path
152
- full_path = File.expand_path(path)
153
- AHN_ROOT.to_s.should == full_path
154
- AHN_ROOT.component_path.should == File.join(full_path, "components")
155
- AHN_ROOT.log_path.should == File.join(full_path, "logs")
156
- AHN_ROOT.dialplan_path.should == full_path
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
237
+
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"
246
+ end
157
247
  end
158
248
  end
159
- private
160
- def path
161
- '/any/ole/path'
162
- end
249
+
163
250
  end
@@ -1,50 +1,47 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'The ahn_log command' do
3
+ Foo = Class.new
4
+ Foo::Bar = Class.new
4
5
 
5
- it 'should add the ahn_log method to the global namespace' do
6
- ahn_log.should be Adhearsion::Logging::DefaultAdhearsionLogger
7
- end
6
+ describe Adhearsion::Logging do
8
7
 
9
- it "should log to the standard Adhearsion logger when given arguments" do
10
- message = "o hai. ur home erly."
11
- flexmock(Log4r::Logger['ahn']).should_receive(:info).once.with(message)
12
- ahn_log message
8
+ before do
9
+ defined?(Logging) and Logging.reset
10
+ Adhearsion::Initializer::Logging.start
11
+ Adhearsion::Logging.silence!
13
12
  end
14
13
 
15
- it 'should create a new logger when given method_missing' do
16
- ahn_log.micromenus 'danger will robinson!'
17
- Log4r::Logger['micromenus'].should_not be nil
14
+ it 'should be added to any Object' do
15
+ Foo.should respond_to(:logger)
18
16
  end
19
17
 
20
- it 'should define a singleton method on itself of any name found by method_missing' do
21
- ahn_log.agi "SOMETHING IMPORTANT HAPPENED"
22
- Adhearsion::Logging::AdhearsionLogger.instance_methods.map{|m| m.to_sym}.should include :agi
18
+ it 'should created the predefined set of log levels' do
19
+ ::Logging::LEVELS.length.should eql(Adhearsion::Logging::LOG_LEVELS.length)
23
20
  end
24
21
 
25
- it "dynamically generated loggers should support logging with blocks" do
26
- # I had to comment out this it because Flexmock makes it impossible to#
27
- # set up an expectation for receiving blocks.
22
+ it 'should be added to any Object instance' do
23
+ Foo.new.should respond_to(:logger)
24
+ end
28
25
 
29
- # proc_to_log = lambda { [1,2,3].reverse.join }
30
- #
31
- # info_catcher = flexmock "A logger that responds to info()"
32
- # info_catcher.should_receive(:info).once.with(&proc_to_log)
33
- #
34
- # flexmock(Log4r::Logger).should_receive(:[]).with('log4r')
35
- # flexmock(Log4r::Logger).should_receive(:[]).once.with('ami').and_return info_catcher
36
- #
37
- # ahn_log.ami(&proc_to_log)
26
+ it "should log to the Object logger when given arguments" do
27
+ message = "o hai. ur home erly."
28
+ foo = Foo.new
29
+ flexmock(::Logging.logger[Foo]).should_receive(:info).once.with(message)
30
+ foo.logger.info message
38
31
  end
39
32
 
40
- it 'new loggers created by method_missing() should be instances of AdhearsionLogger' do
41
- ahn_log.qwerty.should be_a_kind_of Adhearsion::Logging::AdhearsionLogger
33
+ it "should log to the Object logger when given arguments (II)" do
34
+ message = "o hai. ur home erly."
35
+ bar = Foo::Bar.new
36
+ flexmock(::Logging.logger[Foo::Bar]).should_receive(:info).once.with(message)
37
+ bar.logger.info message
42
38
  end
43
39
 
44
- it "handles crazy logger names" do
45
- ahn_log.send :'locals@DEMO_call&', "hey"
46
- Log4r::Logger['locals@DEMO_call&'].should_not be nil
47
- ahn_log.send(:'localsdemo_call').should == Log4r::Logger['locals@DEMO_call&']
40
+ it 'should create a new logger when given method_missing' do
41
+ FooBar = Class.new Foo
42
+ ::Logging::Repository.instance[FooBar].should be_nil
43
+ FooBar.logger.info "o hai. ur home erly."
44
+ ::Logging::Repository.instance[FooBar].should_not be_nil
48
45
  end
49
46
 
50
47
  end
@@ -52,7 +49,12 @@ end
52
49
  # Essential for running the tests
53
50
  describe 'Logger level changing' do
54
51
 
55
- after :each do
52
+ before do
53
+ defined?(Logging) and Logging.reset
54
+ Adhearsion::Initializer::Logging.start
55
+ end
56
+
57
+ after do
56
58
  Adhearsion::Logging.logging_level = :info
57
59
  end
58
60
 
@@ -61,32 +63,41 @@ describe 'Logger level changing' do
61
63
  end
62
64
 
63
65
  it 'changing the logging level should affect all loggers' do
64
- loggers = [ahn_log.one, ahn_log.two, ahn_log.three]
65
- loggers.map(&:level).should_not == [Log4r::WARN] * 3
66
+ loggers = [::Foo.logger, ::Foo::Bar.logger]
67
+ loggers.map(&:level).should_not == [::Logging::LEVELS["debug"]] * 2
68
+ loggers.map(&:level).should == [::Logging::LEVELS["info"]] * 2
66
69
  Adhearsion::Logging.logging_level = :warn
67
- loggers.map(&:level).should == [Log4r::WARN] * 3
70
+ loggers.map(&:level).should == [::Logging::LEVELS["warn"]] * 2
71
+ end
72
+
73
+ it 'changing the logging level, using level=, should affect all loggers' do
74
+ loggers = [Foo.logger, ::Foo::Bar.logger]
75
+ loggers.map(&:level).should_not == [::Logging::LEVELS["debug"]] * 2
76
+ loggers.map(&:level).should == [::Logging::LEVELS["info"]] * 2
77
+ Adhearsion::Logging.level = :warn
78
+ loggers.map(&:level).should == [::Logging::LEVELS["warn"]] * 2
79
+ end
80
+
81
+ it 'should change all the Logger instance level' do
82
+ Foo.logger.level.should be Adhearsion::Logging::INFO
83
+ Adhearsion::Logging.logging_level = :fatal
84
+ Foo.logger.level.should be Adhearsion::Logging::FATAL
68
85
  end
69
86
 
70
- it 'a new logger should have the global Adhearsion logging level' do
71
- ahn_log.foo.level.should be Log4r::INFO
87
+ it 'a new logger should have the :root logging level' do
88
+ Foo.logger.level.should be Adhearsion::Logging::INFO
72
89
  Adhearsion::Logging.logging_level = :fatal
73
- ahn_log.brand_new.level.should be Log4r::FATAL
90
+ Foo::Bar.logger.level.should be Adhearsion::Logging::FATAL
74
91
  end
75
92
 
76
93
  it '#silence!() should change the level to be FATAL' do
77
- flexmock(Adhearsion::Logging::DefaultAdhearsionLogger).should_receive(:level=).once.with(Log4r::FATAL)
78
94
  Adhearsion::Logging.silence!
79
- # Verify and close manually here because the after-test hook breaks the expectation
80
- flexmock_verify
81
- flexmock_close
95
+ Adhearsion::Logging.logging_level.should be(Adhearsion::Logging::FATAL)
82
96
  end
83
97
 
84
98
  it '#unsilence!() should change the level to be INFO' do
85
- flexmock(Adhearsion::Logging::DefaultAdhearsionLogger).should_receive(:level=).once.with(Log4r::INFO)
86
99
  Adhearsion::Logging.unsilence!
87
- # Verify and close manually here because the after-test hook breaks the expectation
88
- flexmock_verify
89
- flexmock_close
100
+ Adhearsion::Logging.logging_level.should be(Adhearsion::Logging::INFO)
90
101
  end
91
102
 
92
103
  end