sevenscale-adhearsion 0.7.1003 → 0.8.0
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 +8 -2
- data/EVENTS +11 -0
- data/Rakefile +92 -26
- data/adhearsion.gemspec +131 -23
- data/app_generators/ahn/ahn_generator.rb +21 -7
- data/app_generators/ahn/templates/.ahnrc +10 -4
- data/app_generators/ahn/templates/Rakefile +7 -2
- data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +15 -0
- data/app_generators/ahn/templates/components/disabled/HOW_TO_ENABLE +7 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +47 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/config.yml +12 -0
- data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +34 -0
- data/app_generators/ahn/templates/components/simon_game/{lib/simon_game.rb → simon_game.rb} +14 -19
- data/app_generators/ahn/templates/config/startup.rb +3 -6
- data/app_generators/ahn/templates/dialplan.rb +2 -3
- data/app_generators/ahn/templates/events.rb +32 -6
- data/bin/jahn +10 -0
- data/examples/asterisk_manager_interface/standalone.rb +51 -0
- data/lib/adhearsion/cli.rb +140 -23
- data/lib/adhearsion/component_manager/component_tester.rb +55 -0
- data/lib/adhearsion/component_manager/spec_framework.rb +24 -0
- data/lib/adhearsion/component_manager.rb +169 -238
- data/lib/adhearsion/events_support.rb +59 -237
- data/lib/adhearsion/{core_extensions → foundation}/all.rb +0 -0
- data/lib/adhearsion/{blank_slate.rb → foundation/blank_slate.rb} +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/custom_daemonizer.rb +0 -0
- data/lib/adhearsion/foundation/event_socket.rb +203 -0
- data/lib/adhearsion/foundation/future_resource.rb +36 -0
- data/lib/adhearsion/{core_extensions → foundation}/global.rb +0 -0
- data/lib/adhearsion/{core_extensions → foundation}/metaprogramming.rb +0 -0
- data/lib/adhearsion/foundation/numeric.rb +13 -0
- data/lib/adhearsion/foundation/pseudo_guid.rb +10 -0
- data/lib/adhearsion/{core_extensions → foundation}/relationship_properties.rb +2 -0
- data/lib/adhearsion/foundation/string.rb +26 -0
- data/lib/adhearsion/foundation/synchronized_hash.rb +96 -0
- data/lib/adhearsion/{core_extensions → foundation}/thread_safety.rb +0 -0
- data/lib/adhearsion/host_definitions.rb +5 -1
- data/lib/adhearsion/initializer/asterisk.rb +33 -11
- data/lib/adhearsion/initializer/configuration.rb +58 -6
- data/lib/adhearsion/initializer/database.rb +3 -46
- data/lib/adhearsion/initializer/drb.rb +9 -3
- data/lib/adhearsion/initializer/freeswitch.rb +3 -3
- data/lib/adhearsion/initializer/rails.rb +1 -1
- data/lib/adhearsion/initializer.rb +213 -87
- data/lib/adhearsion/tasks/deprecations.rb +59 -0
- data/lib/adhearsion/tasks.rb +2 -1
- data/lib/adhearsion/version.rb +3 -3
- data/lib/adhearsion/voip/asterisk/agi_server.rb +6 -6
- data/lib/adhearsion/voip/asterisk/commands.rb +100 -2
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +1754 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +286 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +78 -0
- data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +87 -0
- data/lib/adhearsion/voip/asterisk/manager_interface.rb +562 -0
- data/lib/adhearsion/voip/asterisk/super_manager.rb +19 -0
- data/lib/adhearsion/voip/asterisk.rb +1 -8
- data/lib/adhearsion/voip/call.rb +5 -1
- data/lib/adhearsion/voip/dial_plan.rb +74 -61
- data/lib/adhearsion/voip/dsl/dialing_dsl.rb +1 -1
- data/lib/adhearsion/voip/dsl/dialplan/parser.rb +2 -6
- data/lib/adhearsion/voip/dsl/numerical_string.rb +2 -2
- data/lib/adhearsion/voip/freeswitch/oes_server.rb +2 -2
- data/lib/adhearsion.rb +16 -11
- data/lib/theatre/README.markdown +64 -0
- data/lib/theatre/callback_definition_loader.rb +84 -0
- data/lib/theatre/guid.rb +23 -0
- data/lib/theatre/invocation.rb +121 -0
- data/lib/theatre/namespace_manager.rb +153 -0
- data/lib/theatre/version.rb +2 -0
- data/lib/theatre.rb +151 -0
- metadata +60 -147
- data/Manifest.txt +0 -151
- data/README.txt +0 -5
- data/ahn_generators/component/USAGE +0 -5
- data/ahn_generators/component/component_generator.rb +0 -57
- data/ahn_generators/component/templates/configuration.rb +0 -0
- data/ahn_generators/component/templates/lib/lib.rb.erb +0 -3
- data/ahn_generators/component/templates/test/test.rb.erb +0 -12
- data/ahn_generators/component/templates/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/configuration.rb +0 -0
- data/app_generators/ahn/templates/components/simon_game/test/test_helper.rb +0 -14
- data/app_generators/ahn/templates/components/simon_game/test/test_simon_game.rb +0 -31
- data/lib/adhearsion/core_extensions/array.rb +0 -0
- data/lib/adhearsion/core_extensions/guid.rb +0 -5
- data/lib/adhearsion/core_extensions/hash.rb +0 -0
- data/lib/adhearsion/core_extensions/numeric.rb +0 -4
- data/lib/adhearsion/core_extensions/proc.rb +0 -0
- data/lib/adhearsion/core_extensions/pseudo_uuid.rb +0 -11
- data/lib/adhearsion/core_extensions/publishable.rb +0 -73
- data/lib/adhearsion/core_extensions/string.rb +0 -26
- data/lib/adhearsion/core_extensions/thread.rb +0 -13
- 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 +0 -9
- data/lib/adhearsion/distributed/gateways/soap_gateway.rb +0 -9
- data/lib/adhearsion/distributed/gateways/xmlrpc_gateway.rb +0 -9
- data/lib/adhearsion/distributed/peer_finder.rb +0 -0
- data/lib/adhearsion/distributed/remote_cli.rb +0 -0
- data/lib/adhearsion/hooks.rb +0 -57
- data/lib/adhearsion/initializer/paths.rb +0 -55
- data/lib/adhearsion/voip/asterisk/ami/actions.rb +0 -238
- data/lib/adhearsion/voip/asterisk/ami/machine.rb +0 -871
- data/lib/adhearsion/voip/asterisk/ami/machine.rl +0 -109
- data/lib/adhearsion/voip/asterisk/ami/parser.rb +0 -262
- data/lib/adhearsion/voip/asterisk/ami.rb +0 -147
- data/spec/fixtures/dialplan.rb +0 -3
- data/spec/initializer/test_configuration.rb +0 -267
- data/spec/initializer/test_loading.rb +0 -162
- data/spec/initializer/test_paths.rb +0 -43
- data/spec/sample.rb +0 -9
- data/spec/silence.rb +0 -10
- data/spec/test_ahn_command.rb +0 -149
- data/spec/test_code_quality.rb +0 -87
- data/spec/test_component_manager.rb +0 -97
- data/spec/test_constants.rb +0 -8
- data/spec/test_drb.rb +0 -104
- data/spec/test_events.rb +0 -136
- data/spec/test_helper.rb +0 -106
- data/spec/test_hooks.rb +0 -15
- data/spec/test_host_definitions.rb +0 -79
- data/spec/test_initialization.rb +0 -124
- data/spec/test_logging.rb +0 -80
- data/spec/test_relationship_properties.rb +0 -54
- data/spec/voip/asterisk/ami_response_definitions.rb +0 -23
- data/spec/voip/asterisk/config_file_generators/test_agents.rb +0 -253
- data/spec/voip/asterisk/config_file_generators/test_queues.rb +0 -325
- data/spec/voip/asterisk/config_file_generators/test_voicemail.rb +0 -306
- data/spec/voip/asterisk/menu_command/test_calculated_match.rb +0 -111
- data/spec/voip/asterisk/menu_command/test_matchers.rb +0 -98
- data/spec/voip/asterisk/mock_ami_server.rb +0 -176
- data/spec/voip/asterisk/test_agi_server.rb +0 -453
- data/spec/voip/asterisk/test_ami.rb +0 -227
- data/spec/voip/asterisk/test_commands.rb +0 -2006
- data/spec/voip/asterisk/test_config_manager.rb +0 -129
- data/spec/voip/dsl/dispatcher_spec_helper.rb +0 -45
- data/spec/voip/dsl/test_dialing_dsl.rb +0 -268
- data/spec/voip/dsl/test_dispatcher.rb +0 -82
- data/spec/voip/dsl/test_parser.rb +0 -87
- data/spec/voip/freeswitch/test_basic_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_inbound_connection_manager.rb +0 -39
- data/spec/voip/freeswitch/test_oes_server.rb +0 -9
- data/spec/voip/test_call_routing.rb +0 -127
- data/spec/voip/test_dialplan_manager.rb +0 -442
- data/spec/voip/test_numerical_string.rb +0 -48
- data/spec/voip/test_phone_number.rb +0 -36
- data/test/test_ahn_generator.rb +0 -59
- data/test/test_component_generator.rb +0 -52
- data/test/test_generator_helper.rb +0 -20
data/spec/test_initialization.rb
DELETED
@@ -1,124 +0,0 @@
|
|
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
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
15
|
-
Adhearsion::Initializer.start 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
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
21
|
-
flexmock(File).should_receive(:open).with(File.join(path, 'adhearsion.pid'), 'w', Proc).at_least.once
|
22
|
-
ahn = Adhearsion::Initializer.start 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
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
29
|
-
ahn = Adhearsion::Initializer.start 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
|
-
stub_behavior_for_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.start 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
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
44
|
-
ahn = Adhearsion::Initializer.start path, :daemon => true, :pid_file => false
|
45
|
-
assert_nil ahn.pid_file
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
test "should execute gem when .ahnrc contains gem names" do
|
50
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
51
|
-
ahn_rc = {
|
52
|
-
"gems" => {
|
53
|
-
"activerecord" => { "version" => ">= 1.2.0" },
|
54
|
-
"twitter" => nil
|
55
|
-
},
|
56
|
-
# Paths are unnecessary except to make the other part of bootstrap_rc happy.
|
57
|
-
"paths"=>{"dialplan"=>"dialplan.rb", "init"=>"config/startup.rb", "events"=>"events.rb",
|
58
|
-
"models"=>{"directory"=>"models", "pattern"=>"*.rb"}}
|
59
|
-
}
|
60
|
-
ahn = Adhearsion::Initializer.new path
|
61
|
-
flexmock(Adhearsion::Initializer).should_receive(:get_rules_from).once.and_return ahn_rc
|
62
|
-
flexmock(ahn).should_receive(:gem).once.with("activerecord", ">= 1.2.0")
|
63
|
-
flexmock(ahn).should_receive(:gem).once.with("twitter")
|
64
|
-
ahn.start
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
test "should create a designated pid file when supplied a String path as :pid_file" do
|
69
|
-
random_file = "/tmp/AHN_TEST_#{rand 100000}.pid"
|
70
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
71
|
-
ahn = Adhearsion::Initializer.start path, :pid_file => random_file
|
72
|
-
ahn.pid_file.should.equal(random_file)
|
73
|
-
assert File.exists?(random_file)
|
74
|
-
File.delete random_file
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
def path
|
80
|
-
'/any/ole/path'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "AHN_ROOT" do
|
85
|
-
include InitializerStubs
|
86
|
-
setup do
|
87
|
-
Object.send(:remove_const, :AHN_ROOT) if defined? AHN_ROOT
|
88
|
-
end
|
89
|
-
|
90
|
-
test "initializing will create the AHN_ROOT" do
|
91
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
92
|
-
ahn = Adhearsion::Initializer.start path
|
93
|
-
assert Object.constants.include?("AHN_ROOT")
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
test "swapping out the base_path for the duration of the block" do
|
98
|
-
original_base_path = '.'
|
99
|
-
temporary_base = '/foo'
|
100
|
-
|
101
|
-
path = Adhearsion::PathString.new(original_base_path)
|
102
|
-
path.should.equal original_base_path
|
103
|
-
|
104
|
-
path.using_base_path temporary_base do
|
105
|
-
path.should.equal temporary_base
|
106
|
-
end
|
107
|
-
path.should.equal original_base_path
|
108
|
-
end
|
109
|
-
|
110
|
-
test "creating the AHN_ROOT will set defaults" do
|
111
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
112
|
-
ahn = Adhearsion::Initializer.start path
|
113
|
-
full_path = File.expand_path(path)
|
114
|
-
AHN_ROOT.to_s.should.equal(full_path)
|
115
|
-
AHN_ROOT.component_path.should.equal(File.join(full_path, "components"))
|
116
|
-
AHN_ROOT.log_path.should.equal(File.join(full_path, "logs"))
|
117
|
-
AHN_ROOT.dialplan_path.should.equal(full_path)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
private
|
121
|
-
def path
|
122
|
-
'/any/ole/path'
|
123
|
-
end
|
124
|
-
end
|
data/spec/test_logging.rb
DELETED
@@ -1,80 +0,0 @@
|
|
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
|
@@ -1,54 +0,0 @@
|
|
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
|
@@ -1,23 +0,0 @@
|
|
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
|
@@ -1,253 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), *%w[.. .. .. test_helper])
|
2
|
-
require 'adhearsion/voip/asterisk/config_generators/agents.conf'
|
3
|
-
|
4
|
-
context "The agents.conf config file agents" do
|
5
|
-
|
6
|
-
include AgentsConfigFileGeneratorTestHelper
|
7
|
-
|
8
|
-
attr_reader :agents
|
9
|
-
before:each do
|
10
|
-
reset_agents!
|
11
|
-
end
|
12
|
-
test "The agent() method should enqueue a Hash into Agents#agent_definitions" do
|
13
|
-
agents.agent 1337, :password => 9876, :name => "Jay Phillips"
|
14
|
-
agents.agent_definitions.size.should.be 1
|
15
|
-
agents.agent_definitions.first.should == {:id => 1337, :password => 9876, :name => "Jay Phillips"}
|
16
|
-
end
|
17
|
-
|
18
|
-
test 'should add the warning message to the to_s output' do
|
19
|
-
agents.conf.should =~ /^\s*;.{10}/
|
20
|
-
end
|
21
|
-
|
22
|
-
test "The conf() method should always create a general section" do
|
23
|
-
agents.conf.should =~ /^\[general\]/
|
24
|
-
end
|
25
|
-
|
26
|
-
test "The agent() method should generate a proper String" do
|
27
|
-
agents.agent 123, :name => "Otto Normalverbraucher", :password => "007"
|
28
|
-
agents.agent 889, :name => "John Doe", :password => "998"
|
29
|
-
|
30
|
-
agents.conf.grep(/^agent =>/).map(&:strip).should == [
|
31
|
-
"agent => 123,007,Otto Normalverbraucher",
|
32
|
-
"agent => 889,998,John Doe"
|
33
|
-
]
|
34
|
-
end
|
35
|
-
|
36
|
-
test "The persistent_agents() method should generate a persistentagents yes/no pair" do
|
37
|
-
agents.persistent_agents true
|
38
|
-
generated_config_has_pair(:persistentagents => "yes").should.be true
|
39
|
-
|
40
|
-
reset_agents!
|
41
|
-
|
42
|
-
agents.persistent_agents false
|
43
|
-
generated_config_has_pair(:persistentagents => "no").should.be true
|
44
|
-
end
|
45
|
-
|
46
|
-
test "The persistent_agents() method should be in the [general] section" do
|
47
|
-
agents.persistent_agents true
|
48
|
-
agents.general_section.should == {:persistentagents => "yes"}
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
test "max_login_tries() should generate a 'maxlogintries' numerical pair" do
|
53
|
-
agents.max_login_tries 50
|
54
|
-
generated_config_has_pair(:maxlogintries => "50").should.be true
|
55
|
-
end
|
56
|
-
|
57
|
-
test "max_login_tries() should be in the agents section" do
|
58
|
-
agents.max_login_tries 0
|
59
|
-
agents.agent_section.should == {:maxlogintries => 0}
|
60
|
-
end
|
61
|
-
|
62
|
-
test "log_off_after_duration should generate autologoff" do
|
63
|
-
agents.log_off_after_duration 15.seconds
|
64
|
-
generated_config_has_pair(:autologoff => "15").should.be true
|
65
|
-
end
|
66
|
-
|
67
|
-
test "log_off_if_unavailable should add autologoffunavail to the agents section" do
|
68
|
-
agents.log_off_if_unavailable false
|
69
|
-
agents.agent_section.should == {:autologoffunavail => "no"}
|
70
|
-
end
|
71
|
-
|
72
|
-
test "require_hash_to_acknowledge() should generate a 'ackcall' yes/no pair" do
|
73
|
-
agents.require_hash_to_acknowledge false
|
74
|
-
agents.agent_section.should == {:ackcall => "no"}
|
75
|
-
end
|
76
|
-
|
77
|
-
test "allow_star_to_hangup should generate a 'endcall' yes/no pair" do
|
78
|
-
agents.allow_star_to_hangup false
|
79
|
-
agents.agent_section.should == {:endcall => "no"}
|
80
|
-
end
|
81
|
-
|
82
|
-
test "time_between_calls should convert its argument to milliseconds" do
|
83
|
-
agents.time_between_calls 1.hour
|
84
|
-
agents.agent_section.should == {:wrapuptime => 1.hour * 1_000}
|
85
|
-
end
|
86
|
-
|
87
|
-
test "hold_music_class should convert its argument to a String" do
|
88
|
-
agents.hold_music_class :podcast
|
89
|
-
agents.agent_section_special.should == {:musiconhold => "podcast"}
|
90
|
-
end
|
91
|
-
|
92
|
-
test "play_on_agent_goodbye should generate 'agentgoodbye'" do
|
93
|
-
agents.play_on_agent_goodbye "tt-monkeys"
|
94
|
-
agents.agent_section_special.should == {:agentgoodbye => "tt-monkeys"}
|
95
|
-
end
|
96
|
-
|
97
|
-
test "change_cdr_source should generate updatecdr" do
|
98
|
-
agents.change_cdr_source false
|
99
|
-
agents.agent_section.should == {:updatecdr => "no"}
|
100
|
-
end
|
101
|
-
|
102
|
-
test "play_for_waiting_keep_alive" do
|
103
|
-
agents.play_for_waiting_keep_alive "tt-weasels"
|
104
|
-
agents.agent_section.should == {:custom_beep => "tt-weasels"}
|
105
|
-
end
|
106
|
-
|
107
|
-
test "save_recordings_in should generate 'savecallsin'" do
|
108
|
-
agents.save_recordings_in "/second/star/on/the/right"
|
109
|
-
agents.agent_section.should == {:savecallsin => "/second/star/on/the/right"}
|
110
|
-
end
|
111
|
-
|
112
|
-
test "recording_prefix should generate 'urlprefix'" do
|
113
|
-
agents.recording_prefix "ohai"
|
114
|
-
agents.agent_section.should == {:urlprefix => "ohai"}
|
115
|
-
end
|
116
|
-
|
117
|
-
test "recording_format should only allow a few symbols as an argument" do
|
118
|
-
the_following_code {
|
119
|
-
agents.recording_format :wav
|
120
|
-
agents.agent_section.should == {:recordformat => :wav}
|
121
|
-
}.should.not.raise
|
122
|
-
|
123
|
-
reset_agents!
|
124
|
-
|
125
|
-
the_following_code {
|
126
|
-
agents.recording_format :wav49
|
127
|
-
agents.agent_section.should == {:recordformat => :wav49}
|
128
|
-
}.should.not.raise
|
129
|
-
|
130
|
-
reset_agents!
|
131
|
-
|
132
|
-
the_following_code {
|
133
|
-
agents.recording_format :gsm
|
134
|
-
agents.agent_section.should == {:recordformat => :gsm}
|
135
|
-
}.should.not.raise
|
136
|
-
|
137
|
-
reset_agents!
|
138
|
-
|
139
|
-
the_following_code {
|
140
|
-
agents.recording_format :mp3
|
141
|
-
agents.agent_section.should == {:recordformat => :mp3}
|
142
|
-
}.should.raise ArgumentError
|
143
|
-
|
144
|
-
end
|
145
|
-
|
146
|
-
test "record_agent_calls should generate a 'recordagentcalls' yes/no pair" do
|
147
|
-
agents.record_agent_calls false
|
148
|
-
agents.agent_section.should == {:recordagentcalls => 'no'}
|
149
|
-
end
|
150
|
-
|
151
|
-
test "allow_multiple_logins_per_extension should generate 'multiplelogin' in [general]" do
|
152
|
-
agents.allow_multiple_logins_per_extension true
|
153
|
-
agents.general_section.should == {:multiplelogin => 'yes'}
|
154
|
-
end
|
155
|
-
|
156
|
-
end
|
157
|
-
|
158
|
-
context "The default agents.conf config file converted to this syntax" do
|
159
|
-
|
160
|
-
include AgentsConfigFileGeneratorTestHelper
|
161
|
-
|
162
|
-
attr_reader :default_config, :agents
|
163
|
-
before:each do
|
164
|
-
reset_agents!
|
165
|
-
@default_config = <<-CONFIG
|
166
|
-
[general]
|
167
|
-
persistentagents=yes
|
168
|
-
|
169
|
-
[agents]
|
170
|
-
maxlogintries=5
|
171
|
-
autologoff=15
|
172
|
-
ackcall=no
|
173
|
-
endcall=yes
|
174
|
-
wrapuptime=5000
|
175
|
-
musiconhold => default
|
176
|
-
agentgoodbye => goodbye_file
|
177
|
-
updatecdr=no
|
178
|
-
group=1,2
|
179
|
-
recordagentcalls=yes
|
180
|
-
recordformat=gsm
|
181
|
-
urlprefix=http://localhost/calls/
|
182
|
-
savecallsin=/var/calls
|
183
|
-
custom_beep=beep
|
184
|
-
|
185
|
-
agent => 1001,4321,Mark Spencer
|
186
|
-
agent => 1002,4321,Will Meadows
|
187
|
-
CONFIG
|
188
|
-
end
|
189
|
-
|
190
|
-
test "they're basically the same" do
|
191
|
-
agents.persistent_agents true
|
192
|
-
agents.max_login_tries 5
|
193
|
-
agents.log_off_after_duration 15
|
194
|
-
agents.require_hash_to_acknowledge false
|
195
|
-
agents.allow_star_to_hangup true
|
196
|
-
agents.time_between_calls 5
|
197
|
-
agents.hold_music_class :default
|
198
|
-
agents.play_on_agent_goodbye "goodbye_file"
|
199
|
-
agents.change_cdr_source false
|
200
|
-
agents.groups 1,2
|
201
|
-
agents.record_agent_calls true
|
202
|
-
agents.recording_format :gsm
|
203
|
-
agents.recording_prefix "http://localhost/calls/"
|
204
|
-
agents.save_recordings_in "/var/calls"
|
205
|
-
agents.play_for_waiting_keep_alive "beep"
|
206
|
-
|
207
|
-
agents.agent 1001, :password => 4321, :name => "Mark Spencer"
|
208
|
-
agents.agent 1002, :password => 4321, :name => "Will Meadows"
|
209
|
-
|
210
|
-
cleaned_up_default_config = Adhearsion::VoIP::Asterisk::ConfigFileGenerators::
|
211
|
-
AsteriskConfigGenerator.create_sanitary_hash_from(default_config)
|
212
|
-
|
213
|
-
cleaned_up_generated_config = agents.to_sanitary_hash
|
214
|
-
|
215
|
-
cleaned_up_generated_config.should == cleaned_up_default_config
|
216
|
-
end
|
217
|
-
|
218
|
-
end
|
219
|
-
|
220
|
-
|
221
|
-
context "AgentsConfigFileGeneratorTestHelper" do
|
222
|
-
|
223
|
-
include AgentsConfigFileGeneratorTestHelper
|
224
|
-
|
225
|
-
attr_reader :agents
|
226
|
-
|
227
|
-
test "generated_config_has_pair() works properly" do
|
228
|
-
@agents = flexmock "A fake agents with just one pair", :conf => "foo=bar"
|
229
|
-
generated_config_has_pair(:foo => "bar").should.be true
|
230
|
-
|
231
|
-
@agents = flexmock "A fake agents with just one pair", :conf => "[general]\n\nqaz=qwerty\nagent => 1,2,3"
|
232
|
-
generated_config_has_pair(:qaz => "qwerty").should.be true
|
233
|
-
generated_config_has_pair(:foo => "bar").should.be false
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
BEGIN {
|
238
|
-
module AgentsConfigFileGeneratorTestHelper
|
239
|
-
|
240
|
-
def reset_agents!
|
241
|
-
@agents = Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Agents.new
|
242
|
-
end
|
243
|
-
|
244
|
-
def generated_config_has_pair(pair)
|
245
|
-
agents.conf.grep(/=[^>]/).each do |line|
|
246
|
-
key, value = line.strip.split('=')
|
247
|
-
return true if pair == {key.to_sym => value}
|
248
|
-
end
|
249
|
-
false
|
250
|
-
end
|
251
|
-
|
252
|
-
end
|
253
|
-
}
|