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,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
- }
@@ -1,325 +0,0 @@
1
- require File.join(File.dirname(__FILE__), *%w[.. .. .. test_helper])
2
- require 'adhearsion/voip/asterisk/config_generators/queues.conf'
3
-
4
- context "The queues.conf config file generator" do
5
-
6
- include QueuesConfigFileGeneratorTestHelper
7
-
8
- attr_reader :queues
9
- before:each do
10
- reset_queues!
11
- end
12
-
13
- test 'should set autofill=yes by default' do
14
- generated_config_should_have_pair :autofill => 'yes'
15
- end
16
-
17
- test 'should have a [general] section' do
18
- queues.conf.should.include "[general]\n"
19
- end
20
-
21
- test 'should yield a Queues object in its constructor' do
22
- Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Queues.new do |config|
23
- config.should.be.kind_of Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Queues
24
- end
25
- end
26
-
27
- test 'should add the warning message to the to_s output' do
28
- queues.conf.should =~ /^\s*;.{10}/
29
- end
30
-
31
- end
32
-
33
- context "The queues.conf config file queues's QueueDefinition" do
34
-
35
- include QueuesConfigFileGeneratorTestHelper
36
-
37
- attr_reader :queues
38
- before:each do
39
- reset_queues!
40
- end
41
-
42
- test 'should include [queue_name]' do
43
- name_of_queue = "leet_hax0rz"
44
- queues.queue(name_of_queue).to_s.should.include "[#{name_of_queue}]"
45
- end
46
-
47
- test '#member should create a valid Agent "channel driver" to the member definition list' do
48
- sample_queue = queues.queue "sales" do |sales|
49
- sales.member 123
50
- sales.member "Jay"
51
- sales.member 'SIP/jay-desk-650'
52
- sales.member 'IAX2/12345@voipms/15554443333'
53
- end
54
- sample_queue.members.should == %w[Agent/123 Agent/Jay SIP/jay-desk-650 IAX2/12345@voipms/15554443333]
55
- end
56
-
57
- test 'should automatically enable the two AMI-related events' do
58
- @queues = queues.queue 'name'
59
- generated_config_should_have_pair :eventwhencalled => 'vars'
60
- generated_config_should_have_pair :eventmemberstatus => 'yes'
61
- end
62
-
63
- test '#strategy should only allow the pre-defined settings' do
64
- [:ringall, :roundrobin, :leastrecent, :fewestcalls, :random, :rrmemory].each do |strategy|
65
- the_following_code {
66
- q = queues.queue 'foobar'
67
- q.strategy strategy
68
- }.should.not.raise
69
- end
70
-
71
- the_following_code {
72
- queues.queue('qwerty').strategy :this_is_not_a_valid_strategy
73
- }.should.raise ArgumentError
74
-
75
- end
76
-
77
- test '#sound_files raises an argument error when it sees an unrecognized key' do
78
- the_following_code {
79
- queues.queue 'foobar' do |foobar|
80
- foobar.sound_files \
81
- :you_are_next => rand.to_s,
82
- :there_are => rand.to_s,
83
- :calls_waiting => rand.to_s,
84
- :hold_time => rand.to_s,
85
- :minutes => rand.to_s,
86
- :seconds => rand.to_s,
87
- :thank_you => rand.to_s,
88
- :less_than => rand.to_s,
89
- :report_hold => rand.to_s,
90
- :periodic_announcement => rand.to_s
91
- end
92
- }.should.not.raise
93
-
94
- [:x_you_are_next, :x_there_are, :x_calls_waiting, :x_hold_time, :x_minutes,
95
- :x_seconds, :x_thank_you, :x_less_than, :x_report_hold, :x_periodic_announcement].each do |bad_key|
96
- the_following_code {
97
- queues.queue("foobar") do |foobar|
98
- foobar.sound_files bad_key => rand.to_s
99
- end
100
- }.should.raise ArgumentError
101
- end
102
-
103
- end
104
-
105
- end
106
-
107
- context "The private, helper methods in QueueDefinition" do
108
-
109
- include QueuesConfigFileGeneratorTestHelper
110
-
111
- attr_reader :queue
112
- before:each do
113
- reset_queues!
114
- @queue = @queues.queue "doesn't matter"
115
- end
116
-
117
- test '#boolean should convert a boolean into "yes" or "no"' do
118
- mock_of_properties = flexmock "mock of the properties instance variable of a QueueDefinition"
119
- mock_of_properties.should_receive(:[]=).once.with("icanhascheezburger", "yes")
120
- flexmock(queue).should_receive(:properties).and_return mock_of_properties
121
- queue.send(:boolean, "icanhascheezburger" => true)
122
- end
123
-
124
- test '#int should raise an argument error when its argument is not Numeric' do
125
- the_following_code {
126
- queue.send(:int, "eisley" => :i_break_things!)
127
- }.should.raise ArgumentError
128
- end
129
-
130
- test '#int should coerce a String into a Numeric if possible' do
131
- mock_of_properties = flexmock "mock of the properties instance variable of a QueueDefinition"
132
- mock_of_properties.should_receive(:[]=).once.with("chimpanzee", 1337)
133
- flexmock(queue).should_receive(:properties).and_return mock_of_properties
134
- queue.send(:int, "chimpanzee" => "1337")
135
- end
136
-
137
- test '#string should add the argument directly to the properties' do
138
- mock_of_properties = flexmock "mock of the properties instance variable of a QueueDefinition"
139
- mock_of_properties.should_receive(:[]=).once.with("eins", "zwei")
140
- flexmock(queue).should_receive(:properties).and_return mock_of_properties
141
- queue.send(:string, "eins" => "zwei")
142
- end
143
-
144
- test '#one_of() should add its successful match to the properties attribute' do
145
- mock_properties = flexmock "mock of the properties instance variable of a QueueDefinition"
146
- mock_properties.should_receive(:[]=).once.with(:doesnt_matter, 5)
147
- flexmock(queue).should_receive(:properties).once.and_return mock_properties
148
-
149
- queue.send(:one_of, 1..100, :doesnt_matter => 5)
150
- end
151
-
152
- test "one_of() should convert booleans to yes/no" do
153
- mock_properties = flexmock "mock of the properties instance variable of a QueueDefinition"
154
- mock_properties.should_receive(:[]=).once.with(:doesnt_matter, 'yes')
155
- flexmock(queue).should_receive(:properties).once.and_return mock_properties
156
- queue.send(:one_of, [true, false, :strict], :doesnt_matter => true)
157
-
158
- mock_properties = flexmock "mock of the properties instance variable of a QueueDefinition"
159
- mock_properties.should_receive(:[]=).once.with(:doesnt_matter, :strict)
160
- flexmock(queue).should_receive(:properties).once.and_return mock_properties
161
- queue.send(:one_of, [true, false, :strict], :doesnt_matter => :strict)
162
-
163
- mock_properties = flexmock "mock of the properties instance variable of a QueueDefinition"
164
- mock_properties.should_receive(:[]=).once.with(:doesnt_matter, 'no')
165
- flexmock(queue).should_receive(:properties).once.and_return mock_properties
166
- queue.send(:one_of, [true, false, :strict], :doesnt_matter => false)
167
- end
168
-
169
- test '#one_of() should raise an ArgumentError if a value is not in the criteria' do
170
- the_following_code {
171
- queue.send(:one_of, [:jay, :thomas, :phillips], :sister => :jill)
172
- }.should.raise ArgumentError
173
- end
174
- end
175
-
176
- context 'The queues.conf config file generator when ran against a really big example' do
177
-
178
- include QueuesConfigFileGeneratorTestHelper
179
-
180
- attr_reader :queues, :default_config
181
- before:each do
182
- reset_queues!
183
- @default_config = default_config = <<-CONFIG
184
- [general]
185
- persistentmembers=yes
186
- autofill=yes
187
- monitor-type=MixMonitor
188
-
189
- [markq]
190
- musicclass=default
191
- announce=queue-markq
192
- strategy=ringall
193
- servicelevel=60
194
- context=qoutcon
195
- timeout=15
196
- retry=5
197
- weight=0
198
- wrapuptime=15
199
- autofill=yes
200
- autopause=yes
201
- maxlen=0
202
- setinterfacevar=yes
203
- announce-frequency=90
204
- periodic-announce-frequency=60
205
- announce-holdtime=once
206
- announce-round-seconds=10
207
- queue-youarenext=queue-youarenext
208
- queue-thereare=queue-thereare
209
- queue-callswaiting=queue-callswaiting
210
- queue-holdtime=queue-holdtime
211
- queue-minutes=queue-minutes
212
- queue-seconds=queue-seconds
213
- queue-thankyou=queue-thankyou
214
- queue-lessthan=queue-less-than
215
- queue-reporthold=queue-reporthold
216
- periodic-announce=queue-periodic-announce
217
- monitor-format=gsm
218
- monitor-type=MixMonitor
219
- joinempty=yes
220
- leavewhenempty=yes
221
- eventwhencalled=vars
222
- eventmemberstatus=yes
223
- reportholdtime=no
224
- ringinuse=no
225
- memberdelay=0
226
- timeoutrestart=no
227
-
228
- member => Zap/1
229
- member => Agent/007
230
- CONFIG
231
- end
232
-
233
- test "a sample config with multiple queues" do
234
-
235
- generated = Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Queues.new do |config|
236
- config.persistent_members true
237
- config.monitor_type :mix_monitor
238
-
239
- config.queue 'markq' do |markq|
240
- markq.music_class :default
241
- markq.play_on_connect 'queue-markq'
242
- markq.strategy :ringall
243
- markq.service_level 60
244
- markq.exit_to_context_on_digit_press 'qoutcon'
245
- markq.ring_timeout 15
246
- markq.retry_after_waiting 5
247
- markq.weight 0
248
- markq.wrapup_time 15
249
- markq.autopause true
250
- markq.maximum_length 0
251
- markq.queue_status_announce_frequency 90
252
- markq.announce_hold_time :once
253
- markq.announce_round_seconds 10
254
- markq.sound_files \
255
- :you_are_next => "queue-youarenext",
256
- :there_are => "queue-thereare",
257
- :calls_waiting => "queue-callswaiting",
258
- :hold_time => "queue-holdtime",
259
- :minutes => "queue-minutes",
260
- :seconds => "queue-seconds",
261
- :thank_you => "queue-thankyou",
262
- :less_than => "queue-less-than",
263
- :report_hold => "queue-reporthold"
264
- markq.periodically_announce "queue-periodic-announce"
265
- markq.monitor_format :gsm
266
- markq.monitor_type :mix_monitor
267
- markq.join_empty true
268
- markq.leave_when_empty true
269
- markq.report_hold_time false
270
- markq.ring_in_use false
271
- markq.delay_connection_by 0
272
- markq.timeout_restart false
273
-
274
- markq.member 'Zap/1'
275
- markq.member '007'
276
- end
277
- end
278
-
279
- cleaned_up_default_config = Adhearsion::VoIP::Asterisk::ConfigFileGenerators::
280
- AsteriskConfigGenerator.create_sanitary_hash_from(default_config)
281
-
282
- cleaned_up_generated_config = generated.to_sanitary_hash
283
-
284
- cleaned_up_generated_config.should == cleaned_up_default_config
285
- end
286
-
287
- end
288
-
289
- context "ConfigFileGeneratorTestHelper" do
290
-
291
- include QueuesConfigFileGeneratorTestHelper
292
-
293
- attr_reader :queues
294
-
295
- test "generated_config_has_pair() works properly" do
296
- @queues = flexmock "A fake queues with just one pair", :to_s => "foo=bar"
297
- generated_config_has_pair(:foo => "bar").should.be true
298
-
299
- @queues = flexmock "A fake queues with just one pair", :to_s => "[general]\n\nqaz=qwerty\nagent => 1,2,3"
300
- generated_config_has_pair(:qaz => "qwerty").should.be true
301
- generated_config_has_pair(:foo => "bar").should.be false
302
- end
303
-
304
- end
305
-
306
- BEGIN {
307
- module QueuesConfigFileGeneratorTestHelper
308
-
309
- def reset_queues!
310
- @queues = Adhearsion::VoIP::Asterisk::ConfigFileGenerators::Queues.new
311
- end
312
-
313
- def generated_config_should_have_pair(pair)
314
- generated_config_has_pair(pair).should.equal true
315
- end
316
-
317
- def generated_config_has_pair(pair)
318
- queues.to_s.grep(/=[^>]/).each do |line|
319
- key, value = line.strip.split('=')
320
- return true if pair == {key.to_sym => value}
321
- end
322
- false
323
- end
324
- end
325
- }