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,79 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'adhearsion/host_definitions'
|
3
|
-
|
4
|
-
describe 'HostDefinition' do
|
5
|
-
|
6
|
-
after :each do
|
7
|
-
Adhearsion::HostDefinition.clear_definitions!
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'when loading from a YAML array, it should pass each nested Hash to the constructor' do
|
11
|
-
hosts = [
|
12
|
-
{:host => "hostname1", :username => "user", :password => "password"},
|
13
|
-
{:host => "hostname2", :username => "user", :password => "password"},
|
14
|
-
{:host => "hostname3", :username => "user", :password => "password"}
|
15
|
-
]
|
16
|
-
flexmock(Adhearsion::HostDefinition).should_receive(:new).once.with(hosts[0])
|
17
|
-
flexmock(Adhearsion::HostDefinition).should_receive(:new).once.with(hosts[1])
|
18
|
-
flexmock(Adhearsion::HostDefinition).should_receive(:new).once.with(hosts[2])
|
19
|
-
Adhearsion::HostDefinition.import_from_yaml hosts.to_yaml
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should set the @name property to a new UUID when no name is given' do
|
23
|
-
definition = {:host => "hostname", :username => "user", :password => "pass"}
|
24
|
-
Adhearsion::HostDefinition.new(definition).name.should =~ /^[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}$/i
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'when loading from YAML keys, it should pass each nested Hash to the constructor with the key as :name' do
|
28
|
-
definitions = { :pbx1 => {},
|
29
|
-
:pbx2 => {},
|
30
|
-
:pbx3 => {} }
|
31
|
-
definitions.each_pair do |key,value|
|
32
|
-
flexmock(Adhearsion::HostDefinition).should_receive(:new).once.with(value.merge(:name => key))
|
33
|
-
end
|
34
|
-
Adhearsion::HostDefinition.import_from_data_structure(definitions)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'should have an Array class variable named definitions' do
|
38
|
-
Adhearsion::HostDefinition.definitions.should be_a_kind_of Array
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'should add each HostDefinition to a class variable named @@definitions when instantiated' do
|
42
|
-
Adhearsion::HostDefinition.definitions.size.should be 0
|
43
|
-
Adhearsion::HostDefinition.new :name => "foobar", :host => "hostname", :username => "user", :password => "password"
|
44
|
-
Adhearsion::HostDefinition.definitions.size.should be 1
|
45
|
-
Adhearsion::HostDefinition.clear_definitions!
|
46
|
-
Adhearsion::HostDefinition.definitions.size.should be 0
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should raise a HostDefinitionException when a password and a key are given' do
|
50
|
-
the_following_code {
|
51
|
-
Adhearsion::HostDefinition.new(:username => "user", :host => "foobar", :key => "doesntmatter", :password => "pass")
|
52
|
-
}.should raise_error Adhearsion::HostDefinition::HostDefinitionException
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should raise a HostDefinitionException when no password or key is given' do
|
56
|
-
the_following_code {
|
57
|
-
Adhearsion::HostDefinition.new(:username => "user", :host => "foobar")
|
58
|
-
}.should raise_error Adhearsion::HostDefinition::HostDefinitionException
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should raise a HostDefinitionException when no username is given' do
|
62
|
-
the_following_code {
|
63
|
-
Adhearsion::HostDefinition.new(:host => "host", :password => "password")
|
64
|
-
}.should raise_error Adhearsion::HostDefinition::HostDefinitionException
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should raise a HostDefinitionException when no "host" key is given' do
|
68
|
-
the_following_code {
|
69
|
-
Adhearsion::HostDefinition.new(:username => "foobar", :password => "password")
|
70
|
-
}.should raise_error Adhearsion::HostDefinition::HostDefinitionException
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should raise a HostDefinitionException when an unrecognized key is given' do
|
74
|
-
the_following_code {
|
75
|
-
Adhearsion::HostDefinition.new(:username => "foobar", :password => "password", :host => "blah", :thiskeyisnotrecognized => nil)
|
76
|
-
}.should raise_error Adhearsion::HostDefinition::HostDefinitionException
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
@@ -1,291 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module ConfigurationTestHelper
|
4
|
-
def default_config(&block)
|
5
|
-
Adhearsion::Configuration.new do |config|
|
6
|
-
config.enable_asterisk
|
7
|
-
yield config if block_given?
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "Configuration defaults" do
|
13
|
-
include ConfigurationTestHelper
|
14
|
-
attr_reader :config
|
15
|
-
|
16
|
-
before(:each) do
|
17
|
-
@config = default_config
|
18
|
-
end
|
19
|
-
|
20
|
-
it "incoming calls are answered by default" do
|
21
|
-
config.automatically_answer_incoming_calls.should be true
|
22
|
-
end
|
23
|
-
|
24
|
-
it "calls are ended when hung up" do
|
25
|
-
config.end_call_on_hangup.should be true
|
26
|
-
end
|
27
|
-
|
28
|
-
it "if an error occurs, a call is hungup" do
|
29
|
-
config.end_call_on_error.should be true
|
30
|
-
end
|
31
|
-
|
32
|
-
it "asterisk is enabled by default" do
|
33
|
-
config.asterisk_enabled?.should be true
|
34
|
-
end
|
35
|
-
|
36
|
-
it "default asterisk configuration is available" do
|
37
|
-
config.asterisk.kind_of?(Adhearsion::Configuration::AsteriskConfiguration).should be true
|
38
|
-
end
|
39
|
-
|
40
|
-
it "database access is NOT enabled by default" do
|
41
|
-
config.database_enabled?.should be false
|
42
|
-
end
|
43
|
-
|
44
|
-
it "ldap access is NOT enabled by default" do
|
45
|
-
config.ldap_enabled?.should be false
|
46
|
-
end
|
47
|
-
|
48
|
-
it "freeswith is NOT enabled by default" do
|
49
|
-
config.freeswitch_enabled?.should be false
|
50
|
-
end
|
51
|
-
|
52
|
-
it "AMI is NOT enabled by default" do
|
53
|
-
config.asterisk.ami_enabled?.should be false
|
54
|
-
end
|
55
|
-
|
56
|
-
it "Drb is NOT enabled by default" do
|
57
|
-
config.drb_enabled?.should be false
|
58
|
-
end
|
59
|
-
|
60
|
-
it "XMPP is NOT enabled by default" do
|
61
|
-
config.xmpp_enabled?.should be false
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "Asterisk AGI configuration defaults" do
|
66
|
-
attr_reader :config
|
67
|
-
|
68
|
-
before(:each) do
|
69
|
-
@config = Adhearsion::Configuration::AsteriskConfiguration.new
|
70
|
-
end
|
71
|
-
|
72
|
-
it "asterisk configuration sets default listening port" do
|
73
|
-
config.listening_port.should be Adhearsion::Configuration::AsteriskConfiguration.default_listening_port
|
74
|
-
end
|
75
|
-
|
76
|
-
it "asterisk configuration sets default listening host" do
|
77
|
-
config.listening_host.should == Adhearsion::Configuration::AsteriskConfiguration.default_listening_host
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe 'Logging configuration' do
|
82
|
-
|
83
|
-
attr_reader :config
|
84
|
-
before :each do
|
85
|
-
@config = Adhearsion::Configuration.new
|
86
|
-
end
|
87
|
-
|
88
|
-
after :each do
|
89
|
-
Adhearsion::Logging.logging_level = :fatal
|
90
|
-
Adhearsion::Logging::AdhearsionLogger.outputters = [Log4r::Outputter.stdout]
|
91
|
-
Adhearsion::Logging::AdhearsionLogger.formatters = [Log4r::DefaultFormatter]
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'the logging level should translate from symbols into Log4r constants' do
|
95
|
-
Adhearsion::Logging.logging_level.should_not be Log4r::WARN
|
96
|
-
config.logging :level => :warn
|
97
|
-
Adhearsion::Logging.logging_level.should be Log4r::WARN
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'outputters should be settable' do
|
101
|
-
Adhearsion::Logging::AdhearsionLogger.outputters.should == [Log4r::Outputter.stdout]
|
102
|
-
config.logging :outputters => Log4r::Outputter.stderr
|
103
|
-
Adhearsion::Logging::AdhearsionLogger.outputters.should == [Log4r::Outputter.stderr]
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'formatters should be settable' do
|
107
|
-
Adhearsion::Logging::AdhearsionLogger.formatters.map(&:class).should == [Log4r::DefaultFormatter]
|
108
|
-
config.logging :formatters => Log4r::ObjectFormatter
|
109
|
-
Adhearsion::Logging::AdhearsionLogger.formatters.map(&:class).should == [Log4r::ObjectFormatter]
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'a global formatter should be settable' do
|
113
|
-
Adhearsion::Logging::AdhearsionLogger.outputters << Log4r::Outputter.stdout
|
114
|
-
Adhearsion::Logging::AdhearsionLogger.formatters.map(&:class).should == [Log4r::DefaultFormatter, Log4r::DefaultFormatter]
|
115
|
-
config.logging :formatter => Log4r::ObjectFormatter
|
116
|
-
Adhearsion::Logging::AdhearsionLogger.formatters.map(&:class).should == [Log4r::ObjectFormatter, Log4r::ObjectFormatter]
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "AMI configuration defaults" do
|
122
|
-
attr_reader :config
|
123
|
-
|
124
|
-
before(:each) do
|
125
|
-
@config = Adhearsion::Configuration::AsteriskConfiguration::AMIConfiguration.new
|
126
|
-
end
|
127
|
-
|
128
|
-
it "ami configuration sets default port" do
|
129
|
-
config.port.should be Adhearsion::Configuration::AsteriskConfiguration::AMIConfiguration.default_port
|
130
|
-
end
|
131
|
-
|
132
|
-
it "ami allows you to configure a username and a password, both of which default to nil" do
|
133
|
-
config.username.should be nil
|
134
|
-
config.password.should be nil
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
describe "Rails configuration defaults" do
|
139
|
-
it "should require the path to the Rails app in the constructor" do
|
140
|
-
config = Adhearsion::Configuration::RailsConfiguration.new :path => "path here doesn't matter right now", :env => :development
|
141
|
-
config.rails_root.should_not be nil
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should expand_path() the first constructor parameter" do
|
145
|
-
rails_root = "gui"
|
146
|
-
flexmock(File).should_receive(:expand_path).once.with(rails_root)
|
147
|
-
config = Adhearsion::Configuration::RailsConfiguration.new :path => rails_root, :env => :development
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe "Database configuration defaults" do
|
152
|
-
|
153
|
-
before(:each) do
|
154
|
-
Adhearsion.send(:remove_const, :AHN_CONFIG) if Adhearsion.const_defined?(:AHN_CONFIG)
|
155
|
-
Adhearsion::Configuration.configure {}
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should store the constructor's argument in connection_options()" do
|
159
|
-
sample_options = { :adapter => "sqlite3", :dbfile => "foo.sqlite3" }
|
160
|
-
config = Adhearsion::Configuration::DatabaseConfiguration.new(sample_options)
|
161
|
-
config.connection_options.should be sample_options
|
162
|
-
end
|
163
|
-
it "should remove the :orm key from the connection options" do
|
164
|
-
sample_options = { :orm => :active_record, :adapter => "mysql", :host => "::1",
|
165
|
-
:user => "a", :pass => "b", :database => "ahn" }
|
166
|
-
config = Adhearsion::Configuration::DatabaseConfiguration.new(sample_options.clone)
|
167
|
-
config.orm.should be sample_options.delete(:orm)
|
168
|
-
config.connection_options.should == sample_options
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe "Freeswitch configuration defaults" do
|
173
|
-
attr_reader :config
|
174
|
-
|
175
|
-
before(:each) do
|
176
|
-
@config = Adhearsion::Configuration::FreeswitchConfiguration.new
|
177
|
-
end
|
178
|
-
|
179
|
-
it "freeswitch configuration sets default listening port" do
|
180
|
-
config.listening_port.should be Adhearsion::Configuration::FreeswitchConfiguration.default_listening_port
|
181
|
-
end
|
182
|
-
|
183
|
-
it "freeswitch configuration sets default listening host" do
|
184
|
-
config.listening_host.should == Adhearsion::Configuration::FreeswitchConfiguration.default_listening_host
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe "XMPP configuration defaults" do
|
189
|
-
attr_reader :config
|
190
|
-
|
191
|
-
it "xmpp configuration sets default port when server is set, but no port" do
|
192
|
-
config = Adhearsion::Configuration::XMPPConfiguration.new :jid => "test@example.com", :password => "somepassword", :server => "example.com"
|
193
|
-
config.port.should be Adhearsion::Configuration::XMPPConfiguration.default_port
|
194
|
-
end
|
195
|
-
|
196
|
-
it "should raise when port is specified, but no server" do
|
197
|
-
begin
|
198
|
-
config = Adhearsion::Configuration::XMPPConfiguration.new :jid => "test@example.com", :password => "somepassword", :port => "5223"
|
199
|
-
rescue ArgumentError => e
|
200
|
-
e.message.should == "Must supply a :server argument as well as :port to the XMPP initializer!"
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
describe "Configuration scenarios" do
|
206
|
-
include ConfigurationTestHelper
|
207
|
-
|
208
|
-
it "enabling AMI using all its defaults" do
|
209
|
-
config = enable_ami
|
210
|
-
|
211
|
-
config.asterisk.ami_enabled?.should be true
|
212
|
-
config.asterisk.ami.should be_a_kind_of Adhearsion::Configuration::AsteriskConfiguration::AMIConfiguration
|
213
|
-
end
|
214
|
-
|
215
|
-
it "enabling AMI with custom configuration overrides the defaults" do
|
216
|
-
overridden_port = 911
|
217
|
-
config = enable_ami :port => overridden_port
|
218
|
-
config.asterisk.ami.port.should be overridden_port
|
219
|
-
end
|
220
|
-
|
221
|
-
it "enabling Drb without any configuration" do
|
222
|
-
config = enable_drb
|
223
|
-
config.drb.should_not be nil
|
224
|
-
config.drb.should be_a_kind_of Adhearsion::Configuration::DrbConfiguration
|
225
|
-
end
|
226
|
-
|
227
|
-
it "enabling Drb with a port specified sets the port" do
|
228
|
-
target_port = 911
|
229
|
-
config = enable_drb :port => target_port
|
230
|
-
config.drb.port.should == target_port
|
231
|
-
end
|
232
|
-
|
233
|
-
private
|
234
|
-
def enable_ami(*overrides)
|
235
|
-
default_config do |config|
|
236
|
-
config.asterisk.enable_ami(*overrides)
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
def enable_drb(*overrides)
|
241
|
-
default_config do |config|
|
242
|
-
config.enable_drb *overrides
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
describe "AHN_CONFIG" do
|
248
|
-
before(:each) do
|
249
|
-
Adhearsion.send(:remove_const, :AHN_CONFIG) if Adhearsion.const_defined?(:AHN_CONFIG)
|
250
|
-
end
|
251
|
-
|
252
|
-
it "Running configure sets configuration to Adhearsion::AHN_CONFIG" do
|
253
|
-
Adhearsion.const_defined?(:AHN_CONFIG).should be false
|
254
|
-
Adhearsion::Configuration.configure do |config|
|
255
|
-
# Nothing needs to happen here
|
256
|
-
end
|
257
|
-
|
258
|
-
Adhearsion.const_defined?(:AHN_CONFIG).should be true
|
259
|
-
Adhearsion::AHN_CONFIG.should be_a_kind_of(Adhearsion::Configuration)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
describe "DRb configuration" do
|
264
|
-
it "should not add any ACL rules when :raw_acl is passed in" do
|
265
|
-
config = Adhearsion::Configuration::DrbConfiguration.new :raw_acl => :this_is_an_acl
|
266
|
-
config.acl.should be :this_is_an_acl
|
267
|
-
end
|
268
|
-
|
269
|
-
it "should, by default, allow only localhost connections" do
|
270
|
-
config = Adhearsion::Configuration::DrbConfiguration.new
|
271
|
-
config.acl.should == %w[allow 127.0.0.1]
|
272
|
-
end
|
273
|
-
|
274
|
-
it "should add ACL 'deny' rules before 'allow' rules" do
|
275
|
-
config = Adhearsion::Configuration::DrbConfiguration.new :allow => %w[1.1.1.1 2.2.2.2],
|
276
|
-
:deny => %w[9.9.9.9]
|
277
|
-
config.acl.should == %w[deny 9.9.9.9 allow 1.1.1.1 allow 2.2.2.2]
|
278
|
-
end
|
279
|
-
|
280
|
-
it "should allow both an Array and a String to be passed as an allow/deny ACL rule" do
|
281
|
-
config = Adhearsion::Configuration::DrbConfiguration.new :allow => "1.1.1.1", :deny => "9.9.9.9"
|
282
|
-
config.acl.should == %w[deny 9.9.9.9 allow 1.1.1.1]
|
283
|
-
end
|
284
|
-
|
285
|
-
it "should have a default host and port" do
|
286
|
-
config = Adhearsion::Configuration::DrbConfiguration.new
|
287
|
-
config.host.should_not be nil
|
288
|
-
config.port.should_not be nil
|
289
|
-
end
|
290
|
-
|
291
|
-
end
|
@@ -1,154 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'adhearsion/initializer/database'
|
3
|
-
require 'adhearsion/initializer/asterisk'
|
4
|
-
require 'adhearsion/initializer/rails'
|
5
|
-
require 'adhearsion/initializer/xmpp'
|
6
|
-
require 'active_record'
|
7
|
-
|
8
|
-
module DatabaseInitializationTestHelper
|
9
|
-
|
10
|
-
def start_database_initializer
|
11
|
-
start_database_initializer_with_options :adapter => "sqlite3", :dbfile => "foobar.sqlite3"
|
12
|
-
end
|
13
|
-
|
14
|
-
def start_database_initializer_with_options(options)
|
15
|
-
Adhearsion::Configuration.configure { |config| config.enable_database(options) }
|
16
|
-
Adhearsion::Initializer::DatabaseInitializer.start
|
17
|
-
end
|
18
|
-
|
19
|
-
def expect_establish_connection
|
20
|
-
flexmock(ActiveRecord::Base).should_receive :establish_connection
|
21
|
-
end
|
22
|
-
|
23
|
-
def tempfile_with_contents(contents)
|
24
|
-
Tempfile.new("bogus_model").tap do |file|
|
25
|
-
file.puts contents
|
26
|
-
file.flush
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def sample_user_model
|
31
|
-
<<-CODE
|
32
|
-
class User < ActiveRecord::Base
|
33
|
-
validates_uniqueness_of :name
|
34
|
-
end
|
35
|
-
CODE
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
module AsteriskInitializerTestHelper
|
40
|
-
def initialize_asterisk_with_defaults
|
41
|
-
initialize_asterisk_with_options Hash.new
|
42
|
-
end
|
43
|
-
def initialize_asterisk_with_options(options)
|
44
|
-
flexmock(Adhearsion::Initializer::AsteriskInitializer).should_receive(:join_server_thread_after_initialized)
|
45
|
-
Adhearsion::Configuration.configure { |config| config.enable_asterisk(options) }
|
46
|
-
Adhearsion::Initializer::AsteriskInitializer.start
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
module RailsInitializerTestHelper
|
51
|
-
|
52
|
-
def initialize_rails_with_options(options)
|
53
|
-
rails_options = flexmock "Rails options mock", options
|
54
|
-
flexstub(Adhearsion::AHN_CONFIG).should_receive(:rails).once.and_return(rails_options)
|
55
|
-
Adhearsion::Initializer::RailsInitializer.start
|
56
|
-
end
|
57
|
-
|
58
|
-
def stub_file_checking_methods!
|
59
|
-
flexstub(File).should_receive(:directory?).and_return true
|
60
|
-
flexstub(File).should_receive(:exists?).and_return true
|
61
|
-
end
|
62
|
-
|
63
|
-
def stub_before_call_hook!
|
64
|
-
flexstub(Adhearsion::Events.framework_theatre).should_receive(:register_namespace_name).with([:asterisk, :before_call]).and_return
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "The database initializer" do
|
70
|
-
|
71
|
-
include DatabaseInitializationTestHelper
|
72
|
-
|
73
|
-
after :each do
|
74
|
-
Adhearsion.send(:remove_const, :AHN_CONFIG) if Adhearsion.const_defined? :AHN_CONFIG
|
75
|
-
end
|
76
|
-
|
77
|
-
it "starts a connection through ActiveRecord" do
|
78
|
-
connection_options = { :adapter => "sqlite3",
|
79
|
-
:dbfile => "foo.sqlite3" }
|
80
|
-
flexmock(Adhearsion::Initializer::DatabaseInitializer).should_receive(:require_models).once
|
81
|
-
expect_establish_connection.with(connection_options)
|
82
|
-
|
83
|
-
start_database_initializer_with_options connection_options
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should make any required models available in the main namespace" do
|
87
|
-
bogus_model = tempfile_with_contents sample_user_model
|
88
|
-
flexmock(Adhearsion::Configuration).new_instances.should_receive(:files_from_setting).once.
|
89
|
-
with("paths", "models").and_return [bogus_model.path]
|
90
|
-
expect_establish_connection
|
91
|
-
start_database_initializer
|
92
|
-
User.superclass.should be ActiveRecord::Base
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "The Asterisk initializer" do
|
98
|
-
|
99
|
-
include AsteriskInitializerTestHelper
|
100
|
-
|
101
|
-
it "starts the AGI server" do
|
102
|
-
initialize_asterisk_with_defaults
|
103
|
-
flexmock(Adhearsion::VoIP::Asterisk::AGI::Server).new_instances.should_receive(:start).once
|
104
|
-
end
|
105
|
-
|
106
|
-
it "starts the AGI server with any overridden settings" do
|
107
|
-
overrides = {:host => "127.0.0.1", :port => 7788}
|
108
|
-
config_overrides = {:listening_host => overrides[:host], :listening_port => overrides[:port]}
|
109
|
-
initialize_asterisk_with_options config_overrides
|
110
|
-
flexmock(Adhearsion::VoIP::Asterisk::AGI::Server).new_instances.should_receive(:start).once.with(overrides)
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "The Rails initializer" do
|
116
|
-
|
117
|
-
include RailsInitializerTestHelper
|
118
|
-
|
119
|
-
it "should load the config/environment.rb file within the rails_root path" do
|
120
|
-
rails_root = "/path/to/rails/app"
|
121
|
-
environment_rb = rails_root + '/config/environment.rb'
|
122
|
-
flexmock(Adhearsion::Initializer::RailsInitializer).should_receive(:require).once.with environment_rb
|
123
|
-
stub_file_checking_methods!
|
124
|
-
stub_before_call_hook!
|
125
|
-
initialize_rails_with_options :rails_root => rails_root, :environment => :development
|
126
|
-
end
|
127
|
-
|
128
|
-
it "should raise an exception if the database is initialized at the same time" do
|
129
|
-
flexstub(Adhearsion::AHN_CONFIG).should_receive(:database_enabled?).and_return true
|
130
|
-
flexmock(Adhearsion::Initializer::RailsInitializer).should_receive(:require).and_return
|
131
|
-
stub_file_checking_methods!
|
132
|
-
stub_before_call_hook!
|
133
|
-
the_following_code {
|
134
|
-
initialize_rails_with_options :rails_root => '/tmp', :environment => :development
|
135
|
-
}.should raise_error
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should set the RAILS_ENV to be the argument passed in" do
|
139
|
-
flexmock(Adhearsion::Initializer::RailsInitializer).should_receive(:require).once.and_return
|
140
|
-
stub_file_checking_methods!
|
141
|
-
stub_before_call_hook!
|
142
|
-
initialize_rails_with_options :rails_root => '/tmp', :environment => :development
|
143
|
-
raise Test::Unit::AssertionFailed, 'ENV["RAILS_ENV"] should have been set but was not.' unless ENV['RAILS_ENV'] == "development"
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'should create a BeforeCall hook (presumably to verify the active connections)' do
|
147
|
-
flexstub(Adhearsion::Initializer::RailsInitializer).should_receive :require
|
148
|
-
flexstub(Adhearsion::Initializer::RailsInitializer).should_receive :load_rails
|
149
|
-
stub_file_checking_methods!
|
150
|
-
flexmock(Adhearsion::Events).should_receive(:register_callback).once.with([:asterisk, :before_call], Proc)
|
151
|
-
initialize_rails_with_options :rails_root => '/path/somewhere', :environment => :development
|
152
|
-
end
|
153
|
-
|
154
|
-
end
|