sevenscale-adhearsion 0.7.1000 → 0.7.1003
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/Manifest.txt +5 -3
- data/README.txt +1 -2
- data/Rakefile +7 -1
- data/adhearsion.gemspec +40 -0
- data/app_generators/ahn/ahn_generator.rb +3 -2
- data/app_generators/ahn/templates/.ahnrc +16 -0
- data/app_generators/ahn/templates/Rakefile +15 -0
- data/app_generators/ahn/templates/events.rb +6 -0
- data/lib/adhearsion/cli.rb +1 -1
- data/lib/adhearsion/events_support.rb +262 -0
- data/lib/adhearsion/initializer.rb +52 -22
- data/lib/adhearsion/voip/asterisk/agi_server.rb +3 -0
- data/lib/adhearsion/voip/asterisk/commands.rb +1 -1
- data/lib/adhearsion/voip/asterisk.rb +8 -1
- data/lib/adhearsion/voip/call.rb +35 -1
- data/lib/adhearsion.rb +1 -0
- data/spec/sample.rb +9 -0
- data/spec/test_events.rb +136 -0
- data/spec/test_helper.rb +30 -18
- data/spec/test_hooks.rb +0 -22
- data/spec/test_initialization.rb +67 -48
- data/spec/voip/asterisk/test_agi_server.rb +4 -4
- data/spec/voip/test_dialplan_manager.rb +70 -0
- metadata +17 -5
- data/lib/adhearsion/services/scheduler.rb +0 -5
- data/script/destroy +0 -14
- data/script/generate +0 -14
data/lib/adhearsion/voip/call.rb
CHANGED
@@ -61,6 +61,14 @@ module Adhearsion
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
def with_tag(tag)
|
65
|
+
atomically do
|
66
|
+
calls.inject(Array.new) do |calls_with_tag,(key,call)|
|
67
|
+
call.tagged_with?(tag) ? calls_with_tag << call : calls_with_tag
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
64
72
|
private
|
65
73
|
attr_reader :semaphore, :calls
|
66
74
|
|
@@ -80,7 +88,6 @@ module Adhearsion
|
|
80
88
|
end
|
81
89
|
end
|
82
90
|
|
83
|
-
|
84
91
|
class FailedExtensionCallException < MetaAgiCallException; end
|
85
92
|
|
86
93
|
class HungupExtensionCallException < MetaAgiCallException; end
|
@@ -142,6 +149,33 @@ module Adhearsion
|
|
142
149
|
check_if_valid_call
|
143
150
|
define_variable_accessors
|
144
151
|
set_originating_voip_platform!
|
152
|
+
@tag_mutex = Mutex.new
|
153
|
+
@tags = []
|
154
|
+
end
|
155
|
+
|
156
|
+
def tags
|
157
|
+
@tag_mutex.synchronize do
|
158
|
+
return @tags.clone
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def tag(symbol)
|
163
|
+
raise ArgumentError, "tag must be a Symbol" unless symbol.is_a? Symbol
|
164
|
+
@tag_mutex.synchronize do
|
165
|
+
@tags << symbol
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def remove_tag(symbol)
|
170
|
+
@tag_mutex.synchronize do
|
171
|
+
@tags.reject! { |tag| tag == symbol }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def tagged_with?(symbol)
|
176
|
+
@tag_mutex.synchronize do
|
177
|
+
@tags.include? symbol
|
178
|
+
end
|
145
179
|
end
|
146
180
|
|
147
181
|
def deliver_message(message)
|
data/lib/adhearsion.rb
CHANGED
@@ -19,6 +19,7 @@ require 'adhearsion/voip/asterisk/special_dial_plan_managers'
|
|
19
19
|
require 'adhearsion/core_extensions/all'
|
20
20
|
require 'adhearsion/blank_slate'
|
21
21
|
require 'adhearsion/hooks'
|
22
|
+
require 'adhearsion/events_support'
|
22
23
|
require 'adhearsion/logging'
|
23
24
|
require 'adhearsion/initializer/configuration'
|
24
25
|
require 'adhearsion/initializer'
|
data/spec/sample.rb
ADDED
data/spec/test_events.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
context 'Definitions within an events.rb file' do
|
4
|
+
|
5
|
+
include EventsSubsystemTestHelper
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
Adhearsion::Events.reinitialize_framework_events_container!
|
9
|
+
end
|
10
|
+
|
11
|
+
test 'calling each() on a registrar defines a RegisteredEventCallback' do
|
12
|
+
|
13
|
+
mock_file_access_with_text %{ events.framework.before_call.each { |event| event } }
|
14
|
+
|
15
|
+
framework_events_container.register_namespace_path(:framework).register_callback_name(:before_call)
|
16
|
+
callbacks = framework_events_container.callbacks_at_path :framework, :before_call
|
17
|
+
load_events_file_from_mocked_filesystem
|
18
|
+
|
19
|
+
callbacks.size.should.equal 1
|
20
|
+
callbacks.first.should.be.kind_of Adhearsion::Events::RegisteredEventCallback
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'the each() method does not exist on the object returned by events()' do
|
24
|
+
the_following_code {
|
25
|
+
load_code_from_mocked_filesystem %{ events.each {} }
|
26
|
+
}.should.raise NoMethodError
|
27
|
+
end
|
28
|
+
|
29
|
+
test 'addressing a non-existent path raises an Exception' do
|
30
|
+
[%{ events.monkeys! }, %{events.framework.icanhascheezburger}, %{events.framework}].each do |bad_code|
|
31
|
+
the_following_code {
|
32
|
+
load_code_from_mocked_filesystem bad_code
|
33
|
+
}.should.raise Adhearsion::Events::UndefinedEventNamespace
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Hierarchy tests?
|
41
|
+
|
42
|
+
context 'Executing synchronous events defined within an events.rb file' do
|
43
|
+
|
44
|
+
before :each do
|
45
|
+
Adhearsion::Events.reinitialize_framework_events_container!
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'an exception in a callback should be passed to ahn_log.events.error' do
|
49
|
+
flexmock(ahn_log.events).should_receive(:error).once.with(/lolrus/)
|
50
|
+
Adhearsion::Events.register_namespace_path(:ceiling_cat).register_callback_name(:watches_you)
|
51
|
+
Adhearsion::Events.framework_events_container.events.ceiling_cat.watches_you.each { |prophecy| raise prophecy }
|
52
|
+
the_following_code {
|
53
|
+
Adhearsion::Events.framework_events_container.events.ceiling_cat.watches_you << "I has a lolrus!"
|
54
|
+
}.should.not.raise RuntimeError
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'events should execute the callbacks in the order in which they were defined' do
|
58
|
+
order_keeper = []
|
59
|
+
Adhearsion::Events.register_namespace_path(:foo, :bar).register_callback_name(:before_explosion)
|
60
|
+
Adhearsion::Events.framework_events_container.events.foo.bar.before_explosion.each { |event| order_keeper << 1 }
|
61
|
+
Adhearsion::Events.framework_events_container.events.foo.bar.before_explosion.each { |event| order_keeper << 2 }
|
62
|
+
|
63
|
+
[:one, :two, :three].each do |number|
|
64
|
+
Adhearsion::Events.framework_events_container.events.foo.bar.before_explosion << number
|
65
|
+
end
|
66
|
+
order_keeper.should == [1,2] * 3
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'Executing asynchronous events defined within an events.rb file' do
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
context "Defining new namespaces and events within an EventsDefinitionContainer's object graph" do
|
75
|
+
|
76
|
+
attr_reader :container
|
77
|
+
before :each do
|
78
|
+
@container = Adhearsion::Events::EventsDefinitionContainer.new
|
79
|
+
end
|
80
|
+
|
81
|
+
test 'initializes a RootNamespace' do
|
82
|
+
container.root.should.be.kind_of Adhearsion::Events::RootEventNamespace
|
83
|
+
end
|
84
|
+
|
85
|
+
test 'allows the registration of new namespaces' do
|
86
|
+
container.register_namespace_path(:framework).register_callback_name(:after_call)
|
87
|
+
container.callbacks_at_path(:framework, :after_call).empty?.should == true
|
88
|
+
end
|
89
|
+
|
90
|
+
test 'the callback is executed with the proper message' do
|
91
|
+
container.register_namespace_path(:reporters).register_callback_name(:report)
|
92
|
+
message_from_block = :has_not_executed_yet
|
93
|
+
container.events.reporters.report(:foobar).each { |event| message_from_block = event }
|
94
|
+
container.events.reporters.report << :got_here
|
95
|
+
message_from_block.should.equal :got_here
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'NamespaceDefinitionCapturer' do
|
101
|
+
|
102
|
+
attr_reader :namespace
|
103
|
+
before :each do
|
104
|
+
@namespace = flexmock 'a mock AbstractNamespace'
|
105
|
+
end
|
106
|
+
|
107
|
+
test 'captures any method and returns a NamespaceDefinitionCapturer' do
|
108
|
+
nested_namespace = Adhearsion::Events::RegisteredEventNamespace.new(namespace)
|
109
|
+
namespace.should_receive(:[]).once.with(:foobarz).and_return nested_namespace
|
110
|
+
Adhearsion::Events::NamespaceDefinitionCapturer.new(namespace).foobarz.should.
|
111
|
+
be.kind_of(Adhearsion::Events::NamespaceDefinitionCapturer)
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
BEGIN {
|
117
|
+
module EventsSubsystemTestHelper
|
118
|
+
def mock_file_access_with_text(text)
|
119
|
+
flexmock(File).should_receive(:read).once.and_return text
|
120
|
+
end
|
121
|
+
|
122
|
+
def framework_events_container
|
123
|
+
Adhearsion::Events.framework_events_container
|
124
|
+
end
|
125
|
+
|
126
|
+
def load_code_from_mocked_filesystem(code)
|
127
|
+
mock_file_access_with_text code
|
128
|
+
load_events_file_from_mocked_filesystem
|
129
|
+
end
|
130
|
+
|
131
|
+
def load_events_file_from_mocked_filesystem
|
132
|
+
Adhearsion::Events.load_definitions_from_file "events.rb"
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
}
|
data/spec/test_helper.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
Dir.chdir File.join(File.dirname(__FILE__), '..')
|
2
|
+
|
2
3
|
require 'rubygems'
|
4
|
+
|
3
5
|
def require_or_report_dependency(require_name, gem_name)
|
4
6
|
begin
|
5
7
|
require require_name
|
@@ -9,9 +11,9 @@ def require_or_report_dependency(require_name, gem_name)
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def report_dependency!(name)
|
12
|
-
puts
|
14
|
+
2.times { puts }
|
13
15
|
puts "You need #{name} to run these tests: gem install #{name}"
|
14
|
-
puts
|
16
|
+
2.times { puts }
|
15
17
|
exit!
|
16
18
|
end
|
17
19
|
|
@@ -29,14 +31,6 @@ $: << File.expand_path('lib')
|
|
29
31
|
$: << File.dirname(__FILE__)
|
30
32
|
|
31
33
|
require 'adhearsion'
|
32
|
-
class Adhearsion::Initializer
|
33
|
-
def asterisk_enabled?
|
34
|
-
false
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
34
|
|
41
35
|
class Test::Unit::TestCase
|
42
36
|
|
@@ -57,23 +51,40 @@ end
|
|
57
51
|
|
58
52
|
module InitializerStubs
|
59
53
|
|
54
|
+
DEFAULT_AHNRC_DATA_STRUCTURE = YAML.load_file(
|
55
|
+
File.dirname(__FILE__) + "/../app_generators/ahn/templates/.ahnrc"
|
56
|
+
) unless defined? DEFAULT_AHNRC_DATA_STRUCTURE
|
57
|
+
|
60
58
|
UNWANTED_BEHAVIOR = {
|
61
|
-
Adhearsion::Initializer
|
59
|
+
Adhearsion::Initializer => [:initialize_log_file, :switch_to_root_directory, :daemonize!],
|
60
|
+
Adhearsion::Initializer.metaclass => { :get_rules_from => DEFAULT_AHNRC_DATA_STRUCTURE },
|
62
61
|
Adhearsion::Hooks::AfterInitialized.metaclass => [:create_hook, :trigger_hooks]
|
63
62
|
} unless defined? UNWANTED_BEHAVIOR
|
64
63
|
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
def stub_behavior_for_initializer_with_no_path_changing_behavior
|
65
|
+
stub_unwanted_behavior
|
66
|
+
yield if block_given?
|
67
|
+
ensure
|
68
|
+
unstub_directory_changing_behavior
|
69
|
+
end
|
70
|
+
|
71
|
+
def with_new_initializer_with_no_path_changing_behavior(&block)
|
72
|
+
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
73
|
+
block.call Adhearsion::Initializer.start('path does not matter')
|
74
|
+
end
|
70
75
|
end
|
71
76
|
|
72
77
|
def stub_unwanted_behavior
|
73
78
|
UNWANTED_BEHAVIOR.each do |stub_victim_class, undesired_methods|
|
74
|
-
undesired_methods.each do |
|
79
|
+
undesired_methods.each do |undesired_method_name_or_key_value_pair|
|
80
|
+
undesired_method_name, method_implementation = case undesired_method_name_or_key_value_pair
|
81
|
+
when Array
|
82
|
+
[undesired_method_name_or_key_value_pair.first, lambda { undesired_method_name_or_key_value_pair.last } ]
|
83
|
+
else
|
84
|
+
[undesired_method_name_or_key_value_pair, lambda{ |*args| }]
|
85
|
+
end
|
75
86
|
stub_victim_class.send(:alias_method, "pre_stubbed_#{undesired_method_name}", undesired_method_name)
|
76
|
-
stub_victim_class.send(:define_method, undesired_method_name)
|
87
|
+
stub_victim_class.send(:define_method, undesired_method_name, &method_implementation)
|
77
88
|
end
|
78
89
|
end
|
79
90
|
end
|
@@ -81,6 +92,7 @@ module InitializerStubs
|
|
81
92
|
def unstub_directory_changing_behavior
|
82
93
|
UNWANTED_BEHAVIOR.each do |stub_victim_class, undesired_methods|
|
83
94
|
undesired_methods.each do |undesired_method_name|
|
95
|
+
undesired_method_name = undesired_method_name.first if undesired_method_name.kind_of? Array
|
84
96
|
stub_victim_class.send(:alias_method, undesired_method_name, "pre_stubbed_#{undesired_method_name}")
|
85
97
|
end
|
86
98
|
end
|
data/spec/test_hooks.rb
CHANGED
@@ -1,27 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/test_helper.rb"
|
2
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
3
|
context "A HookWithArguments" do
|
26
4
|
test "should pass the arguments to trigger_hooks() along to each registered block" do
|
27
5
|
hook_manager = Adhearsion::Hooks::HookWithArguments.new
|
data/spec/test_initialization.rb
CHANGED
@@ -11,55 +11,74 @@ context "Adhearsion::Initializer" do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
test "initialization will start with only a path given" do
|
14
|
-
|
15
|
-
Adhearsion::Initializer.
|
14
|
+
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
15
|
+
Adhearsion::Initializer.start path
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
test "should create a pid file in the app's path when given 'true' as the pid_file hash key argument" do
|
20
|
-
|
21
|
-
flexmock(File).should_receive(:open).
|
22
|
-
ahn = Adhearsion::Initializer.
|
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
23
|
ahn.pid_file[0, path.length].should.equal(path)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
63
82
|
end
|
64
83
|
|
65
84
|
context "AHN_ROOT" do
|
@@ -69,8 +88,8 @@ context "AHN_ROOT" do
|
|
69
88
|
end
|
70
89
|
|
71
90
|
test "initializing will create the AHN_ROOT" do
|
72
|
-
|
73
|
-
ahn = Adhearsion::Initializer.
|
91
|
+
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
92
|
+
ahn = Adhearsion::Initializer.start path
|
74
93
|
assert Object.constants.include?("AHN_ROOT")
|
75
94
|
end
|
76
95
|
end
|
@@ -89,8 +108,8 @@ context "AHN_ROOT" do
|
|
89
108
|
end
|
90
109
|
|
91
110
|
test "creating the AHN_ROOT will set defaults" do
|
92
|
-
|
93
|
-
ahn = Adhearsion::Initializer.
|
111
|
+
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
112
|
+
ahn = Adhearsion::Initializer.start path
|
94
113
|
full_path = File.expand_path(path)
|
95
114
|
AHN_ROOT.to_s.should.equal(full_path)
|
96
115
|
AHN_ROOT.component_path.should.equal(File.join(full_path, "components"))
|
@@ -24,7 +24,7 @@ context "The AGI server's serve() method" do
|
|
24
24
|
|
25
25
|
test 'should hand the call off to a new Manager if the request is agi://IP_ADDRESS_HERE' do
|
26
26
|
stub_before_call_hooks!
|
27
|
-
call_mock = flexmock 'A new mock call that will be passed to the manager', :variables => {}
|
27
|
+
call_mock = flexmock 'A new mock call that will be passed to the manager', :variables => {}, :unique_identifier => "X"
|
28
28
|
|
29
29
|
flexmock(Adhearsion).should_receive(:receive_call_from).once.and_return call_mock
|
30
30
|
manager_mock = flexmock 'a mock dialplan manager'
|
@@ -35,7 +35,7 @@ context "The AGI server's serve() method" do
|
|
35
35
|
|
36
36
|
test 'should hand off a call to a ConfirmationManager if the request begins with confirm!' do
|
37
37
|
confirm_options = Adhearsion::DialPlan::ConfirmationManager.encode_hash_for_dial_macro_argument :timeout => 20, :key => "#"
|
38
|
-
call_mock = flexmock "a call that has network_script as a variable", :variables => {:network_script => "confirm!#{confirm_options[/^M\(\^?(.+)\)$/,1]}"}
|
38
|
+
call_mock = flexmock "a call that has network_script as a variable", :variables => {:network_script => "confirm!#{confirm_options[/^M\(\^?(.+)\)$/,1]}"}, :unique_identifier => "X"
|
39
39
|
manager_mock = flexmock 'a mock ConfirmationManager'
|
40
40
|
|
41
41
|
the_following_code {
|
@@ -54,7 +54,7 @@ context "The AGI server's serve() method" do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
test 'should execute the OnHungupCall hooks when a HungupExtensionCallException is raised' do
|
57
|
-
call_mock = flexmock 'a bogus call', :hungup_call? => true, :variables => {:extension => "h"}
|
57
|
+
call_mock = flexmock 'a bogus call', :hungup_call? => true, :variables => {:extension => "h"}, :unique_identifier => "X"
|
58
58
|
mock_env = flexmock "A mock execution environment which gets passed along in the HungupExtensionCallException"
|
59
59
|
|
60
60
|
stub_confirmation_manager!
|
@@ -66,7 +66,7 @@ context "The AGI server's serve() method" do
|
|
66
66
|
end
|
67
67
|
|
68
68
|
test 'should execute the OnFailedCall hooks when a FailedExtensionCallException is raised' do
|
69
|
-
call_mock = flexmock 'a bogus call', :failed_call? => true, :variables => {:extension => "failed"}
|
69
|
+
call_mock = flexmock 'a bogus call', :failed_call? => true, :variables => {:extension => "failed"}, :unique_identifier => "X"
|
70
70
|
mock_env = flexmock "A mock execution environment which gets passed along in the HungupExtensionCallException", :failed_reason => "does not matter"
|
71
71
|
|
72
72
|
server = Adhearsion::VoIP::Asterisk::AGI::Server::RubyServer.new :port, :host
|
@@ -93,6 +93,76 @@ context "DialPlan::Manager's handling a failed call" do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
+
context "Call tagging" do
|
97
|
+
|
98
|
+
include DialplanTestingHelper
|
99
|
+
|
100
|
+
after :all do
|
101
|
+
Adhearsion.active_calls.clear!
|
102
|
+
end
|
103
|
+
|
104
|
+
test 'tagging a call with a single Symbol' do
|
105
|
+
the_following_code {
|
106
|
+
call = new_call_for_context "roflcopter"
|
107
|
+
call.tag :moderator
|
108
|
+
}.should.not.raise
|
109
|
+
end
|
110
|
+
|
111
|
+
test 'tagging a call with multiple Symbols' do
|
112
|
+
the_following_code {
|
113
|
+
call = new_call_for_context "roflcopter"
|
114
|
+
call.tag :moderator
|
115
|
+
call.tag :female
|
116
|
+
}.should.not.raise
|
117
|
+
end
|
118
|
+
|
119
|
+
test 'Call#tagged_with? with one tag' do
|
120
|
+
call = new_call_for_context "roflcopter"
|
121
|
+
call.tag :guest
|
122
|
+
call.tagged_with?(:guest).should.equal true
|
123
|
+
call.tagged_with?(:authorized).should.equal false
|
124
|
+
end
|
125
|
+
|
126
|
+
test "Call#remove_tag" do
|
127
|
+
call = new_call_for_context "roflcopter"
|
128
|
+
call.tag :moderator
|
129
|
+
call.tag :female
|
130
|
+
call.remove_tag :female
|
131
|
+
call.tag :male
|
132
|
+
call.tags.should == [:moderator, :male]
|
133
|
+
end
|
134
|
+
|
135
|
+
test 'Call#tagged_with? with many tags' do
|
136
|
+
call = new_call_for_context "roflcopter"
|
137
|
+
call.tag :customer
|
138
|
+
call.tag :authorized
|
139
|
+
call.tagged_with?(:customer).should.equal true
|
140
|
+
call.tagged_with?(:authorized).should.equal true
|
141
|
+
end
|
142
|
+
|
143
|
+
test 'tagging a call with a non-Symbol object' do
|
144
|
+
bad_objects = ["moderator", 123, Object.new, 888.88, nil, true, false, StringIO.new]
|
145
|
+
bad_objects.each do |bad_object|
|
146
|
+
the_following_code {
|
147
|
+
new_call_for_context("roflcopter").tag bad_object
|
148
|
+
}.should.raise ArgumentError
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
test "finding calls by a tag" do
|
153
|
+
Adhearsion.active_calls.clear!
|
154
|
+
|
155
|
+
calls = Array.new(5) { new_call_for_context "roflcopter" }
|
156
|
+
calls.each { |call| Adhearsion.active_calls << call }
|
157
|
+
|
158
|
+
tagged_call = calls.last
|
159
|
+
tagged_call.tag :moderator
|
160
|
+
|
161
|
+
Adhearsion.active_calls.with_tag(:moderator).should == [tagged_call]
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
96
166
|
context "DialPlan::Manager's handling a hungup call" do
|
97
167
|
|
98
168
|
include DialplanTestingHelper
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sevenscale-adhearsion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1003
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay Phillips
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-09-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,6 +30,15 @@ dependencies:
|
|
30
30
|
- !ruby/object:Gem::Version
|
31
31
|
version: 1.0.5
|
32
32
|
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: hoe
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.7.0
|
41
|
+
version:
|
33
42
|
description: Adhearsion is an open-source VoIP development framework written in Ruby
|
34
43
|
email: Jay -at- Codemecca.com
|
35
44
|
executables:
|
@@ -47,6 +56,7 @@ files:
|
|
47
56
|
- Manifest.txt
|
48
57
|
- README.txt
|
49
58
|
- Rakefile
|
59
|
+
- adhearsion.gemspec
|
50
60
|
- ahn_generators/component/USAGE
|
51
61
|
- ahn_generators/component/component_generator.rb
|
52
62
|
- ahn_generators/component/templates/configuration.rb
|
@@ -64,6 +74,7 @@ files:
|
|
64
74
|
- app_generators/ahn/templates/components/simon_game/test/test_simon_game.rb
|
65
75
|
- app_generators/ahn/templates/config/startup.rb
|
66
76
|
- app_generators/ahn/templates/dialplan.rb
|
77
|
+
- app_generators/ahn/templates/events.rb
|
67
78
|
- bin/ahn
|
68
79
|
- bin/ahnctl
|
69
80
|
- bin/jahn
|
@@ -94,6 +105,7 @@ files:
|
|
94
105
|
- lib/adhearsion/distributed/gateways/xmlrpc_gateway.rb
|
95
106
|
- lib/adhearsion/distributed/peer_finder.rb
|
96
107
|
- lib/adhearsion/distributed/remote_cli.rb
|
108
|
+
- lib/adhearsion/events_support.rb
|
97
109
|
- lib/adhearsion/hooks.rb
|
98
110
|
- lib/adhearsion/host_definitions.rb
|
99
111
|
- lib/adhearsion/initializer.rb
|
@@ -105,7 +117,6 @@ files:
|
|
105
117
|
- lib/adhearsion/initializer/paths.rb
|
106
118
|
- lib/adhearsion/initializer/rails.rb
|
107
119
|
- lib/adhearsion/logging.rb
|
108
|
-
- lib/adhearsion/services/scheduler.rb
|
109
120
|
- lib/adhearsion/tasks.rb
|
110
121
|
- lib/adhearsion/tasks/database.rb
|
111
122
|
- lib/adhearsion/tasks/generating.rb
|
@@ -148,18 +159,18 @@ files:
|
|
148
159
|
- lib/adhearsion/voip/menu_state_machine/matchers.rb
|
149
160
|
- lib/adhearsion/voip/menu_state_machine/menu_builder.rb
|
150
161
|
- lib/adhearsion/voip/menu_state_machine/menu_class.rb
|
151
|
-
- script/destroy
|
152
|
-
- script/generate
|
153
162
|
- spec/fixtures/dialplan.rb
|
154
163
|
- spec/initializer/test_configuration.rb
|
155
164
|
- spec/initializer/test_loading.rb
|
156
165
|
- spec/initializer/test_paths.rb
|
166
|
+
- spec/sample.rb
|
157
167
|
- spec/silence.rb
|
158
168
|
- spec/test_ahn_command.rb
|
159
169
|
- spec/test_code_quality.rb
|
160
170
|
- spec/test_component_manager.rb
|
161
171
|
- spec/test_constants.rb
|
162
172
|
- spec/test_drb.rb
|
173
|
+
- spec/test_events.rb
|
163
174
|
- spec/test_helper.rb
|
164
175
|
- spec/test_hooks.rb
|
165
176
|
- spec/test_host_definitions.rb
|
@@ -227,6 +238,7 @@ test_files:
|
|
227
238
|
- spec/test_component_manager.rb
|
228
239
|
- spec/test_constants.rb
|
229
240
|
- spec/test_drb.rb
|
241
|
+
- spec/test_events.rb
|
230
242
|
- spec/test_helper.rb
|
231
243
|
- spec/test_hooks.rb
|
232
244
|
- spec/test_host_definitions.rb
|