sevenscale-adhearsion 0.7.1000
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +3 -0
- data/LICENSE +456 -0
- data/Manifest.txt +149 -0
- data/README.txt +6 -0
- data/Rakefile +48 -0
- data/ahn_generators/component/USAGE +5 -0
- data/ahn_generators/component/component_generator.rb +57 -0
- data/ahn_generators/component/templates/configuration.rb +0 -0
- data/ahn_generators/component/templates/lib/lib.rb.erb +3 -0
- data/ahn_generators/component/templates/test/test.rb.erb +12 -0
- data/ahn_generators/component/templates/test/test_helper.rb +14 -0
- data/app_generators/ahn/USAGE +5 -0
- data/app_generators/ahn/ahn_generator.rb +76 -0
- data/app_generators/ahn/templates/.ahnrc +12 -0
- data/app_generators/ahn/templates/README +8 -0
- data/app_generators/ahn/templates/Rakefile +3 -0
- data/app_generators/ahn/templates/components/simon_game/configuration.rb +0 -0
- data/app_generators/ahn/templates/components/simon_game/lib/simon_game.rb +61 -0
- data/app_generators/ahn/templates/components/simon_game/test/test_helper.rb +14 -0
- data/app_generators/ahn/templates/components/simon_game/test/test_simon_game.rb +31 -0
- data/app_generators/ahn/templates/config/startup.rb +53 -0
- data/app_generators/ahn/templates/dialplan.rb +4 -0
- data/bin/ahn +28 -0
- data/bin/ahnctl +68 -0
- data/bin/jahn +32 -0
- data/lib/adhearsion/blank_slate.rb +5 -0
- data/lib/adhearsion/cli.rb +106 -0
- data/lib/adhearsion/component_manager.rb +277 -0
- data/lib/adhearsion/core_extensions/all.rb +9 -0
- data/lib/adhearsion/core_extensions/array.rb +0 -0
- data/lib/adhearsion/core_extensions/custom_daemonizer.rb +45 -0
- data/lib/adhearsion/core_extensions/global.rb +1 -0
- data/lib/adhearsion/core_extensions/guid.rb +5 -0
- data/lib/adhearsion/core_extensions/hash.rb +0 -0
- data/lib/adhearsion/core_extensions/metaprogramming.rb +17 -0
- data/lib/adhearsion/core_extensions/numeric.rb +4 -0
- data/lib/adhearsion/core_extensions/proc.rb +0 -0
- data/lib/adhearsion/core_extensions/pseudo_uuid.rb +11 -0
- data/lib/adhearsion/core_extensions/publishable.rb +73 -0
- data/lib/adhearsion/core_extensions/relationship_properties.rb +40 -0
- data/lib/adhearsion/core_extensions/string.rb +26 -0
- data/lib/adhearsion/core_extensions/thread.rb +13 -0
- data/lib/adhearsion/core_extensions/thread_safety.rb +7 -0
- data/lib/adhearsion/core_extensions/time.rb +0 -0
- data/lib/adhearsion/distributed/gateways/dbus_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/osa_gateway.rb +0 -0
- data/lib/adhearsion/distributed/gateways/rest_gateway.rb +9 -0
- data/lib/adhearsion/distributed/gateways/soap_gateway.rb +9 -0
- data/lib/adhearsion/distributed/gateways/xmlrpc_gateway.rb +9 -0
- data/lib/adhearsion/distributed/peer_finder.rb +0 -0
- data/lib/adhearsion/distributed/remote_cli.rb +0 -0
- data/lib/adhearsion/hooks.rb +57 -0
- data/lib/adhearsion/host_definitions.rb +63 -0
- data/lib/adhearsion/initializer/asterisk.rb +59 -0
- data/lib/adhearsion/initializer/configuration.rb +202 -0
- data/lib/adhearsion/initializer/database.rb +92 -0
- data/lib/adhearsion/initializer/drb.rb +25 -0
- data/lib/adhearsion/initializer/freeswitch.rb +22 -0
- data/lib/adhearsion/initializer/paths.rb +55 -0
- data/lib/adhearsion/initializer/rails.rb +40 -0
- data/lib/adhearsion/initializer.rb +217 -0
- data/lib/adhearsion/logging.rb +92 -0
- data/lib/adhearsion/services/scheduler.rb +5 -0
- data/lib/adhearsion/tasks/database.rb +5 -0
- data/lib/adhearsion/tasks/generating.rb +20 -0
- data/lib/adhearsion/tasks/lint.rb +4 -0
- data/lib/adhearsion/tasks/testing.rb +37 -0
- data/lib/adhearsion/tasks.rb +15 -0
- data/lib/adhearsion/version.rb +9 -0
- data/lib/adhearsion/voip/asterisk/agi_server.rb +78 -0
- data/lib/adhearsion/voip/asterisk/ami/actions.rb +238 -0
- data/lib/adhearsion/voip/asterisk/ami/machine.rb +871 -0
- data/lib/adhearsion/voip/asterisk/ami/machine.rl +109 -0
- data/lib/adhearsion/voip/asterisk/ami/parser.rb +262 -0
- data/lib/adhearsion/voip/asterisk/ami.rb +147 -0
- data/lib/adhearsion/voip/asterisk/commands.rb +1186 -0
- data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +140 -0
- data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +101 -0
- data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +250 -0
- data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +240 -0
- data/lib/adhearsion/voip/asterisk/config_manager.rb +71 -0
- data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +80 -0
- data/lib/adhearsion/voip/asterisk.rb +4 -0
- data/lib/adhearsion/voip/call.rb +402 -0
- data/lib/adhearsion/voip/call_routing.rb +64 -0
- data/lib/adhearsion/voip/commands.rb +9 -0
- data/lib/adhearsion/voip/constants.rb +39 -0
- data/lib/adhearsion/voip/conveniences.rb +18 -0
- data/lib/adhearsion/voip/dial_plan.rb +205 -0
- data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +37 -0
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +151 -0
- data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +27 -0
- data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +124 -0
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +75 -0
- data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +16 -0
- data/lib/adhearsion/voip/dsl/numerical_string.rb +117 -0
- data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +48 -0
- data/lib/adhearsion/voip/freeswitch/event_handler.rb +58 -0
- data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +129 -0
- data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +38 -0
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +195 -0
- data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +80 -0
- data/lib/adhearsion/voip/menu_state_machine/matchers.rb +123 -0
- data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +58 -0
- data/lib/adhearsion/voip/menu_state_machine/menu_class.rb +149 -0
- data/lib/adhearsion.rb +31 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/fixtures/dialplan.rb +3 -0
- data/spec/initializer/test_configuration.rb +267 -0
- data/spec/initializer/test_loading.rb +162 -0
- data/spec/initializer/test_paths.rb +43 -0
- data/spec/silence.rb +10 -0
- data/spec/test_ahn_command.rb +149 -0
- data/spec/test_code_quality.rb +87 -0
- data/spec/test_component_manager.rb +97 -0
- data/spec/test_constants.rb +8 -0
- data/spec/test_drb.rb +104 -0
- data/spec/test_helper.rb +94 -0
- data/spec/test_hooks.rb +37 -0
- data/spec/test_host_definitions.rb +79 -0
- data/spec/test_initialization.rb +105 -0
- data/spec/test_logging.rb +80 -0
- data/spec/test_relationship_properties.rb +54 -0
- data/spec/voip/asterisk/ami_response_definitions.rb +23 -0
- data/spec/voip/asterisk/config_file_generators/test_agents.rb +253 -0
- data/spec/voip/asterisk/config_file_generators/test_queues.rb +325 -0
- data/spec/voip/asterisk/config_file_generators/test_voicemail.rb +306 -0
- data/spec/voip/asterisk/menu_command/test_calculated_match.rb +111 -0
- data/spec/voip/asterisk/menu_command/test_matchers.rb +98 -0
- data/spec/voip/asterisk/mock_ami_server.rb +176 -0
- data/spec/voip/asterisk/test_agi_server.rb +453 -0
- data/spec/voip/asterisk/test_ami.rb +227 -0
- data/spec/voip/asterisk/test_commands.rb +2006 -0
- data/spec/voip/asterisk/test_config_manager.rb +129 -0
- data/spec/voip/dsl/dispatcher_spec_helper.rb +45 -0
- data/spec/voip/dsl/test_dialing_dsl.rb +268 -0
- data/spec/voip/dsl/test_dispatcher.rb +82 -0
- data/spec/voip/dsl/test_parser.rb +87 -0
- data/spec/voip/freeswitch/test_basic_connection_manager.rb +39 -0
- data/spec/voip/freeswitch/test_inbound_connection_manager.rb +39 -0
- data/spec/voip/freeswitch/test_oes_server.rb +9 -0
- data/spec/voip/test_call_routing.rb +127 -0
- data/spec/voip/test_dialplan_manager.rb +372 -0
- data/spec/voip/test_numerical_string.rb +48 -0
- data/spec/voip/test_phone_number.rb +36 -0
- data/test/test_ahn_generator.rb +59 -0
- data/test/test_component_generator.rb +52 -0
- data/test/test_generator_helper.rb +20 -0
- metadata +254 -0
data/spec/test_helper.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
Dir.chdir File.join(File.dirname(__FILE__), '..')
|
2
|
+
require 'rubygems'
|
3
|
+
def require_or_report_dependency(require_name, gem_name)
|
4
|
+
begin
|
5
|
+
require require_name
|
6
|
+
rescue LoadError
|
7
|
+
report_dependency!(gem_name)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def report_dependency!(name)
|
12
|
+
puts;puts
|
13
|
+
puts "You need #{name} to run these tests: gem install #{name}"
|
14
|
+
puts;puts
|
15
|
+
exit!
|
16
|
+
end
|
17
|
+
|
18
|
+
require_or_report_dependency('test/spec', 'test-spec')
|
19
|
+
require_or_report_dependency('flexmock/test_unit', 'flexmock')
|
20
|
+
require_or_report_dependency('active_support', 'activesupport')
|
21
|
+
# require_or_report_dependency('ruby-debug', 'ruby-debug')
|
22
|
+
require_or_report_dependency('rubigen', 'rubigen')
|
23
|
+
|
24
|
+
require 'pp'
|
25
|
+
require 'stringio'
|
26
|
+
|
27
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
28
|
+
$: << File.expand_path('lib')
|
29
|
+
$: << File.dirname(__FILE__)
|
30
|
+
|
31
|
+
require 'adhearsion'
|
32
|
+
class Adhearsion::Initializer
|
33
|
+
def asterisk_enabled?
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
class Test::Unit::TestCase
|
42
|
+
|
43
|
+
alias_method :the_following_code, :lambda
|
44
|
+
def self.test(*args, &block)
|
45
|
+
if block_given?
|
46
|
+
specify(args, &block)
|
47
|
+
else
|
48
|
+
disabled_test(*args)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.disabled_test(*args, &block)
|
53
|
+
xspecify(*args, &block)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
module InitializerStubs
|
59
|
+
|
60
|
+
UNWANTED_BEHAVIOR = {
|
61
|
+
Adhearsion::Initializer => [:initialize_log_file, :switch_to_root_directory, :daemonize!],
|
62
|
+
Adhearsion::Hooks::AfterInitialized.metaclass => [:create_hook, :trigger_hooks]
|
63
|
+
} unless defined? UNWANTED_BEHAVIOR
|
64
|
+
|
65
|
+
def with_new_initializer_with_no_path_changing_behavior
|
66
|
+
stub_unwanted_behavior
|
67
|
+
Adhearsion::Initializer.new('path does not matter')
|
68
|
+
yield if block_given?
|
69
|
+
unstub_directory_changing_behavior
|
70
|
+
end
|
71
|
+
|
72
|
+
def stub_unwanted_behavior
|
73
|
+
UNWANTED_BEHAVIOR.each do |stub_victim_class, undesired_methods|
|
74
|
+
undesired_methods.each do |undesired_method_name|
|
75
|
+
stub_victim_class.send(:alias_method, "pre_stubbed_#{undesired_method_name}", undesired_method_name)
|
76
|
+
stub_victim_class.send(:define_method, undesired_method_name) { |*args| }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def unstub_directory_changing_behavior
|
82
|
+
UNWANTED_BEHAVIOR.each do |stub_victim_class, undesired_methods|
|
83
|
+
undesired_methods.each do |undesired_method_name|
|
84
|
+
stub_victim_class.send(:alias_method, undesired_method_name, "pre_stubbed_#{undesired_method_name}")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
Adhearsion::Initializer.ahn_root = File.dirname(__FILE__) + '/fixtures'
|
91
|
+
require 'spec/silence' unless ENV['SHOW_DISABLED']
|
92
|
+
|
93
|
+
require 'adhearsion/voip/asterisk'
|
94
|
+
require 'adhearsion/component_manager'
|
data/spec/test_hooks.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper.rb"
|
2
|
+
|
3
|
+
# context "Adhearsion::Hooks::TearDown when initializing a project" do
|
4
|
+
# include InitializerStubs
|
5
|
+
# test "should trap TERM and INT signals" do
|
6
|
+
# flexmock(Adhearsion::Hooks::TearDown).should_receive(:catch_termination_signals).at_least.once
|
7
|
+
# with_new_initializer_with_no_path_changing_behavior {}
|
8
|
+
# end
|
9
|
+
# end
|
10
|
+
|
11
|
+
# module StandardHookBehavior
|
12
|
+
# def test_standard_hook_behavior
|
13
|
+
# @hook.should.respond_to(:trigger_hooks)
|
14
|
+
# @hook.should.respond_to(:create_hook)
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
|
18
|
+
# for hook in Adhearsion::Hooks.constants.map { |c| (Adhearsion::Hooks.const_get c) }
|
19
|
+
# describe hook.to_s do
|
20
|
+
# include StandardHookBehavior
|
21
|
+
# before(:each) { @hook = hook }
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
|
25
|
+
context "A HookWithArguments" do
|
26
|
+
test "should pass the arguments to trigger_hooks() along to each registered block" do
|
27
|
+
hook_manager = Adhearsion::Hooks::HookWithArguments.new
|
28
|
+
hook_manager.create_hook do |foo, bar|
|
29
|
+
foo.should.equal :foo
|
30
|
+
bar.should.equal :bar
|
31
|
+
throw :inside_hook
|
32
|
+
end
|
33
|
+
the_following_code {
|
34
|
+
hook_manager.trigger_hooks(:foo, :bar)
|
35
|
+
}.should.throw :inside_hook
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
|
+
require 'adhearsion/host_definitions'
|
3
|
+
|
4
|
+
context 'HostDefinition' do
|
5
|
+
|
6
|
+
after :each do
|
7
|
+
Adhearsion::HostDefinition.clear_definitions!
|
8
|
+
end
|
9
|
+
|
10
|
+
test '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
|
+
test '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
|
+
test '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
|
+
test 'should have an Array class variable named definitions' do
|
38
|
+
Adhearsion::HostDefinition.definitions.should.be.kind_of Array
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'should add each HostDefinition to a class variable named @@definitions when instantiated' do
|
42
|
+
Adhearsion::HostDefinition.definitions.size.should.equal 0
|
43
|
+
Adhearsion::HostDefinition.new :name => "foobar", :host => "hostname", :username => "user", :password => "password"
|
44
|
+
Adhearsion::HostDefinition.definitions.size.should.equal 1
|
45
|
+
Adhearsion::HostDefinition.clear_definitions!
|
46
|
+
Adhearsion::HostDefinition.definitions.size.should.equal 0
|
47
|
+
end
|
48
|
+
|
49
|
+
test '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 Adhearsion::HostDefinition::HostDefinitionException
|
53
|
+
end
|
54
|
+
|
55
|
+
test '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 Adhearsion::HostDefinition::HostDefinitionException
|
59
|
+
end
|
60
|
+
|
61
|
+
test '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 Adhearsion::HostDefinition::HostDefinitionException
|
65
|
+
end
|
66
|
+
|
67
|
+
test '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 Adhearsion::HostDefinition::HostDefinitionException
|
71
|
+
end
|
72
|
+
|
73
|
+
test '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 Adhearsion::HostDefinition::HostDefinitionException
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
context "Adhearsion::Initializer" do
|
4
|
+
|
5
|
+
include InitializerStubs
|
6
|
+
# TODO: create a specification for aliases
|
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
|
12
|
+
|
13
|
+
test "initialization will start with only a path given" do
|
14
|
+
with_new_initializer_with_no_path_changing_behavior do
|
15
|
+
Adhearsion::Initializer.new path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
test "should create a pid file in the app's path when given 'true' as the pid_file hash key argument" do
|
20
|
+
with_new_initializer_with_no_path_changing_behavior do
|
21
|
+
flexmock(File).should_receive(:open).once.with(File.join(path, 'adhearsion.pid'), 'w', Proc)
|
22
|
+
ahn = Adhearsion::Initializer.new path, :pid_file => true
|
23
|
+
ahn.pid_file[0, path.length].should.equal(path)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
test "should NOT create a pid file in the app's path when given 'false' as the pid_file hash key argument" do
|
28
|
+
with_new_initializer_with_no_path_changing_behavior do
|
29
|
+
ahn = Adhearsion::Initializer.new path, :pid_file => false
|
30
|
+
assert_nil ahn.pid_file
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
test "should create a pid file in the app's path by default when daemonizing" do
|
35
|
+
with_new_initializer_with_no_path_changing_behavior do
|
36
|
+
flexmock(File).should_receive(:open).once.with(File.join(path, 'adhearsion.pid'), 'w', Proc)
|
37
|
+
ahn = Adhearsion::Initializer.new path, :daemon => true
|
38
|
+
ahn.pid_file[0, path.size].should.equal(path)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
test "should NOT create a pid file in the app's path when daemonizing and :pid_file is given as false" do
|
43
|
+
with_new_initializer_with_no_path_changing_behavior do
|
44
|
+
ahn = Adhearsion::Initializer.new path, :daemon => true, :pid_file => false
|
45
|
+
assert_nil ahn.pid_file
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
test "should create a designated pid file when supplied a String path as :pid_file" do
|
50
|
+
random_file = "/tmp/AHN_TEST_#{rand 100000}.pid"
|
51
|
+
with_new_initializer_with_no_path_changing_behavior do
|
52
|
+
ahn = Adhearsion::Initializer.new path, :pid_file => random_file
|
53
|
+
ahn.pid_file.should.equal(random_file)
|
54
|
+
assert File.exists?(random_file)
|
55
|
+
File.delete random_file
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def path
|
61
|
+
'/any/ole/path'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "AHN_ROOT" do
|
66
|
+
include InitializerStubs
|
67
|
+
setup do
|
68
|
+
Object.send(:remove_const, :AHN_ROOT) if defined? AHN_ROOT
|
69
|
+
end
|
70
|
+
|
71
|
+
test "initializing will create the AHN_ROOT" do
|
72
|
+
with_new_initializer_with_no_path_changing_behavior do
|
73
|
+
ahn = Adhearsion::Initializer.new path
|
74
|
+
assert Object.constants.include?("AHN_ROOT")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
test "swapping out the base_path for the duration of the block" do
|
79
|
+
original_base_path = '.'
|
80
|
+
temporary_base = '/foo'
|
81
|
+
|
82
|
+
path = Adhearsion::PathString.new(original_base_path)
|
83
|
+
path.should.equal original_base_path
|
84
|
+
|
85
|
+
path.using_base_path temporary_base do
|
86
|
+
path.should.equal temporary_base
|
87
|
+
end
|
88
|
+
path.should.equal original_base_path
|
89
|
+
end
|
90
|
+
|
91
|
+
test "creating the AHN_ROOT will set defaults" do
|
92
|
+
with_new_initializer_with_no_path_changing_behavior do
|
93
|
+
ahn = Adhearsion::Initializer.new path
|
94
|
+
full_path = File.expand_path(path)
|
95
|
+
AHN_ROOT.to_s.should.equal(full_path)
|
96
|
+
AHN_ROOT.component_path.should.equal(File.join(full_path, "components"))
|
97
|
+
AHN_ROOT.log_path.should.equal(File.join(full_path, "logs"))
|
98
|
+
AHN_ROOT.dialplan_path.should.equal(full_path)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
private
|
102
|
+
def path
|
103
|
+
'/any/ole/path'
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper"
|
2
|
+
|
3
|
+
context 'The ahn_log command' do
|
4
|
+
|
5
|
+
test 'should add the ahn_log method to the global namespace' do
|
6
|
+
ahn_log.should.be Adhearsion::Logging::DefaultAdhearsionLogger
|
7
|
+
end
|
8
|
+
|
9
|
+
test "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
|
13
|
+
end
|
14
|
+
|
15
|
+
test '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
|
18
|
+
end
|
19
|
+
|
20
|
+
test '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.should.include 'agi'
|
23
|
+
end
|
24
|
+
|
25
|
+
test "dynamically generated loggers should support logging with blocks" do
|
26
|
+
# I had to comment out this test because Flexmock makes it impossible to#
|
27
|
+
# set up an expectation for receiving blocks.
|
28
|
+
|
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)
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'new loggers created by method_missing() should be instances of AdhearsionLogger' do
|
41
|
+
ahn_log.qwerty.should.be.kind_of Adhearsion::Logging::AdhearsionLogger
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
# Essential for running the tests
|
47
|
+
context 'Logger level changing' do
|
48
|
+
|
49
|
+
after :each do
|
50
|
+
Adhearsion::Logging.logging_level = :info
|
51
|
+
end
|
52
|
+
|
53
|
+
after :all do
|
54
|
+
Adhearsion::Logging.logging_level = :fatal # Silence them again
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'changing the logging level should affect all loggers' do
|
58
|
+
loggers = [ahn_log.one, ahn_log.two, ahn_log.three]
|
59
|
+
loggers.map(&:level).should.not == [Log4r::WARN] * 3
|
60
|
+
Adhearsion::Logging.logging_level = :warn
|
61
|
+
loggers.map(&:level).should == [Log4r::WARN] * 3
|
62
|
+
end
|
63
|
+
|
64
|
+
test 'a new logger should have the global Adhearsion logging level' do
|
65
|
+
ahn_log.foo.level.should.equal Log4r::INFO
|
66
|
+
Adhearsion::Logging.logging_level = :fatal
|
67
|
+
ahn_log.brand_new.level.should.equal Log4r::FATAL
|
68
|
+
end
|
69
|
+
|
70
|
+
test '#silence!() should change the level to be FATAL' do
|
71
|
+
flexmock(Adhearsion::Logging::DefaultAdhearsionLogger).should_receive(:level=).once.with(Log4r::FATAL)
|
72
|
+
Adhearsion::Logging.silence!
|
73
|
+
end
|
74
|
+
|
75
|
+
test '#unsilence!() should change the level to be INFO' do
|
76
|
+
flexmock(Adhearsion::Logging::DefaultAdhearsionLogger).should_receive(:level=).once.with(Log4r::INFO)
|
77
|
+
Adhearsion::Logging.unsilence!
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/test_helper.rb"
|
2
|
+
require 'adhearsion/core_extensions/relationship_properties'
|
3
|
+
|
4
|
+
describe "Module#relationships" do
|
5
|
+
|
6
|
+
describe "Overriding relationships in subclasses" do
|
7
|
+
|
8
|
+
it "should be overridable in subclasses" do
|
9
|
+
super_class = Class.new do
|
10
|
+
relationships :storage_medium => Array
|
11
|
+
end
|
12
|
+
sub_class = Class.new(super_class) do
|
13
|
+
relationships :storage_medium => Hash
|
14
|
+
end
|
15
|
+
super_class.new.send(:storage_medium).should.equal Array
|
16
|
+
sub_class.new.send(:storage_medium).should.equal Hash
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not affect other defined relationships" do
|
20
|
+
super_class = Class.new do
|
21
|
+
relationships :io_class => TCPSocket, :error_class => StandardError
|
22
|
+
end
|
23
|
+
sub_class = Class.new(super_class) do
|
24
|
+
relationships :error_class => RuntimeError
|
25
|
+
end
|
26
|
+
super_class.new.send(:io_class).should.equal TCPSocket
|
27
|
+
sub_class.new.send(:io_class).should.equal TCPSocket
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be accessible within instance methods of that Class as another instance method" do
|
33
|
+
klass = Class.new do
|
34
|
+
relationships :struct => Struct
|
35
|
+
def new_struct
|
36
|
+
struct.new
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be accessible in subclasses" do
|
42
|
+
super_class = Class.new do
|
43
|
+
relationships :number_class => Bignum
|
44
|
+
end
|
45
|
+
|
46
|
+
Class.new(super_class) do
|
47
|
+
def number_class_name
|
48
|
+
number_class.name
|
49
|
+
end
|
50
|
+
end.new.number_class_name.should == "Bignum"
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
def ami(m, &block) context("AMI", "##{m}", &block) end
|
2
|
+
|
3
|
+
ami:ping do
|
4
|
+
test "should return the number of seconds before a response if reachable"
|
5
|
+
test "should raise a PingError if unreachable"
|
6
|
+
end
|
7
|
+
|
8
|
+
ami:agents do
|
9
|
+
test "should return an Array of Agent objects"
|
10
|
+
test "should convert the logged-in time to a Ruby DateTime"
|
11
|
+
test "should convert the logged-in status to a Symbol"
|
12
|
+
test "should work with known logged-in statuses"
|
13
|
+
test "should convert unrecognized logged-in statuses to :unknown"
|
14
|
+
end
|
15
|
+
|
16
|
+
ami:queues do
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
ami:state_of_extension do
|
21
|
+
test "should take one argument"
|
22
|
+
test "should "
|
23
|
+
end
|