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
@@ -1,267 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
-
|
3
|
-
context "Configuration defaults" do
|
4
|
-
include ConfigurationTestHelper
|
5
|
-
attr_reader :config
|
6
|
-
|
7
|
-
setup do
|
8
|
-
@config = default_config
|
9
|
-
end
|
10
|
-
|
11
|
-
test "incoming calls are answered by default" do
|
12
|
-
assert config.automatically_answer_incoming_calls
|
13
|
-
end
|
14
|
-
|
15
|
-
test "calls are ended when hung up" do
|
16
|
-
assert config.end_call_on_hangup
|
17
|
-
end
|
18
|
-
|
19
|
-
test "if an error occurs, a call is hungup" do
|
20
|
-
assert config.end_call_on_error
|
21
|
-
end
|
22
|
-
|
23
|
-
test "asterisk is enabled by default" do
|
24
|
-
assert config.asterisk_enabled?
|
25
|
-
end
|
26
|
-
|
27
|
-
test "default asterisk configuration is available" do
|
28
|
-
assert_kind_of Adhearsion::Configuration::AsteriskConfiguration, config.asterisk
|
29
|
-
end
|
30
|
-
|
31
|
-
test "database access is NOT enabled by default" do
|
32
|
-
assert !config.database_enabled?
|
33
|
-
end
|
34
|
-
|
35
|
-
test "freeswith is NOT enabled by default" do
|
36
|
-
assert !config.freeswitch_enabled?
|
37
|
-
end
|
38
|
-
|
39
|
-
test "AMI is NOT enabled by default" do
|
40
|
-
assert !config.asterisk.ami_enabled?
|
41
|
-
end
|
42
|
-
|
43
|
-
test "Drb is NOT enabled by default" do
|
44
|
-
assert !config.drb_enabled?
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
context "Asterisk AGI configuration defaults" do
|
49
|
-
attr_reader :config
|
50
|
-
|
51
|
-
setup do
|
52
|
-
@config = Adhearsion::Configuration::AsteriskConfiguration.new
|
53
|
-
end
|
54
|
-
|
55
|
-
test "asterisk configuration sets default listening port" do
|
56
|
-
config.listening_port.should.equal Adhearsion::Configuration::AsteriskConfiguration.default_listening_port
|
57
|
-
end
|
58
|
-
|
59
|
-
test "asterisk configuration sets default listening host" do
|
60
|
-
config.listening_host.should.equal Adhearsion::Configuration::AsteriskConfiguration.default_listening_host
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'Logging configuration' do
|
65
|
-
|
66
|
-
attr_reader :config
|
67
|
-
before :each do
|
68
|
-
@config = Adhearsion::Configuration.new
|
69
|
-
end
|
70
|
-
|
71
|
-
after :each do
|
72
|
-
Adhearsion::Logging.logging_level = :fatal
|
73
|
-
end
|
74
|
-
|
75
|
-
test 'the logging level should translate from symbols into Log4r constants' do
|
76
|
-
Adhearsion::Logging.logging_level.should.not.equal Log4r::WARN
|
77
|
-
config.logging :level => :warn
|
78
|
-
Adhearsion::Logging.logging_level.should.equal Log4r::WARN
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
context "AMI configuration defaults" do
|
84
|
-
attr_reader :config
|
85
|
-
|
86
|
-
setup do
|
87
|
-
@config = Adhearsion::Configuration::AsteriskConfiguration::AMIConfiguration.new
|
88
|
-
end
|
89
|
-
|
90
|
-
test "ami configuration sets default port" do
|
91
|
-
config.port.should.equal Adhearsion::Configuration::AsteriskConfiguration::AMIConfiguration.default_port
|
92
|
-
end
|
93
|
-
|
94
|
-
test "ami allows you to configure a username and a password, both of which default to nil" do
|
95
|
-
config.username.should.be.nil
|
96
|
-
config.password.should.be.nil
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "Rails configuration defaults" do
|
101
|
-
test "should require the path to the Rails app in the constructor" do
|
102
|
-
config = Adhearsion::Configuration::RailsConfiguration.new :path => "path here doesn't matter right now", :env => :development
|
103
|
-
config.rails_root.should.not.be.nil
|
104
|
-
end
|
105
|
-
|
106
|
-
test "should expand_path() the first constructor parameter" do
|
107
|
-
rails_root = "gui"
|
108
|
-
flexmock(File).should_receive(:expand_path).once.with(rails_root)
|
109
|
-
config = Adhearsion::Configuration::RailsConfiguration.new :path => rails_root, :env => :development
|
110
|
-
end
|
111
|
-
|
112
|
-
test "should ensure that the environment provided is one supported by Rails" do
|
113
|
-
the_following_code {
|
114
|
-
Adhearsion::Configuration::RailsConfiguration.new :path => "doesnt matter", :env => :this_is_not_a_rails_env
|
115
|
-
}.should.raise ArgumentError
|
116
|
-
|
117
|
-
the_following_code {
|
118
|
-
Adhearsion::Configuration::RailsConfiguration.new :path => "doesnt matter", :env => :development
|
119
|
-
Adhearsion::Configuration::RailsConfiguration.new :path => "doesnt matter", :env => :production
|
120
|
-
Adhearsion::Configuration::RailsConfiguration.new :path => "doesnt matter", :env => :test
|
121
|
-
}.should.not.raise ArgumentError
|
122
|
-
end
|
123
|
-
|
124
|
-
test "should convert the environment into a Symbol" do
|
125
|
-
Adhearsion::Configuration::RailsConfiguration::SUPPORTED_RAILS_ENVIRONMENTS.should.not.be.empty
|
126
|
-
Adhearsion::Configuration::RailsConfiguration::SUPPORTED_RAILS_ENVIRONMENTS.each do |env|
|
127
|
-
config = Adhearsion::Configuration::RailsConfiguration.new :path => "doesnt matter", :env => env.to_s
|
128
|
-
config.environment.should.equal env
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context "Database configuration defaults" do
|
134
|
-
|
135
|
-
setup do
|
136
|
-
Adhearsion.send(:remove_const, :AHN_CONFIG) if Adhearsion.const_defined?(:AHN_CONFIG)
|
137
|
-
Adhearsion::Configuration.configure {}
|
138
|
-
end
|
139
|
-
|
140
|
-
it "should store the constructor's argument in connection_options()" do
|
141
|
-
sample_options = { :adapter => "sqlite3", :dbfile => "foo.sqlite3" }
|
142
|
-
config = Adhearsion::Configuration::DatabaseConfiguration.new(sample_options)
|
143
|
-
config.connection_options.should.equal sample_options
|
144
|
-
end
|
145
|
-
it "should remove the :orm key from the connection options" do
|
146
|
-
sample_options = { :orm => :active_record, :adapter => "mysql", :host => "::1",
|
147
|
-
:user => "a", :pass => "b", :database => "ahn" }
|
148
|
-
config = Adhearsion::Configuration::DatabaseConfiguration.new(sample_options.clone)
|
149
|
-
config.orm.should.equal sample_options.delete(:orm)
|
150
|
-
config.connection_options.should.equal sample_options
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
context "Freeswitch configuration defaults" do
|
155
|
-
attr_reader :config
|
156
|
-
|
157
|
-
setup do
|
158
|
-
@config = Adhearsion::Configuration::FreeswitchConfiguration.new
|
159
|
-
end
|
160
|
-
|
161
|
-
test "freeswitch configuration sets default listening port" do
|
162
|
-
config.listening_port.should.equal Adhearsion::Configuration::FreeswitchConfiguration.default_listening_port
|
163
|
-
end
|
164
|
-
|
165
|
-
test "freeswitch configuration sets default listening host" do
|
166
|
-
config.listening_host.should.equal Adhearsion::Configuration::FreeswitchConfiguration.default_listening_host
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context "Configuration scenarios" do
|
171
|
-
include ConfigurationTestHelper
|
172
|
-
|
173
|
-
test "enabling AMI using all its defaults" do
|
174
|
-
config = enable_ami
|
175
|
-
|
176
|
-
assert config.asterisk.ami_enabled?
|
177
|
-
config.asterisk.ami.should.be.kind_of Adhearsion::Configuration::AsteriskConfiguration::AMIConfiguration
|
178
|
-
end
|
179
|
-
|
180
|
-
test "enabling AMI with custom configuration overrides the defaults" do
|
181
|
-
overridden_port = 911
|
182
|
-
config = enable_ami :port => overridden_port
|
183
|
-
config.asterisk.ami.port.should.equal overridden_port
|
184
|
-
end
|
185
|
-
|
186
|
-
test "enabling Drb without any configuration" do
|
187
|
-
config = enable_drb
|
188
|
-
assert config.drb
|
189
|
-
config.drb.should.be.kind_of Adhearsion::Configuration::DrbConfiguration
|
190
|
-
end
|
191
|
-
|
192
|
-
test "enabling Drb with a port specified sets the port" do
|
193
|
-
target_port = 911
|
194
|
-
config = enable_drb :port => target_port
|
195
|
-
config.drb.port.should.be.equal target_port
|
196
|
-
end
|
197
|
-
|
198
|
-
private
|
199
|
-
def enable_ami(*overrides)
|
200
|
-
default_config do |config|
|
201
|
-
config.asterisk.enable_ami(*overrides)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
def enable_drb(*overrides)
|
206
|
-
default_config do |config|
|
207
|
-
config.enable_drb *overrides
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
context "AHN_CONFIG" do
|
213
|
-
setup do
|
214
|
-
Adhearsion.send(:remove_const, :AHN_CONFIG) if Adhearsion.const_defined?(:AHN_CONFIG)
|
215
|
-
end
|
216
|
-
|
217
|
-
test "Running configure sets configuration to Adhearsion::AHN_CONFIG" do
|
218
|
-
assert !Adhearsion.const_defined?(:AHN_CONFIG)
|
219
|
-
Adhearsion::Configuration.configure do |config|
|
220
|
-
# Nothing needs to happen here
|
221
|
-
end
|
222
|
-
|
223
|
-
assert Adhearsion.const_defined?(:AHN_CONFIG)
|
224
|
-
Adhearsion::AHN_CONFIG.should.be.kind_of(Adhearsion::Configuration)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
context "DRb configuration" do
|
229
|
-
test "should not add any ACL rules when :raw_acl is passed in" do
|
230
|
-
config = Adhearsion::Configuration::DrbConfiguration.new :raw_acl => :this_is_an_acl
|
231
|
-
config.acl.should.equal :this_is_an_acl
|
232
|
-
end
|
233
|
-
|
234
|
-
test "should, by default, allow only localhost connections" do
|
235
|
-
config = Adhearsion::Configuration::DrbConfiguration.new
|
236
|
-
config.acl.should == %w[allow 127.0.0.1]
|
237
|
-
end
|
238
|
-
|
239
|
-
test "should add ACL 'deny' rules before 'allow' rules" do
|
240
|
-
config = Adhearsion::Configuration::DrbConfiguration.new :allow => %w[1.1.1.1 2.2.2.2],
|
241
|
-
:deny => %w[9.9.9.9]
|
242
|
-
config.acl.should == %w[deny 9.9.9.9 allow 1.1.1.1 allow 2.2.2.2]
|
243
|
-
end
|
244
|
-
|
245
|
-
test "should allow both an Array and a String to be passed as an allow/deny ACL rule" do
|
246
|
-
config = Adhearsion::Configuration::DrbConfiguration.new :allow => "1.1.1.1", :deny => "9.9.9.9"
|
247
|
-
config.acl.should == %w[deny 9.9.9.9 allow 1.1.1.1]
|
248
|
-
end
|
249
|
-
|
250
|
-
test "should have a default host and port" do
|
251
|
-
config = Adhearsion::Configuration::DrbConfiguration.new
|
252
|
-
config.host.should.not.equal nil
|
253
|
-
config.port.should.not.equal nil
|
254
|
-
end
|
255
|
-
|
256
|
-
end
|
257
|
-
|
258
|
-
BEGIN {
|
259
|
-
module ConfigurationTestHelper
|
260
|
-
def default_config(&block)
|
261
|
-
Adhearsion::Configuration.new do |config|
|
262
|
-
config.enable_asterisk
|
263
|
-
yield config if block_given?
|
264
|
-
end
|
265
|
-
end
|
266
|
-
end
|
267
|
-
}
|
@@ -1,162 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
-
require 'adhearsion/initializer/database'
|
3
|
-
require 'adhearsion/initializer/asterisk'
|
4
|
-
require 'adhearsion/initializer/rails'
|
5
|
-
require 'active_record'
|
6
|
-
|
7
|
-
context "The database initializer" do
|
8
|
-
|
9
|
-
include DatabaseInitializationTestHelper
|
10
|
-
|
11
|
-
test "starts a connection through ActiveRecord" do
|
12
|
-
connection_options = { :adapter => "sqlite3",
|
13
|
-
:dbfile => "foo.sqlite3" }
|
14
|
-
flexmock(Adhearsion::Initializer::DatabaseInitializer).should_receive(:require_models).once
|
15
|
-
flexmock(ActiveRecord::Base).should_receive(:establish_connection).with(connection_options)
|
16
|
-
|
17
|
-
start_database_initializer_with_options connection_options
|
18
|
-
end
|
19
|
-
|
20
|
-
test "should make any required models available in the main namespace" do
|
21
|
-
bogus_model = tempfile_with_contents sample_user_model
|
22
|
-
flexmock(Adhearsion::Initializer::DatabaseInitializer).should_receive(:all_models).and_return([bogus_model.path])
|
23
|
-
start_database_initializer
|
24
|
-
User.superclass.should.equal ActiveRecord::Base
|
25
|
-
end
|
26
|
-
|
27
|
-
test 'should enable ActiveRecord concurrency' do
|
28
|
-
bogus_model = tempfile_with_contents sample_user_model
|
29
|
-
flexmock(Adhearsion::Initializer::DatabaseInitializer).should_receive(:all_models).and_return([bogus_model.path])
|
30
|
-
start_database_initializer
|
31
|
-
ActiveRecord::Base.send(:class_variable_get, :@@allow_concurrency).should.be true
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
context "The Asterisk initializer" do
|
37
|
-
|
38
|
-
include AsteriskInitializerTestHelper
|
39
|
-
|
40
|
-
test "starts the AGI server" do
|
41
|
-
initialize_asterisk_with_defaults
|
42
|
-
flexmock(Adhearsion::VoIP::Asterisk::AGI::Server).new_instances.should_receive(:start).once
|
43
|
-
end
|
44
|
-
|
45
|
-
test "starts the AGI server with any overridden settings" do
|
46
|
-
overrides = {:host => "127.0.0.1", :port => 7788}
|
47
|
-
config_overrides = {:listening_host => overrides[:host], :listening_port => overrides[:port]}
|
48
|
-
initialize_asterisk_with_options config_overrides
|
49
|
-
flexmock(Adhearsion::VoIP::Asterisk::AGI::Server).new_instances.should_receive(:start).once.with(overrides)
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
context "The Rails initializer" do
|
55
|
-
|
56
|
-
include RailsInitializerTestHelper
|
57
|
-
|
58
|
-
test "should load the config/environment.rb file within the rails_root path" do
|
59
|
-
rails_root = "/path/to/rails/app"
|
60
|
-
environment_rb = rails_root + '/config/environment.rb'
|
61
|
-
flexmock(Adhearsion::Initializer::RailsInitializer).should_receive(:require).once.with environment_rb
|
62
|
-
stub_file_checking_methods!
|
63
|
-
stub_before_call_hook!
|
64
|
-
initialize_rails_with_options :rails_root => rails_root, :environment => :development
|
65
|
-
end
|
66
|
-
|
67
|
-
test "should raise an exception if the database is initialized at the same time" do
|
68
|
-
flexmock(Adhearsion::AHN_CONFIG).should_receive(:database_enabled?).and_return true
|
69
|
-
flexmock(Adhearsion::Initializer::RailsInitializer).should_receive(:require).and_return
|
70
|
-
stub_file_checking_methods!
|
71
|
-
stub_before_call_hook!
|
72
|
-
the_following_code {
|
73
|
-
initialize_rails_with_options :rails_root => '/tmp', :environment => :development
|
74
|
-
}.should.raise
|
75
|
-
end
|
76
|
-
|
77
|
-
test "should set the RAILS_ENV to be the argument passed in" do
|
78
|
-
flexmock(ENV).should_receive(:[]=).once.with("RAILS_ENV", "development")
|
79
|
-
flexmock(Adhearsion::Initializer::RailsInitializer).should_receive(:require).once.and_return
|
80
|
-
stub_file_checking_methods!
|
81
|
-
stub_before_call_hook!
|
82
|
-
initialize_rails_with_options :rails_root => '/tmp', :environment => :development
|
83
|
-
end
|
84
|
-
|
85
|
-
test 'should enable ActiveRecord concurrency' do
|
86
|
-
flexstub(Adhearsion::Initializer::RailsInitializer).should_receive :require
|
87
|
-
flexstub(Adhearsion::Initializer::RailsInitializer).should_receive :load_rails
|
88
|
-
stub_file_checking_methods!
|
89
|
-
stub_before_call_hook!
|
90
|
-
initialize_rails_with_options :rails_root => '/path/somewhere', :environment => :development
|
91
|
-
ActiveRecord::Base.send(:class_variable_get, :@@allow_concurrency).should.equal true
|
92
|
-
end
|
93
|
-
|
94
|
-
test 'should create a BeforeCall hook (presumably to verify the active connections)' do
|
95
|
-
flexstub(Adhearsion::Initializer::RailsInitializer).should_receive :require
|
96
|
-
flexstub(Adhearsion::Initializer::RailsInitializer).should_receive :load_rails
|
97
|
-
stub_file_checking_methods!
|
98
|
-
flexmock(Adhearsion::Hooks::BeforeCall).should_receive(:create_hook).once
|
99
|
-
initialize_rails_with_options :rails_root => '/path/somewhere', :environment => :development
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
BEGIN {
|
105
|
-
module DatabaseInitializationTestHelper
|
106
|
-
|
107
|
-
def start_database_initializer
|
108
|
-
start_database_initializer_with_options :adapter => "sqlite3", :dbfile => "foobar.sqlite3"
|
109
|
-
end
|
110
|
-
|
111
|
-
def start_database_initializer_with_options(options)
|
112
|
-
Adhearsion::Configuration.configure { |config| config.enable_database(options) }
|
113
|
-
Adhearsion::Initializer::DatabaseInitializer.start
|
114
|
-
end
|
115
|
-
|
116
|
-
def tempfile_with_contents(contents)
|
117
|
-
returning Tempfile.new("bogus_model") do |file|
|
118
|
-
file.puts contents
|
119
|
-
file.flush
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def sample_user_model
|
124
|
-
<<-CODE
|
125
|
-
class User < ActiveRecord::Base
|
126
|
-
validates_uniqueness_of :name
|
127
|
-
end
|
128
|
-
CODE
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
module AsteriskInitializerTestHelper
|
133
|
-
def initialize_asterisk_with_defaults
|
134
|
-
initialize_asterisk_with_options Hash.new
|
135
|
-
end
|
136
|
-
def initialize_asterisk_with_options(options)
|
137
|
-
flexmock(Adhearsion::Initializer::AsteriskInitializer).should_receive(:join_server_thread_after_initialized)
|
138
|
-
Adhearsion::Configuration.configure { |config| config.enable_asterisk(options) }
|
139
|
-
Adhearsion::Initializer::AsteriskInitializer.start
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
module RailsInitializerTestHelper
|
144
|
-
|
145
|
-
def initialize_rails_with_options(options)
|
146
|
-
rails_options = flexmock "Rails options mock", options
|
147
|
-
flexstub(Adhearsion::AHN_CONFIG).should_receive(:rails).once.and_return(rails_options)
|
148
|
-
Adhearsion::Initializer::RailsInitializer.start
|
149
|
-
end
|
150
|
-
|
151
|
-
def stub_file_checking_methods!
|
152
|
-
flexstub(File).should_receive(:directory?).and_return true
|
153
|
-
flexstub(File).should_receive(:exists?).and_return true
|
154
|
-
end
|
155
|
-
|
156
|
-
def stub_before_call_hook!
|
157
|
-
flexstub(Adhearsion::Hooks::BeforeCall).should_receive :create_hook
|
158
|
-
end
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
}
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
-
|
3
|
-
describe "Adhearsion::Paths" do
|
4
|
-
|
5
|
-
#TODO: All this crap will go away
|
6
|
-
disabled_test "should find all files when given a glob" do
|
7
|
-
inside_initialized_app do |path|
|
8
|
-
tmps = %w"foo.rb BA\ R.gem _q_a_z_.c"
|
9
|
-
tmps.each { |f| FileUtils.touch "#{path}/helpers/#{f}" }
|
10
|
-
found_helpers = all_helpers
|
11
|
-
all_helpers.should.not.be.empty
|
12
|
-
all_helpers.map! {|f| File.basename f }
|
13
|
-
all_helpers.each { |f| all_helpers.should.include(f) }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
test "should find files when several globs are given"
|
17
|
-
|
18
|
-
test "should allow the removal of path managers" do
|
19
|
-
Adhearsion::Paths.manager_for :helpers, :directory => "helpers"
|
20
|
-
Adhearsion::Paths.remove_manager_for :helpers
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "The .ahnrc " do
|
25
|
-
test "should allow ERb"
|
26
|
-
test "should create methods for every path declared"
|
27
|
-
test "should add all_x and x_path methods to main namespace and pluralize names" do
|
28
|
-
Adhearsion::Paths.manager_for "helper", :directory => "helpers"
|
29
|
-
should.respond_to(:all_helpers)
|
30
|
-
should.respond_to(:helper_path)
|
31
|
-
end
|
32
|
-
test "should have an init key"
|
33
|
-
test "should allow a String to the init key"
|
34
|
-
test "should default the init key to config/startup.rb"
|
35
|
-
test "should allow an Array to the init key"
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "Adhearsion's paths syntax sugar" do
|
39
|
-
test "should calculate helper paths properly"
|
40
|
-
test "should find log files properly"
|
41
|
-
test "should find helper config paths properly"
|
42
|
-
test "should return the configuration for a helper properly"
|
43
|
-
end
|
data/spec/sample.rb
DELETED
data/spec/silence.rb
DELETED
data/spec/test_ahn_command.rb
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/test_helper"
|
2
|
-
require 'adhearsion/cli'
|
3
|
-
|
4
|
-
module AhnCommandSpecHelper
|
5
|
-
def simulate_args(*args)
|
6
|
-
ARGV.clear
|
7
|
-
ARGV.concat args
|
8
|
-
end
|
9
|
-
|
10
|
-
def capture_stdout(&block)
|
11
|
-
old = $stdout
|
12
|
-
$stdout = io = StringIO.new
|
13
|
-
yield
|
14
|
-
ensure
|
15
|
-
$stdout = old
|
16
|
-
return io.string
|
17
|
-
end
|
18
|
-
|
19
|
-
def new_tmp_dir(filename=String.random)
|
20
|
-
File.join Dir.tmpdir, filename
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'The Ahn Command helper' do
|
27
|
-
|
28
|
-
include AhnCommandSpecHelper
|
29
|
-
|
30
|
-
test "args are simulated properly" do
|
31
|
-
before = ARGV.clone
|
32
|
-
simulate_args "create", "/tmp/blah"
|
33
|
-
ARGV.should.not.equal before
|
34
|
-
end
|
35
|
-
|
36
|
-
test "STDOUT should be captured" do
|
37
|
-
capture_stdout do
|
38
|
-
puts "wee"
|
39
|
-
end.should.equal "wee\n"
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
context "A simulated use of the 'ahn' command" do
|
45
|
-
|
46
|
-
include AhnCommandSpecHelper
|
47
|
-
|
48
|
-
test "USAGE is defined" do
|
49
|
-
assert Adhearsion::CLI::AhnCommand.const_defined?('USAGE')
|
50
|
-
end
|
51
|
-
|
52
|
-
test "arguments to 'create' are executed properly properly" do
|
53
|
-
some_path = "/path/somewhere"
|
54
|
-
simulate_args "create", some_path
|
55
|
-
flexmock(Adhearsion::CLI::AhnCommand::CommandHandler).should_receive(:create).once.with(some_path, :default)
|
56
|
-
capture_stdout { Adhearsion::CLI::AhnCommand.execute! }
|
57
|
-
end
|
58
|
-
|
59
|
-
test "arguments to 'start' are executed properly properly" do
|
60
|
-
some_path = "/tmp/blargh"
|
61
|
-
simulate_args "start", some_path
|
62
|
-
flexmock(Adhearsion::CLI::AhnCommand::CommandHandler).should_receive(:start).once.with(some_path, false, nil)
|
63
|
-
Adhearsion::CLI::AhnCommand.execute!
|
64
|
-
end
|
65
|
-
|
66
|
-
test "should execute arguments to 'start' for daemonizing properly" do
|
67
|
-
somewhere = "/tmp/blarghh"
|
68
|
-
simulate_args "start", 'daemon', somewhere
|
69
|
-
flexmock(Adhearsion::CLI::AhnCommand::CommandHandler).should_receive(:start).once.with(somewhere, true, nil)
|
70
|
-
Adhearsion::CLI::AhnCommand.execute!
|
71
|
-
end
|
72
|
-
|
73
|
-
test 'parse_arguments should recognize start with daemon properly' do
|
74
|
-
path = '/path/to/somesuch'
|
75
|
-
arguments = ["start", 'daemon', path]
|
76
|
-
Adhearsion::CLI::AhnCommand.parse_arguments(arguments).should == [:start, path, true, nil]
|
77
|
-
end
|
78
|
-
|
79
|
-
test 'should recognize start with daemon and pid file properly' do
|
80
|
-
project_path = '/second/star/on/the/right'
|
81
|
-
pid_file_path = '/straight/on/til/morning'
|
82
|
-
arguments = ["start", "daemon", project_path, "--pid-file=#{pid_file_path}"]
|
83
|
-
Adhearsion::CLI::AhnCommand.parse_arguments(arguments).should == [:start, project_path, true, pid_file_path]
|
84
|
-
end
|
85
|
-
|
86
|
-
test 'parse_arguments should recognize start without daemon properly' do
|
87
|
-
path = '/path/to/somewhere'
|
88
|
-
arguments = ['start', path]
|
89
|
-
Adhearsion::CLI::AhnCommand.parse_arguments(arguments).should == [:start, path, false, nil]
|
90
|
-
end
|
91
|
-
|
92
|
-
test "if no path is provided, running Ahn command blows up" do
|
93
|
-
the_following_code {
|
94
|
-
Adhearsion::CLI::AhnCommand.parse_arguments(['start'])
|
95
|
-
}.should.raise Adhearsion::CLI::AhnCommand::CommandHandler::UnknownCommand
|
96
|
-
end
|
97
|
-
|
98
|
-
test "printing the version" do
|
99
|
-
capture_stdout do
|
100
|
-
simulate_args 'version'
|
101
|
-
Adhearsion::CLI::AhnCommand.execute!
|
102
|
-
end.should =~ Regexp.new(Regexp.escape(Adhearsion::VERSION::STRING))
|
103
|
-
end
|
104
|
-
|
105
|
-
test "printing the help" do
|
106
|
-
capture_stdout do
|
107
|
-
simulate_args 'help'
|
108
|
-
Adhearsion::CLI::AhnCommand.execute!
|
109
|
-
end.should =~ Regexp.new(Regexp.escape(Adhearsion::CLI::AhnCommand::USAGE))
|
110
|
-
end
|
111
|
-
|
112
|
-
test "reacting to unrecognized commands" do
|
113
|
-
the_following_code {
|
114
|
-
simulate_args "alpha", "beta"
|
115
|
-
Adhearsion::CLI::AhnCommand.execute!
|
116
|
-
}.should.raise(Adhearsion::CLI::AhnCommand::CommandHandler::UnknownCommand)
|
117
|
-
end
|
118
|
-
|
119
|
-
test "giving a path that doesn't contain a project raises an exception" do
|
120
|
-
the_following_code {
|
121
|
-
simulate_args "start", "/asjdfas/sndjfabsdfbqwb/qnjwejqbwh"
|
122
|
-
Adhearsion::CLI::AhnCommand.execute!
|
123
|
-
}.should.raise(Adhearsion::CLI::AhnCommand::CommandHandler::PathInvalid)
|
124
|
-
end
|
125
|
-
|
126
|
-
test "giving an unrecognized project name raises an exception" do
|
127
|
-
the_following_code {
|
128
|
-
nonexistent_app_name, nonexistent_path = "a2n8y3gny2", "/tmp/qjweqbwas"
|
129
|
-
simulate_args "create:#{nonexistent_app_name}", nonexistent_path
|
130
|
-
Adhearsion::CLI::AhnCommand.execute!
|
131
|
-
}.should.raise Adhearsion::CLI::AhnCommand::CommandHandler::UnknownProject
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
context 'A real use of the "ahn" command' do
|
136
|
-
|
137
|
-
include AhnCommandSpecHelper
|
138
|
-
|
139
|
-
test "the 'create' command" do
|
140
|
-
the_following_code {
|
141
|
-
tmp_path = new_tmp_dir
|
142
|
-
simulate_args "create", tmp_path
|
143
|
-
RubiGen::Base.default_options.merge! :quiet => true
|
144
|
-
capture_stdout { Adhearsion::CLI::AhnCommand.execute! }
|
145
|
-
File.exists?(File.join(tmp_path, ".ahnrc")).should.be true
|
146
|
-
}.should.not.raise
|
147
|
-
end
|
148
|
-
|
149
|
-
end
|