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.
- data/.gitignore +17 -10
- data/CHANGELOG.md +273 -0
- data/Gemfile +1 -1
- data/Guardfile +17 -0
- data/README.markdown +61 -9
- data/Rakefile +16 -48
- data/adhearsion.gemspec +21 -7
- data/bin/ahn +3 -1
- data/cucumber.yml +4 -0
- data/features/app_generator.feature +42 -0
- data/features/cli.feature +108 -0
- data/features/step_definitions/app_generator_steps.rb +6 -0
- data/features/step_definitions/cli_steps.rb +74 -0
- data/features/support/aruba_helper.rb +22 -0
- data/features/support/env.rb +37 -0
- data/features/support/utils.rb +8 -0
- data/lib/adhearsion.rb +85 -41
- data/lib/adhearsion/call.rb +176 -0
- data/lib/adhearsion/call_controller.rb +134 -0
- data/lib/adhearsion/call_controller/dial.rb +70 -0
- data/lib/adhearsion/call_controller/input.rb +173 -0
- data/lib/adhearsion/call_controller/menu.rb +124 -0
- data/lib/adhearsion/call_controller/output.rb +267 -0
- data/lib/adhearsion/call_controller/record.rb +42 -0
- data/lib/adhearsion/call_controller/utility.rb +60 -0
- data/lib/adhearsion/calls.rb +81 -0
- data/lib/adhearsion/cli.rb +1 -3
- data/lib/adhearsion/cli_commands.rb +142 -0
- data/lib/adhearsion/configuration.rb +149 -0
- data/lib/adhearsion/console.rb +19 -8
- data/lib/adhearsion/dialplan_controller.rb +9 -0
- data/lib/adhearsion/events.rb +84 -0
- data/lib/adhearsion/foundation/all.rb +0 -7
- data/lib/adhearsion/foundation/custom_daemonizer.rb +4 -6
- data/lib/adhearsion/foundation/exception_handler.rb +9 -0
- data/lib/adhearsion/foundation/object.rb +26 -8
- data/lib/adhearsion/foundation/synchronized_hash.rb +3 -6
- data/lib/adhearsion/foundation/thread_safety.rb +17 -1
- data/lib/adhearsion/generators/app/app_generator.rb +4 -13
- data/lib/adhearsion/generators/app/templates/Gemfile +10 -5
- data/lib/adhearsion/generators/app/templates/Procfile +1 -0
- data/lib/adhearsion/generators/app/templates/README.md +28 -0
- data/lib/adhearsion/generators/app/templates/config/adhearsion.rb +41 -0
- data/lib/adhearsion/generators/app/templates/{components/simon_game → lib}/simon_game.rb +6 -18
- data/lib/adhearsion/generators/app/templates/script/ahn +2 -2
- data/lib/adhearsion/initializer.rb +151 -293
- data/lib/adhearsion/initializer/logging.rb +33 -0
- data/lib/adhearsion/logging.rb +65 -69
- data/lib/adhearsion/menu_dsl.rb +15 -0
- data/lib/adhearsion/menu_dsl/calculated_match.rb +39 -0
- data/lib/adhearsion/menu_dsl/calculated_match_collection.rb +41 -0
- data/lib/adhearsion/menu_dsl/fixnum_match_calculator.rb +18 -0
- data/lib/adhearsion/menu_dsl/match_calculator.rb +36 -0
- data/lib/adhearsion/{voip/menu_state_machine/menu_class.rb → menu_dsl/menu.rb} +38 -40
- data/lib/adhearsion/menu_dsl/menu_builder.rb +69 -0
- data/lib/adhearsion/menu_dsl/range_match_calculator.rb +55 -0
- data/lib/adhearsion/menu_dsl/string_match_calculator.rb +21 -0
- data/lib/adhearsion/outbound_call.rb +64 -0
- data/lib/adhearsion/plugin.rb +319 -0
- data/lib/adhearsion/plugin/collection.rb +19 -0
- data/lib/adhearsion/plugin/initializer.rb +37 -0
- data/lib/adhearsion/plugin/methods_container.rb +6 -0
- data/lib/adhearsion/process.rb +94 -0
- data/lib/adhearsion/punchblock_plugin.rb +29 -0
- data/lib/adhearsion/punchblock_plugin/initializer.rb +137 -0
- data/lib/adhearsion/router.rb +30 -0
- data/lib/adhearsion/router/route.rb +42 -0
- data/lib/adhearsion/script_ahn_loader.rb +2 -2
- data/lib/adhearsion/tasks.rb +14 -9
- data/lib/adhearsion/tasks/configuration.rb +26 -0
- data/lib/adhearsion/tasks/plugins.rb +17 -0
- data/lib/adhearsion/version.rb +8 -14
- data/spec/adhearsion/call_controller/dial_spec.rb +138 -0
- data/spec/adhearsion/call_controller/input_spec.rb +278 -0
- data/spec/adhearsion/call_controller/menu_spec.rb +120 -0
- data/spec/adhearsion/call_controller/output_spec.rb +466 -0
- data/spec/adhearsion/call_controller/record_spec.rb +125 -0
- data/spec/adhearsion/call_controller_spec.rb +395 -0
- data/spec/adhearsion/call_spec.rb +438 -0
- data/spec/adhearsion/calls_spec.rb +47 -0
- data/spec/adhearsion/configuration_spec.rb +308 -0
- data/spec/adhearsion/dialplan_controller_spec.rb +26 -0
- data/spec/adhearsion/events_spec.rb +112 -0
- data/spec/adhearsion/initializer/logging_spec.rb +58 -0
- data/spec/adhearsion/initializer_spec.rb +209 -122
- data/spec/adhearsion/logging_spec.rb +58 -47
- data/spec/adhearsion/menu_dsl/calculated_match_collection_spec.rb +56 -0
- data/spec/adhearsion/menu_dsl/calculated_match_spec.rb +57 -0
- data/spec/adhearsion/menu_dsl/fixnum_match_calculator_spec.rb +33 -0
- data/spec/adhearsion/menu_dsl/match_calculator_spec.rb +13 -0
- data/spec/adhearsion/menu_dsl/menu_builder_spec.rb +118 -0
- data/spec/adhearsion/menu_dsl/menu_spec.rb +210 -0
- data/spec/adhearsion/menu_dsl/range_match_calculator_spec.rb +28 -0
- data/spec/adhearsion/menu_dsl/string_match_calculator_spec.rb +36 -0
- data/spec/adhearsion/menu_dsl_spec.rb +12 -0
- data/spec/adhearsion/outbound_call_spec.rb +174 -0
- data/spec/adhearsion/plugin_spec.rb +489 -0
- data/spec/adhearsion/process_spec.rb +34 -0
- data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +294 -0
- data/spec/adhearsion/router/route_spec.rb +99 -0
- data/spec/adhearsion/router_spec.rb +106 -0
- data/spec/adhearsion_spec.rb +46 -0
- data/spec/spec_helper.rb +14 -14
- data/spec/support/call_controller_test_helpers.rb +48 -0
- data/spec/support/initializer_stubs.rb +8 -13
- data/spec/support/punchblock_mocks.rb +6 -0
- metadata +255 -253
- data/CHANGELOG +0 -174
- data/bin/ahnctl +0 -68
- data/bin/jahn +0 -43
- data/examples/asterisk_manager_interface/standalone.rb +0 -51
- data/lib/adhearsion/commands.rb +0 -302
- data/lib/adhearsion/component_manager.rb +0 -278
- data/lib/adhearsion/component_manager/component_tester.rb +0 -54
- data/lib/adhearsion/component_manager/spec_framework.rb +0 -18
- data/lib/adhearsion/events_support.rb +0 -65
- data/lib/adhearsion/foundation/blank_slate.rb +0 -3
- data/lib/adhearsion/foundation/event_socket.rb +0 -205
- data/lib/adhearsion/foundation/future_resource.rb +0 -36
- data/lib/adhearsion/foundation/metaprogramming.rb +0 -17
- data/lib/adhearsion/foundation/numeric.rb +0 -13
- data/lib/adhearsion/foundation/pseudo_guid.rb +0 -10
- data/lib/adhearsion/foundation/relationship_properties.rb +0 -42
- data/lib/adhearsion/foundation/string.rb +0 -26
- data/lib/adhearsion/generators/app/templates/.ahnrc +0 -34
- data/lib/adhearsion/generators/app/templates/README +0 -8
- data/lib/adhearsion/generators/app/templates/components/ami_remote/ami_remote.rb +0 -15
- data/lib/adhearsion/generators/app/templates/components/disabled/HOW_TO_ENABLE +0 -7
- data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/README.markdown +0 -47
- data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.rb +0 -34
- data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.yml +0 -12
- data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/README.markdown +0 -3
- data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.rb +0 -11
- data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.yml +0 -0
- data/lib/adhearsion/generators/app/templates/config/startup.rb +0 -81
- data/lib/adhearsion/generators/app/templates/dialplan.rb +0 -3
- data/lib/adhearsion/generators/app/templates/events.rb +0 -33
- data/lib/adhearsion/host_definitions.rb +0 -67
- data/lib/adhearsion/initializer/asterisk.rb +0 -86
- data/lib/adhearsion/initializer/configuration.rb +0 -324
- data/lib/adhearsion/initializer/database.rb +0 -60
- data/lib/adhearsion/initializer/drb.rb +0 -31
- data/lib/adhearsion/initializer/freeswitch.rb +0 -22
- data/lib/adhearsion/initializer/ldap.rb +0 -57
- data/lib/adhearsion/initializer/rails.rb +0 -41
- data/lib/adhearsion/initializer/xmpp.rb +0 -42
- data/lib/adhearsion/tasks/components.rb +0 -32
- data/lib/adhearsion/tasks/database.rb +0 -5
- data/lib/adhearsion/tasks/deprecations.rb +0 -59
- data/lib/adhearsion/tasks/generating.rb +0 -20
- data/lib/adhearsion/tasks/lint.rb +0 -4
- data/lib/adhearsion/voip/asterisk.rb +0 -4
- data/lib/adhearsion/voip/asterisk/agi_server.rb +0 -121
- data/lib/adhearsion/voip/asterisk/commands.rb +0 -1966
- data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +0 -140
- data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +0 -102
- data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +0 -250
- data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +0 -240
- data/lib/adhearsion/voip/asterisk/config_manager.rb +0 -64
- data/lib/adhearsion/voip/asterisk/manager_interface.rb +0 -697
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +0 -1681
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +0 -341
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +0 -78
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +0 -87
- data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +0 -80
- data/lib/adhearsion/voip/call.rb +0 -521
- data/lib/adhearsion/voip/call_routing.rb +0 -64
- data/lib/adhearsion/voip/commands.rb +0 -17
- data/lib/adhearsion/voip/constants.rb +0 -39
- data/lib/adhearsion/voip/conveniences.rb +0 -18
- data/lib/adhearsion/voip/dial_plan.rb +0 -252
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +0 -151
- data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +0 -37
- data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +0 -27
- data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +0 -124
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +0 -69
- data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +0 -16
- data/lib/adhearsion/voip/dsl/numerical_string.rb +0 -128
- data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +0 -48
- data/lib/adhearsion/voip/freeswitch/event_handler.rb +0 -58
- data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +0 -129
- data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +0 -38
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +0 -195
- data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +0 -80
- data/lib/adhearsion/voip/menu_state_machine/matchers.rb +0 -123
- data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +0 -57
- data/lib/adhearsion/xmpp/connection.rb +0 -61
- data/lib/theatre.rb +0 -147
- data/lib/theatre/README.markdown +0 -64
- data/lib/theatre/callback_definition_loader.rb +0 -86
- data/lib/theatre/guid.rb +0 -23
- data/lib/theatre/invocation.rb +0 -131
- data/lib/theatre/namespace_manager.rb +0 -153
- data/lib/theatre/version.rb +0 -2
- data/spec/adhearsion/cli_spec.rb +0 -306
- data/spec/adhearsion/component_manager_spec.rb +0 -292
- data/spec/adhearsion/constants_spec.rb +0 -8
- data/spec/adhearsion/drb_spec.rb +0 -65
- data/spec/adhearsion/fixtures/dialplan.rb +0 -3
- data/spec/adhearsion/foundation/event_socket_spec.rb +0 -168
- data/spec/adhearsion/host_definitions_spec.rb +0 -79
- data/spec/adhearsion/initializer/configuration_spec.rb +0 -291
- data/spec/adhearsion/initializer/loading_spec.rb +0 -154
- data/spec/adhearsion/initializer/paths_spec.rb +0 -74
- data/spec/adhearsion/relationship_properties_spec.rb +0 -54
- data/spec/adhearsion/voip/asterisk/agi_server_spec.rb +0 -473
- data/spec/adhearsion/voip/asterisk/ami/ami_spec.rb +0 -550
- data/spec/adhearsion/voip/asterisk/ami/lexer/ami_fixtures.yml +0 -30
- data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story +0 -291
- data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story.rb +0 -241
- data/spec/adhearsion/voip/asterisk/ami/lexer/story_helper.rb +0 -124
- data/spec/adhearsion/voip/asterisk/commands_spec.rb +0 -3241
- data/spec/adhearsion/voip/asterisk/config_file_generators/agents_spec.rb +0 -251
- data/spec/adhearsion/voip/asterisk/config_file_generators/queues_spec.rb +0 -323
- data/spec/adhearsion/voip/asterisk/config_file_generators/voicemail_spec.rb +0 -306
- data/spec/adhearsion/voip/asterisk/config_manager_spec.rb +0 -127
- data/spec/adhearsion/voip/asterisk/menu_command/calculated_match_spec.rb +0 -109
- data/spec/adhearsion/voip/asterisk/menu_command/matchers_spec.rb +0 -97
- data/spec/adhearsion/voip/call_routing_spec.rb +0 -125
- data/spec/adhearsion/voip/dialplan_manager_spec.rb +0 -468
- data/spec/adhearsion/voip/dsl/dialing_dsl_spec.rb +0 -270
- data/spec/adhearsion/voip/dsl/dispatcher_spec.rb +0 -82
- data/spec/adhearsion/voip/dsl/dispatcher_spec_helper.rb +0 -45
- data/spec/adhearsion/voip/dsl/parser_spec.rb +0 -69
- data/spec/adhearsion/voip/freeswitch/basic_connection_manager_spec.rb +0 -39
- data/spec/adhearsion/voip/freeswitch/inbound_connection_manager_spec.rb +0 -39
- data/spec/adhearsion/voip/freeswitch/oes_server_spec.rb +0 -9
- data/spec/adhearsion/voip/numerical_string_spec.rb +0 -61
- data/spec/adhearsion/voip/phone_number_spec.rb +0 -45
- data/spec/support/the_following_code.rb +0 -3
- data/spec/theatre/dsl_examples/simple_before_call.rb +0 -7
- data/spec/theatre/dsl_spec.rb +0 -69
- data/spec/theatre/invocation_spec.rb +0 -182
- data/spec/theatre/namespace_spec.rb +0 -125
- data/spec/theatre/spec_helper_spec.rb +0 -28
- data/spec/theatre/theatre_class_spec.rb +0 -148
@@ -1,163 +1,250 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Adhearsion::Initializer do
|
4
4
|
|
5
5
|
include InitializerStubs
|
6
6
|
# TODO: create a specification for aliases
|
7
7
|
|
8
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
19
|
-
Adhearsion::Initializer.start path
|
19
|
+
after do
|
20
|
+
Adhearsion::Events.reinitialize_queue!
|
20
21
|
end
|
21
|
-
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
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 "
|
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
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
136
|
-
|
137
|
-
|
186
|
+
after do
|
187
|
+
ENV['RAILS_ENV'] = nil
|
188
|
+
end
|
138
189
|
|
139
|
-
|
140
|
-
|
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
|
-
|
143
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
-
|
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
|
-
|
3
|
+
Foo = Class.new
|
4
|
+
Foo::Bar = Class.new
|
4
5
|
|
5
|
-
|
6
|
-
ahn_log.should be Adhearsion::Logging::DefaultAdhearsionLogger
|
7
|
-
end
|
6
|
+
describe Adhearsion::Logging do
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
16
|
-
|
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
|
21
|
-
|
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
|
26
|
-
|
27
|
-
|
22
|
+
it 'should be added to any Object instance' do
|
23
|
+
Foo.new.should respond_to(:logger)
|
24
|
+
end
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
41
|
-
|
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
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
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 = [
|
65
|
-
loggers.map(&:level).should_not == [
|
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 == [
|
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
|
71
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
88
|
-
flexmock_verify
|
89
|
-
flexmock_close
|
100
|
+
Adhearsion::Logging.logging_level.should be(Adhearsion::Logging::INFO)
|
90
101
|
end
|
91
102
|
|
92
103
|
end
|