eric-adhearsion 0.7.999 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/CHANGELOG +8 -2
  2. data/EVENTS +11 -0
  3. data/Rakefile +96 -24
  4. data/adhearsion.gemspec +148 -0
  5. data/app_generators/ahn/ahn_generator.rb +24 -9
  6. data/app_generators/ahn/templates/.ahnrc +25 -3
  7. data/app_generators/ahn/templates/Rakefile +22 -2
  8. data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +15 -0
  9. data/app_generators/ahn/templates/components/disabled/HOW_TO_ENABLE +7 -0
  10. data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +47 -0
  11. data/app_generators/ahn/templates/components/disabled/stomp_gateway/config.yml +12 -0
  12. data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +34 -0
  13. data/app_generators/ahn/templates/components/simon_game/{lib/simon_game.rb → simon_game.rb} +14 -19
  14. data/app_generators/ahn/templates/config/startup.rb +3 -6
  15. data/app_generators/ahn/templates/dialplan.rb +2 -3
  16. data/app_generators/ahn/templates/events.rb +32 -0
  17. data/bin/jahn +10 -0
  18. data/examples/asterisk_manager_interface/standalone.rb +51 -0
  19. data/lib/adhearsion.rb +17 -11
  20. data/lib/adhearsion/cli.rb +141 -24
  21. data/lib/adhearsion/component_manager.rb +169 -238
  22. data/lib/adhearsion/component_manager/component_tester.rb +55 -0
  23. data/lib/adhearsion/component_manager/spec_framework.rb +24 -0
  24. data/lib/adhearsion/events_support.rb +84 -0
  25. data/lib/adhearsion/{core_extensions → foundation}/all.rb +0 -0
  26. data/lib/adhearsion/{blank_slate.rb → foundation/blank_slate.rb} +0 -0
  27. data/lib/adhearsion/{core_extensions → foundation}/custom_daemonizer.rb +0 -0
  28. data/lib/adhearsion/foundation/event_socket.rb +203 -0
  29. data/lib/adhearsion/foundation/future_resource.rb +36 -0
  30. data/lib/adhearsion/{core_extensions → foundation}/global.rb +0 -0
  31. data/lib/adhearsion/{core_extensions → foundation}/metaprogramming.rb +0 -0
  32. data/lib/adhearsion/foundation/numeric.rb +13 -0
  33. data/lib/adhearsion/foundation/pseudo_guid.rb +10 -0
  34. data/lib/adhearsion/{core_extensions → foundation}/relationship_properties.rb +2 -0
  35. data/lib/adhearsion/foundation/string.rb +26 -0
  36. data/lib/adhearsion/foundation/synchronized_hash.rb +96 -0
  37. data/lib/adhearsion/{core_extensions → foundation}/thread_safety.rb +0 -0
  38. data/lib/adhearsion/host_definitions.rb +5 -1
  39. data/lib/adhearsion/initializer.rb +229 -73
  40. data/lib/adhearsion/initializer/asterisk.rb +33 -11
  41. data/lib/adhearsion/initializer/configuration.rb +58 -6
  42. data/lib/adhearsion/initializer/database.rb +3 -46
  43. data/lib/adhearsion/initializer/drb.rb +9 -3
  44. data/lib/adhearsion/initializer/freeswitch.rb +3 -3
  45. data/lib/adhearsion/initializer/rails.rb +1 -1
  46. data/lib/adhearsion/tasks.rb +2 -1
  47. data/lib/adhearsion/tasks/deprecations.rb +59 -0
  48. data/lib/adhearsion/version.rb +3 -3
  49. data/lib/adhearsion/voip/asterisk.rb +2 -2
  50. data/lib/adhearsion/voip/asterisk/agi_server.rb +9 -6
  51. data/lib/adhearsion/voip/asterisk/commands.rb +106 -4
  52. data/lib/adhearsion/voip/asterisk/manager_interface.rb +562 -0
  53. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +1754 -0
  54. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +286 -0
  55. data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +78 -0
  56. data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +87 -0
  57. data/lib/adhearsion/voip/asterisk/super_manager.rb +19 -0
  58. data/lib/adhearsion/voip/call.rb +51 -2
  59. data/lib/adhearsion/voip/dial_plan.rb +74 -61
  60. data/lib/adhearsion/voip/dsl/dialing_dsl.rb +1 -1
  61. data/lib/adhearsion/voip/dsl/dialplan/parser.rb +2 -6
  62. data/lib/adhearsion/voip/dsl/numerical_string.rb +2 -2
  63. data/lib/adhearsion/voip/freeswitch/oes_server.rb +2 -2
  64. data/lib/theatre.rb +151 -0
  65. data/lib/theatre/README.markdown +64 -0
  66. data/lib/theatre/callback_definition_loader.rb +84 -0
  67. data/lib/theatre/guid.rb +23 -0
  68. data/lib/theatre/invocation.rb +121 -0
  69. data/lib/theatre/namespace_manager.rb +153 -0
  70. data/lib/theatre/version.rb +2 -0
  71. metadata +63 -138
  72. data/Manifest.txt +0 -149
  73. data/README.txt +0 -6
  74. data/ahn_generators/component/USAGE +0 -5
  75. data/ahn_generators/component/component_generator.rb +0 -57
  76. data/ahn_generators/component/templates/configuration.rb +0 -0
  77. data/ahn_generators/component/templates/lib/lib.rb.erb +0 -3
  78. data/ahn_generators/component/templates/test/test.rb.erb +0 -12
  79. data/ahn_generators/component/templates/test/test_helper.rb +0 -14
  80. data/app_generators/ahn/templates/components/simon_game/configuration.rb +0 -0
  81. data/app_generators/ahn/templates/components/simon_game/test/test_helper.rb +0 -14
  82. data/app_generators/ahn/templates/components/simon_game/test/test_simon_game.rb +0 -31
  83. data/lib/adhearsion/core_extensions/array.rb +0 -0
  84. data/lib/adhearsion/core_extensions/guid.rb +0 -5
  85. data/lib/adhearsion/core_extensions/hash.rb +0 -0
  86. data/lib/adhearsion/core_extensions/numeric.rb +0 -4
  87. data/lib/adhearsion/core_extensions/proc.rb +0 -0
  88. data/lib/adhearsion/core_extensions/pseudo_uuid.rb +0 -11
  89. data/lib/adhearsion/core_extensions/publishable.rb +0 -73
  90. data/lib/adhearsion/core_extensions/string.rb +0 -26
  91. data/lib/adhearsion/core_extensions/thread.rb +0 -13
  92. data/lib/adhearsion/core_extensions/time.rb +0 -0
  93. data/lib/adhearsion/distributed/gateways/dbus_gateway.rb +0 -0
  94. data/lib/adhearsion/distributed/gateways/osa_gateway.rb +0 -0
  95. data/lib/adhearsion/distributed/gateways/rest_gateway.rb +0 -9
  96. data/lib/adhearsion/distributed/gateways/soap_gateway.rb +0 -9
  97. data/lib/adhearsion/distributed/gateways/xmlrpc_gateway.rb +0 -9
  98. data/lib/adhearsion/distributed/peer_finder.rb +0 -0
  99. data/lib/adhearsion/distributed/remote_cli.rb +0 -0
  100. data/lib/adhearsion/hooks.rb +0 -57
  101. data/lib/adhearsion/initializer/paths.rb +0 -55
  102. data/lib/adhearsion/services/scheduler.rb +0 -5
  103. data/lib/adhearsion/voip/asterisk/ami.rb +0 -147
  104. data/lib/adhearsion/voip/asterisk/ami/actions.rb +0 -238
  105. data/lib/adhearsion/voip/asterisk/ami/machine.rb +0 -871
  106. data/lib/adhearsion/voip/asterisk/ami/machine.rl +0 -109
  107. data/lib/adhearsion/voip/asterisk/ami/parser.rb +0 -262
  108. data/script/destroy +0 -14
  109. data/script/generate +0 -14
  110. data/spec/fixtures/dialplan.rb +0 -3
  111. data/spec/initializer/test_configuration.rb +0 -267
  112. data/spec/initializer/test_loading.rb +0 -162
  113. data/spec/initializer/test_paths.rb +0 -43
  114. data/spec/silence.rb +0 -10
  115. data/spec/test_ahn_command.rb +0 -149
  116. data/spec/test_code_quality.rb +0 -87
  117. data/spec/test_component_manager.rb +0 -97
  118. data/spec/test_constants.rb +0 -8
  119. data/spec/test_drb.rb +0 -104
  120. data/spec/test_helper.rb +0 -94
  121. data/spec/test_hooks.rb +0 -37
  122. data/spec/test_host_definitions.rb +0 -79
  123. data/spec/test_initialization.rb +0 -105
  124. data/spec/test_logging.rb +0 -80
  125. data/spec/test_relationship_properties.rb +0 -54
  126. data/spec/voip/asterisk/ami_response_definitions.rb +0 -23
  127. data/spec/voip/asterisk/config_file_generators/test_agents.rb +0 -253
  128. data/spec/voip/asterisk/config_file_generators/test_queues.rb +0 -325
  129. data/spec/voip/asterisk/config_file_generators/test_voicemail.rb +0 -306
  130. data/spec/voip/asterisk/menu_command/test_calculated_match.rb +0 -111
  131. data/spec/voip/asterisk/menu_command/test_matchers.rb +0 -98
  132. data/spec/voip/asterisk/mock_ami_server.rb +0 -176
  133. data/spec/voip/asterisk/test_agi_server.rb +0 -451
  134. data/spec/voip/asterisk/test_ami.rb +0 -227
  135. data/spec/voip/asterisk/test_commands.rb +0 -2006
  136. data/spec/voip/asterisk/test_config_manager.rb +0 -129
  137. data/spec/voip/dsl/dispatcher_spec_helper.rb +0 -45
  138. data/spec/voip/dsl/test_dialing_dsl.rb +0 -268
  139. data/spec/voip/dsl/test_dispatcher.rb +0 -82
  140. data/spec/voip/dsl/test_parser.rb +0 -87
  141. data/spec/voip/freeswitch/test_basic_connection_manager.rb +0 -39
  142. data/spec/voip/freeswitch/test_inbound_connection_manager.rb +0 -39
  143. data/spec/voip/freeswitch/test_oes_server.rb +0 -9
  144. data/spec/voip/test_call_routing.rb +0 -127
  145. data/spec/voip/test_dialplan_manager.rb +0 -372
  146. data/spec/voip/test_numerical_string.rb +0 -48
  147. data/spec/voip/test_phone_number.rb +0 -36
  148. data/test/test_ahn_generator.rb +0 -59
  149. data/test/test_component_generator.rb +0 -52
  150. data/test/test_generator_helper.rb +0 -20
@@ -1,306 +0,0 @@
1
- require File.join(File.dirname(__FILE__), *%w[.. .. .. test_helper])
2
- require 'adhearsion/voip/asterisk/config_generators/voicemail.conf'
3
-
4
- context 'Basic requirements of the Voicemail config generator' do
5
- attr_reader :config
6
- before :each do
7
- @config = Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Voicemail.new
8
- end
9
-
10
- test 'should have a [general] context' do
11
- config.to_sanitary_hash.has_key?('[general]').should.equal true
12
- end
13
-
14
- test 'should set the format to "wav" by default in the general section' do
15
- config.to_sanitary_hash['[general]'].should.include 'format=wav'
16
- end
17
-
18
- test 'an exception should be raised if the context name is "general"' do
19
- the_following_code {
20
- config.context(:general) {|_|}
21
- }.should.raise ArgumentError
22
- end
23
-
24
- end
25
-
26
- context 'Defining recording-related settings of the Voicemail config file' do
27
-
28
- attr_reader :recordings
29
- before :each do
30
- @recordings = Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Voicemail::RecordingDefinition.new
31
- end
32
-
33
- test 'the recordings setting setter' do
34
- Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Voicemail.new.recordings.should.be.kind_of? recordings.class
35
- end
36
-
37
- test 'recordings format should only allow a few options' do
38
- the_following_code {
39
- recordings.format :wav
40
- recordings.format :wav49
41
- recordings.format :gsm
42
- }.should.not.raise
43
-
44
- the_following_code {
45
- recordings.format :lolcats
46
- }.should.raise ArgumentError
47
- end
48
-
49
- end
50
-
51
- context 'Defining email-related Voicemail settings' do
52
-
53
- attr_reader :email
54
- before :each do
55
- @email = Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Voicemail::EmailDefinition.new
56
- end
57
-
58
- test 'the [] operator is overloaded to return conveniences for the body() and subject() methods' do
59
- variables = %{#{email[:name]} #{email[:mailbox]} #{email[:date]} #{email[:duration]} } +
60
- %{#{email[:message_number]} #{email[:caller_id]} #{email[:caller_id_number]} } +
61
- %{#{email[:caller_id_name]}}
62
- formatted = %{${VM_NAME} ${VM_MAILBOX} ${VM_DATE} ${VM_DUR} ${VM_MSGNUM} ${VM_CALLERID} ${VM_CIDNUM} ${VM_CIDNAME}}
63
- email.body variables
64
- email.subject variables
65
- email.properties[:emailbody].should == formatted
66
- email.properties[:emailsubject].should == formatted
67
- end
68
-
69
- test 'when defining a body, newlines should be escaped and carriage returns removed' do
70
- unescaped, escaped = "one\ntwo\n\r\r\nthree\n\n\n", 'one\ntwo\n\nthree\n\n\n'
71
- email.body unescaped
72
- email.properties[:emailbody].should == escaped
73
- end
74
-
75
- test 'the body must not be allowed to exceed 512 characters' do
76
- the_following_code {
77
- email.body "X" * 512
78
- }.should.not.raise ArgumentError
79
-
80
- the_following_code {
81
- email.body "X" * 513
82
- }.should.raise ArgumentError
83
-
84
- the_following_code {
85
- email.body "X" * 1000
86
- }.should.raise ArgumentError
87
- end
88
-
89
- test 'should store away the email command properly' do
90
- mail_command = "/usr/sbin/sendmail -f alice@wonderland.com -t"
91
- email.command mail_command
92
- email.properties[:mailcmd].should == mail_command
93
- end
94
-
95
- end
96
-
97
- context 'A mailbox definition' do
98
- attr_reader :mailbox
99
- before :each do
100
- @mailbox = Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Voicemail::ContextDefinition::MailboxDefinition.new("123")
101
- end
102
-
103
- test 'setting the name should be reflected in the to_hash form of the definition' do
104
- mailbox.name "Foobar"
105
- mailbox.to_hash[:name].should == "Foobar"
106
- end
107
-
108
- test 'setting the pin_number should be reflected in the to_hash form of the definition' do
109
- mailbox.pin_number 555
110
- mailbox.to_hash[:pin_number].should.equal 555
111
- end
112
-
113
- test 'the mailbox number should be available in the mailbox_number getter' do
114
- Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Voicemail::ContextDefinition::MailboxDefinition.new '123'
115
- mailbox.mailbox_number.should.equal '123'
116
- end
117
-
118
- test 'an ArgumentError should be raised if the mailbox_number is not numeric' do
119
- the_following_code {
120
- Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Voicemail::ContextDefinition::MailboxDefinition.new("this is not numeric")
121
- }.should.raise ArgumentError
122
- end
123
-
124
- test 'an ArgumentError should be raised if the pin_number is not numeric' do
125
- the_following_code {
126
- mailbox.pin_number "this is not numeric"
127
- }.should.raise ArgumentError
128
- end
129
-
130
- test "the string representation should be valid" do
131
- expected = "123 => 1337,Jay Phillips,ahn@adhearsion.com"
132
- mailbox.pin_number 1337
133
- mailbox.name "Jay Phillips"
134
- mailbox.email "ahn@adhearsion.com"
135
- mailbox.to_s.should == expected
136
- end
137
-
138
- test 'should not add a trailing comma when the email is left out' do
139
- mailbox.pin_number 1337
140
- mailbox.name "Jay Phillips"
141
- mailbox.to_s.ends_with?(',').should.equal false
142
- end
143
-
144
- test 'should not add a trailing comma when the email and name is left out' do
145
- mailbox.pin_number 1337
146
- mailbox.to_s.ends_with?(',').should.equal false
147
- end
148
-
149
- end
150
-
151
- context "A Voicemail context definition" do
152
-
153
- test "should ultimately add a [] context definition to the string output" do
154
- voicemail = Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Voicemail.new
155
- voicemail.context "monkeys" do |config|
156
- config.should.be.kind_of voicemail.class::ContextDefinition
157
- config.mailbox 1234 do |mailbox|
158
- mailbox.pin_number 3333
159
- mailbox.email "alice@wonderland.com"
160
- mailbox.name "Alice Little"
161
- end
162
- end
163
- voicemail.to_sanitary_hash.has_key?('[monkeys]').should.equal true
164
- end
165
-
166
- test 'should raise a LocalJumpError if no block is given' do
167
- the_following_code {
168
- Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Voicemail.new.context('lols')
169
- }.should.raise LocalJumpError
170
- end
171
-
172
- test 'its string representation should begin with a context declaration' do
173
- vm = Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Voicemail.new
174
- vm.context("jay") {|_|}.to_s.starts_with?("[jay]").should.equal true
175
- end
176
-
177
- end
178
-
179
- context 'Defining Voicemail contexts with mailbox definitions' do
180
-
181
- end
182
-
183
- context 'An expansive example of the Voicemail config generator' do
184
-
185
- before :each do
186
- @employees = [
187
- {:name => "Tango", :pin_number => 7777, :mailbox_number => 10},
188
- {:name => "Echo", :pin_number => 7777, :mailbox_number => 20},
189
- {:name => "Sierra", :pin_number => 7777, :mailbox_number => 30},
190
- {:name => "Tango2", :pin_number => 7777, :mailbox_number => 40}
191
- ].map { |hash| OpenStruct.new(hash) }
192
-
193
- @groups = [
194
- {:name => "Brand New Cadillac", :pin_number => 1111, :mailbox_number => 1},
195
- {:name => "Jimmy Jazz", :pin_number => 2222, :mailbox_number => 2},
196
- {:name => "Death or Glory", :pin_number => 3333, :mailbox_number => 3},
197
- {:name => "Rudie Can't Fail", :pin_number => 4444, :mailbox_number => 4},
198
- {:name => "Spanish Bombs", :pin_number => 5555, :mailbox_number => 5}
199
- ].map { |hash| OpenStruct.new(hash) }
200
- end
201
-
202
- test 'a huge, brittle integration test' do
203
- vm = Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Voicemail.new do |voicemail|
204
- voicemail.context :default do |context|
205
- context.mailbox 123 do |mailbox|
206
- mailbox.name "Administrator"
207
- mailbox.email "jabberwocky@wonderland.com"
208
- mailbox.pin_number 9876
209
- end
210
- end
211
-
212
- voicemail.context :employees do |context|
213
- @employees.each do |employee|
214
- context.mailbox employee.mailbox_number do |mailbox|
215
- mailbox.pin_number 1337
216
- mailbox.name employee.name
217
- end
218
- end
219
- end
220
-
221
- voicemail.context :groups do |context|
222
- @groups.each do |group|
223
- context.mailbox group.mailbox_number do |mailbox|
224
- mailbox.pin_number 1337
225
- mailbox.name group.name
226
- mailbox.email "foo@qaz.org"
227
- end
228
- end
229
- end
230
-
231
- voicemail.execute_on_pin_change "/path/to/my/changer_script.rb"
232
- ############################################################################
233
- ############################################################################
234
-
235
- signature = "Your Friendly Phone System"
236
-
237
- # execute_after_email "netcat 192.168.1.2 12345"
238
- # greeting_maximum 1.minute
239
- # time_jumped_with_skip_key 3.seconds # milliseconds!
240
- # logging_in do |config|
241
- # config.maximum_attempts 3
242
- # end
243
-
244
- voicemail.recordings do |config|
245
- config.format :wav # ONCE YOU PICK A FORMAT, NEVER CHANGE IT UNLESS YOU KNOW THE CONSEQUENCES!
246
- config.allowed_length 3.seconds..5.minutes
247
- config.maximum_silence 10.seconds
248
- # config.silence_threshold 128 # wtf?
249
- end
250
-
251
- voicemail.emails do |config|
252
- config.from :name => signature, :email => "noreply@adhearsion.com"
253
- config.attach_recordings true
254
- config.command '/usr/sbin/sendmail -f alice@wonderland.com -t'
255
- config.subject "New voicemail for #{config[:name]}"
256
- config.body <<-BODY.unindent
257
- Dear #{config[:name]}:
258
-
259
- The caller #{config[:caller_id]} left you a #{config[:duration]} long voicemail
260
- (number #{config[:message_number]}) on #{config[:date]} in mailbox #{config[:mailbox]}.
261
-
262
- #{ "The recording is attached to this email.\n" if config.attach_recordings? }
263
- - #{signature}
264
- BODY
265
- end
266
- end
267
- internalized = vm.to_sanitary_hash
268
- internalized.size.should.equal 5 # general, zonemessages, default, employees, groups
269
-
270
- target_config = <<-CONFIG
271
- [general]
272
- attach=yes
273
- emailbody=Dear ${VM_NAME}:\\nThe caller ${VM_CALLERID} left you a ${VM_DUR} long voicemail\\n(number ${VM_MSGNUM}) on ${VM_DATE} in mailbox ${VM_MAILBOX}.\\nThe recording is attached to this email.\\n- Your Friendly Phone System\\n
274
- emailsubject=New voicemail for ${VM_NAME}
275
- externpass=/path/to/my/changer_script.rb
276
- format=wav
277
- fromstring=Your Friendly Phone System
278
- mailcmd=/usr/sbin/sendmail -f alice@wonderland.com -t
279
- serveremail=noreply@adhearsion.com
280
-
281
- [zonemessages]
282
- eastern=America/New_York|'vm-received' Q 'digits/at' IMp
283
- central=America/Chicago|'vm-received' Q 'digits/at' IMp
284
- central24=America/Chicago|'vm-received' q 'digits/at' H N 'hours'
285
- military=Zulu|'vm-received' q 'digits/at' H N 'hours' 'phonetic/z_p'
286
- european=Europe/Copenhagen|'vm-received' a d b 'digits/at' HM
287
- [default]
288
- 123 => 9876,Administrator,jabberwocky@wonderland.com
289
-
290
- [employees]
291
- 10 => 1337,Tango
292
- 20 => 1337,Echo
293
- 30 => 1337,Sierra
294
- 40 => 1337,Tango2
295
-
296
- [groups]
297
- 1 => 1337,Brand New Cadillac,foo@qaz.org
298
- 2 => 1337,Jimmy Jazz,foo@qaz.org
299
- 3 => 1337,Death or Glory,foo@qaz.org
300
- 4 => 1337,Rudie Can't Fail,foo@qaz.org
301
- 5 => 1337,Spanish Bombs,foo@qaz.org
302
- CONFIG
303
- vm.to_s.grep(/^$|^[^;]/).join.strip.should == target_config.strip
304
-
305
- end
306
- end
@@ -1,111 +0,0 @@
1
- require File.join(File.dirname(__FILE__), *%w[.. .. .. test_helper])
2
- require 'adhearsion/voip/menu_state_machine/calculated_match'
3
-
4
- context 'CalculatedMatch' do
5
- test "should make accessible the context name" do
6
- Adhearsion::VoIP::CalculatedMatch.new(:match_payload => :foobar).match_payload.should.equal :foobar
7
- end
8
- test "should make accessible the original pattern" do
9
- Adhearsion::VoIP::CalculatedMatch.new(:pattern => :something).pattern.should.equal :something
10
- end
11
- test "should make accessible the matched query" do
12
- Adhearsion::VoIP::CalculatedMatch.new(:query => 123).query.should.equal 123
13
- end
14
- test '#type_of_match should return :exact, :potential, or nil' do
15
- Adhearsion::VoIP::CalculatedMatch.new(:potential_matches => [1]).type_of_match.should.equal :potential
16
- Adhearsion::VoIP::CalculatedMatch.new(:exact_matches => [3,3]).type_of_match.should.equal :exact
17
- Adhearsion::VoIP::CalculatedMatch.new(:exact_matches => [8,3], :potential_matches => [0,9]).type_of_match.should.equal :exact
18
- Adhearsion::VoIP::CalculatedMatch.new.type_of_match.should.equal nil
19
- end
20
- test '#exact_match? should return true if the match was exact' do
21
- Adhearsion::VoIP::CalculatedMatch.new(:exact_matches => [0,3,5]).should.be.exact_match
22
- end
23
-
24
- test '#potential_match? should return true if the match was exact' do
25
- Adhearsion::VoIP::CalculatedMatch.new(:potential_matches => [88,99,77]).should.be.potential_match
26
- end
27
-
28
- test '#exact_matches should return an array of exact matches' do
29
- Adhearsion::VoIP::CalculatedMatch.new(:exact_matches => [0,3,5]).exact_matches.should == [0,3,5]
30
- end
31
-
32
- test '#potential_matches should return an array of potential matches' do
33
- Adhearsion::VoIP::CalculatedMatch.new(:potential_matches => [88,99,77]).potential_matches.should == [88,99,77]
34
- end
35
-
36
- test '::failed_match! should return a match that *really* failed' do
37
- failure = Adhearsion::VoIP::CalculatedMatch.failed_match! 10..20, 30, :match_payload_does_not_matter
38
- failure.should.not.be.exact_match
39
- failure.should.not.be.potential_match
40
- failure.type_of_match.should.be nil
41
-
42
- failure.match_payload.should.equal :match_payload_does_not_matter
43
- failure.pattern.should == (10..20)
44
- failure.query.should == 30
45
- end
46
-
47
- end
48
-
49
- context 'CalculatedMatchCollection' do
50
-
51
- include CalculatedMatchCollectionTestHelper
52
-
53
- attr_reader :collection
54
- before:each do
55
- @collection = Adhearsion::VoIP::CalculatedMatchCollection.new
56
- end
57
-
58
- test 'the <<() method should collect the potential matches into the actual_potential_matches Array' do
59
- mock_matches_array_1 = [:foo, :bar, :qaz],
60
- mock_matches_array_2 = [10,20,30]
61
- mock_matches_1 = mock_with_potential_matches mock_matches_array_1
62
- mock_matches_2 = mock_with_potential_matches mock_matches_array_2
63
-
64
- collection << mock_matches_1
65
- collection.actual_potential_matches.should == mock_matches_array_1
66
-
67
- collection << mock_matches_2
68
- collection.actual_potential_matches.should == mock_matches_array_1 + mock_matches_array_2
69
- end
70
-
71
- test 'the <<() method should collect the exact matches into the actual_exact_matches Array' do
72
- mock_matches_array_1 = [:blam, :blargh],
73
- mock_matches_array_2 = [5,4,3,2,1]
74
- mock_matches_1 = mock_with_exact_matches mock_matches_array_1
75
- mock_matches_2 = mock_with_exact_matches mock_matches_array_2
76
-
77
- collection << mock_matches_1
78
- collection.actual_exact_matches.should == mock_matches_array_1
79
-
80
- collection << mock_matches_2
81
- collection.actual_exact_matches.should == mock_matches_array_1 + mock_matches_array_2
82
- end
83
-
84
- test "if any exact matches exist, the exact_match?() method should return true" do
85
- collection << mock_with_exact_matches([1,2,3])
86
- collection.should.be.exact_match
87
- end
88
-
89
- test "if any potential matches exist, the potential_match?() method should return true" do
90
- collection << mock_with_potential_matches([1,2,3])
91
- collection.should.be.potential_match
92
- end
93
- end
94
-
95
- BEGIN {
96
- module CalculatedMatchCollectionTestHelper
97
- def mock_with_potential_matches(potential_matches)
98
- Adhearsion::VoIP::CalculatedMatch.new :potential_matches => potential_matches
99
- end
100
-
101
- def mock_with_exact_matches(exact_matches)
102
- Adhearsion::VoIP::CalculatedMatch.new :exact_matches => exact_matches
103
- end
104
-
105
- def mock_with_potential_and_exact_matches(potential_matches, exact_matches)
106
- Adhearsion::VoIP::CalculatedMatch.new :potential_matches => potential_matches,
107
- :exact_matches => exact_matches
108
- end
109
-
110
- end
111
- }
@@ -1,98 +0,0 @@
1
- require File.join(File.dirname(__FILE__), *%w[.. .. .. test_helper])
2
- require 'adhearsion/voip/menu_state_machine/menu_builder'
3
- require 'adhearsion/voip/menu_state_machine/matchers'
4
-
5
- context "MatchCalculator" do
6
- test "the build_with_pattern() method should return an appropriate subclass instance based on the pattern's class" do
7
- Adhearsion::VoIP::MatchCalculator.build_with_pattern(1..2, :main).should.be.instance_of Adhearsion::VoIP::RangeMatchCalculator
8
- end
9
-
10
- end
11
-
12
- context "The RangeMatchCalculator" do
13
-
14
- test "matching with a Range should handle the case of two potential matches in the range" do
15
- digits_that_begin_with_eleven = [110..119, 1100..1111].map { |x| Array(x) }.flatten
16
-
17
- calculator = Adhearsion::VoIP::RangeMatchCalculator.new 11..1111, :match_payload_doesnt_matter
18
- match = calculator.match 11
19
- match.exact_matches.should == [11]
20
- match.potential_matches.should == digits_that_begin_with_eleven
21
- end
22
-
23
- test 'return values of #match should be an instance of CalculatedMatch' do
24
- calculator = Adhearsion::VoIP::RangeMatchCalculator.new 1..9, :match_payload_doesnt_matter
25
- calculator.match(0).should.be.instance_of Adhearsion::VoIP::CalculatedMatch
26
- calculator.match(1000).should.be.instance_of Adhearsion::VoIP::CalculatedMatch
27
- end
28
-
29
- end
30
-
31
- context "FixnumMatchCalculator" do
32
- attr_reader :match_payload
33
- before:each do
34
- @match_payload = :main
35
- end
36
-
37
- test "a potential match scenario" do
38
- calculator = Adhearsion::VoIP::FixnumMatchCalculator.new(444, match_payload)
39
- match = calculator.match 4
40
- match.should.be.potential_match
41
- match.should.not.be.exact_match
42
- match.potential_matches.should == [444]
43
- end
44
-
45
- test 'a multi-digit exact match scenario' do
46
- calculator = Adhearsion::VoIP::FixnumMatchCalculator.new(5555, match_payload)
47
- calculator.match(5555).should.be.exact_match
48
- end
49
-
50
- test 'a single-digit exact match scenario' do
51
- calculator = Adhearsion::VoIP::FixnumMatchCalculator.new(1, match_payload)
52
- calculator.match(1).should.be.exact_match
53
- end
54
-
55
- test 'the context name given to the calculator should be passed on to the CalculatedMatch' do
56
- match_payload = :icanhascheezburger
57
- calculator = Adhearsion::VoIP::FixnumMatchCalculator.new(1337, match_payload)
58
- calculator.match(1337).match_payload.should.equal match_payload
59
- end
60
-
61
- end
62
-
63
- context "StringMatchCalculator" do
64
-
65
- attr_reader :match_payload
66
- before:each do
67
- @match_payload = :doesnt_matter
68
- end
69
-
70
- test "numerical digits mixed with special digits" do
71
-
72
- %w[5*11#3 5*** ###].each do |str|
73
- calculator = Adhearsion::VoIP::StringMatchCalculator.new(str, match_payload)
74
-
75
- match_case = calculator.match str[0,2]
76
-
77
- match_case.should.not.be.exact_match
78
- match_case.should.be.potential_match
79
- match_case.potential_matches.should == [str]
80
-
81
- match_case = calculator.match str
82
- match_case.should.be.exact_match
83
- match_case.should.not.be.potential_match
84
- match_case.exact_matches.should == [str]
85
- end
86
- end
87
-
88
- test "matching the special DTMF characters such as * and #" do
89
- %w[* #].each do |special_digit|
90
- calculator = Adhearsion::VoIP::StringMatchCalculator.new(special_digit, match_payload)
91
- match_case = calculator.match special_digit
92
- match_case.should.not.be.potential_match
93
- match_case.should.be.exact_match
94
- match_case.exact_matches.first.should == special_digit
95
- end
96
- end
97
-
98
- end