adhearsion 2.6.4 → 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -9
- data/CHANGELOG.md +22 -7
- data/Gemfile +2 -0
- data/README.markdown +4 -5
- data/Rakefile +1 -2
- data/adhearsion.gemspec +19 -8
- data/features/cli_create.feature +19 -3
- data/features/step_definitions/cli_steps.rb +0 -11
- data/features/support/env.rb +3 -4
- data/lib/adhearsion.rb +48 -27
- data/lib/adhearsion/call.rb +34 -50
- data/lib/adhearsion/call_controller.rb +6 -12
- data/lib/adhearsion/call_controller/dial.rb +15 -53
- data/lib/adhearsion/call_controller/input.rb +39 -162
- data/lib/adhearsion/call_controller/input/ask_grammar_builder.rb +44 -0
- data/lib/adhearsion/call_controller/input/menu_builder.rb +136 -0
- data/lib/adhearsion/call_controller/input/prompt_builder.rb +78 -0
- data/lib/adhearsion/call_controller/input/result.rb +46 -0
- data/lib/adhearsion/call_controller/output.rb +48 -67
- data/lib/adhearsion/call_controller/output/abstract_player.rb +3 -3
- data/lib/adhearsion/call_controller/output/async_player.rb +3 -3
- data/lib/adhearsion/call_controller/output/player.rb +1 -1
- data/lib/adhearsion/call_controller/record.rb +23 -8
- data/lib/adhearsion/calls.rb +1 -1
- data/lib/adhearsion/cli_commands/ahn_command.rb +2 -65
- data/lib/adhearsion/cli_commands/thor_errors.rb +0 -6
- data/lib/adhearsion/configuration.rb +91 -39
- data/lib/adhearsion/core_ext/blather/stanza.rb +41 -0
- data/lib/adhearsion/core_ext/blather/stanza/presence.rb +13 -0
- data/lib/adhearsion/error.rb +5 -0
- data/lib/adhearsion/event.rb +21 -0
- data/lib/adhearsion/event/active_speaker.rb +11 -0
- data/lib/adhearsion/event/answered.rb +11 -0
- data/lib/adhearsion/event/asterisk.rb +10 -0
- data/lib/adhearsion/event/asterisk/ami.rb +34 -0
- data/lib/adhearsion/event/complete.rb +75 -0
- data/lib/adhearsion/event/dtmf.rb +11 -0
- data/lib/adhearsion/event/end.rb +22 -0
- data/lib/adhearsion/event/input_timers_started.rb +9 -0
- data/lib/adhearsion/event/joined.rb +17 -0
- data/lib/adhearsion/event/offer.rb +14 -0
- data/lib/adhearsion/event/ringing.rb +11 -0
- data/lib/adhearsion/event/started_speaking.rb +13 -0
- data/lib/adhearsion/event/stopped_speaking.rb +13 -0
- data/lib/adhearsion/event/unjoined.rb +17 -0
- data/lib/adhearsion/events.rb +47 -66
- data/lib/adhearsion/foundation.rb +0 -1
- data/lib/adhearsion/foundation/object.rb +0 -5
- data/lib/adhearsion/generators/app/app_generator.rb +4 -1
- data/lib/adhearsion/generators/app/templates/Gemfile.erb +2 -10
- data/lib/adhearsion/generators/app/templates/adhearsion.erb +9 -9
- data/lib/adhearsion/generators/app/templates/config.ru +7 -0
- data/lib/adhearsion/generators/app/templates/en.yml +4 -0
- data/lib/adhearsion/generators/app/templates/events.erb +2 -2
- data/lib/adhearsion/generators/app/templates/hello_world.wav +0 -0
- data/lib/adhearsion/generators/app/templates/simon_game.rb +2 -1
- data/lib/adhearsion/generators/app/templates/simon_game_spec.rb +2 -2
- data/lib/adhearsion/has_headers.rb +34 -0
- data/lib/adhearsion/http_server.rb +37 -0
- data/lib/adhearsion/initializer.rb +19 -153
- data/lib/adhearsion/logging.rb +6 -25
- data/lib/adhearsion/outbound_call.rb +5 -5
- data/lib/adhearsion/plugin.rb +1 -0
- data/lib/adhearsion/protocol_error.rb +26 -0
- data/lib/adhearsion/rayo.rb +30 -0
- data/lib/adhearsion/rayo/client.rb +62 -0
- data/lib/adhearsion/rayo/client/component_registry.rb +33 -0
- data/lib/adhearsion/rayo/command.rb +21 -0
- data/lib/adhearsion/rayo/command/accept.rb +16 -0
- data/lib/adhearsion/rayo/command/answer.rb +16 -0
- data/lib/adhearsion/rayo/command/dial.rb +57 -0
- data/lib/adhearsion/rayo/command/hangup.rb +16 -0
- data/lib/adhearsion/rayo/command/join.rb +43 -0
- data/lib/adhearsion/rayo/command/mute.rb +13 -0
- data/lib/adhearsion/rayo/command/redirect.rb +23 -0
- data/lib/adhearsion/rayo/command/reject.rb +40 -0
- data/lib/adhearsion/rayo/command/unjoin.rb +24 -0
- data/lib/adhearsion/rayo/command/unmute.rb +13 -0
- data/lib/adhearsion/rayo/command_node.rb +47 -0
- data/lib/adhearsion/rayo/component.rb +21 -0
- data/lib/adhearsion/rayo/component/asterisk.rb +13 -0
- data/lib/adhearsion/rayo/component/asterisk/agi.rb +14 -0
- data/lib/adhearsion/rayo/component/asterisk/agi/command.rb +46 -0
- data/lib/adhearsion/rayo/component/asterisk/ami.rb +14 -0
- data/lib/adhearsion/rayo/component/asterisk/ami/action.rb +61 -0
- data/lib/adhearsion/rayo/component/component_node.rb +90 -0
- data/lib/adhearsion/rayo/component/input.rb +186 -0
- data/lib/adhearsion/rayo/component/output.rb +471 -0
- data/lib/adhearsion/rayo/component/prompt.rb +53 -0
- data/lib/adhearsion/rayo/component/receive_fax.rb +26 -0
- data/lib/adhearsion/rayo/component/record.rb +165 -0
- data/lib/adhearsion/rayo/component/send_fax.rb +64 -0
- data/lib/adhearsion/rayo/component/stop.rb +11 -0
- data/lib/adhearsion/rayo/connection.rb +12 -0
- data/lib/adhearsion/rayo/connection/asterisk.rb +74 -0
- data/lib/adhearsion/rayo/connection/connected.rb +22 -0
- data/lib/adhearsion/rayo/connection/generic_connection.rb +22 -0
- data/lib/adhearsion/rayo/connection/xmpp.rb +198 -0
- data/lib/adhearsion/rayo/disconnected_error.rb +22 -0
- data/lib/adhearsion/{punchblock_plugin → rayo}/initializer.rb +19 -19
- data/lib/adhearsion/rayo/rayo_node.rb +127 -0
- data/lib/adhearsion/rayo/ref.rb +57 -0
- data/lib/adhearsion/statistics.rb +1 -1
- data/lib/adhearsion/tasks.rb +1 -2
- data/lib/adhearsion/tasks/configuration.rb +1 -1
- data/lib/adhearsion/tasks/environment.rb +0 -2
- data/lib/adhearsion/tasks/i18n.rb +49 -0
- data/lib/adhearsion/translator.rb +11 -0
- data/lib/adhearsion/translator/asterisk.rb +234 -0
- data/lib/adhearsion/translator/asterisk/agi_app.rb +17 -0
- data/lib/adhearsion/translator/asterisk/agi_command.rb +45 -0
- data/lib/adhearsion/translator/asterisk/ami_error_converter.rb +20 -0
- data/lib/adhearsion/translator/asterisk/call.rb +416 -0
- data/lib/adhearsion/translator/asterisk/channel.rb +43 -0
- data/lib/adhearsion/translator/asterisk/component.rb +88 -0
- data/lib/adhearsion/translator/asterisk/component/asterisk.rb +15 -0
- data/lib/adhearsion/translator/asterisk/component/asterisk/agi_command.rb +42 -0
- data/lib/adhearsion/translator/asterisk/component/asterisk/ami_action.rb +68 -0
- data/lib/adhearsion/translator/asterisk/component/composed_prompt.rb +76 -0
- data/lib/adhearsion/translator/asterisk/component/dtmf_recognizer.rb +137 -0
- data/lib/adhearsion/translator/asterisk/component/input.rb +34 -0
- data/lib/adhearsion/translator/asterisk/component/input_component.rb +90 -0
- data/lib/adhearsion/translator/asterisk/component/mrcp_native_prompt.rb +71 -0
- data/lib/adhearsion/translator/asterisk/component/mrcp_prompt.rb +55 -0
- data/lib/adhearsion/translator/asterisk/component/mrcp_recog_prompt.rb +165 -0
- data/lib/adhearsion/translator/asterisk/component/output.rb +233 -0
- data/lib/adhearsion/translator/asterisk/component/record.rb +101 -0
- data/lib/adhearsion/translator/asterisk/component/stop_by_redirect.rb +30 -0
- data/lib/adhearsion/translator/asterisk/unimrcp_app.rb +28 -0
- data/lib/adhearsion/uri_list.rb +21 -0
- data/lib/adhearsion/version.rb +1 -1
- data/spec/adhearsion/call_controller/dial_spec.rb +79 -1420
- data/spec/adhearsion/call_controller/input_spec.rb +1141 -237
- data/spec/adhearsion/call_controller/output/async_player_spec.rb +10 -10
- data/spec/adhearsion/call_controller/output/player_spec.rb +8 -8
- data/spec/adhearsion/call_controller/output_spec.rb +162 -215
- data/spec/adhearsion/call_controller/record_spec.rb +15 -16
- data/spec/adhearsion/call_controller_spec.rb +23 -40
- data/spec/adhearsion/call_spec.rb +123 -129
- data/spec/adhearsion/calls_spec.rb +3 -3
- data/spec/adhearsion/configuration_spec.rb +94 -108
- data/spec/adhearsion/event/answered_spec.rb +50 -0
- data/spec/adhearsion/event/asterisk/Find Results +402 -0
- data/spec/adhearsion/event/asterisk/ami_spec.rb +81 -0
- data/spec/adhearsion/event/complete_spec.rb +176 -0
- data/spec/adhearsion/event/dtmf_spec.rb +35 -0
- data/spec/adhearsion/event/end_spec.rb +85 -0
- data/spec/adhearsion/event/input_timers_started_spec.rb +19 -0
- data/spec/adhearsion/event/joined_spec.rb +53 -0
- data/spec/adhearsion/event/offer_spec.rb +106 -0
- data/spec/adhearsion/event/ringing_spec.rb +50 -0
- data/spec/adhearsion/event/started_speaking_spec.rb +37 -0
- data/spec/adhearsion/event/stopped_speaking_spec.rb +37 -0
- data/spec/adhearsion/event/unjoined_spec.rb +48 -0
- data/spec/adhearsion/event/untitled +0 -0
- data/spec/adhearsion/events_spec.rb +19 -45
- data/spec/adhearsion/initializer_spec.rb +12 -184
- data/spec/adhearsion/logging_spec.rb +5 -20
- data/spec/adhearsion/outbound_call_spec.rb +13 -13
- data/spec/adhearsion/plugin_spec.rb +3 -4
- data/spec/adhearsion/protocol_error_spec.rb +91 -0
- data/spec/adhearsion/rayo/client/component_registry_spec.rb +26 -0
- data/spec/adhearsion/rayo/client_spec.rb +134 -0
- data/spec/adhearsion/rayo/command/accept_spec.rb +63 -0
- data/spec/adhearsion/rayo/command/answer_spec.rb +73 -0
- data/spec/adhearsion/rayo/command/dial_spec.rb +156 -0
- data/spec/adhearsion/rayo/command/hangup_spec.rb +63 -0
- data/spec/adhearsion/rayo/command/join_spec.rb +158 -0
- data/spec/adhearsion/rayo/command/mute_spec.rb +32 -0
- data/spec/adhearsion/rayo/command/redirect_spec.rb +89 -0
- data/spec/adhearsion/rayo/command/reject_spec.rb +117 -0
- data/spec/adhearsion/rayo/command/unjoin_spec.rb +82 -0
- data/spec/adhearsion/rayo/command/unmute_spec.rb +32 -0
- data/spec/adhearsion/rayo/command_node_spec.rb +101 -0
- data/spec/adhearsion/rayo/component/asterisk/agi/command_spec.rb +111 -0
- data/spec/adhearsion/rayo/component/asterisk/ami/action_spec.rb +173 -0
- data/spec/adhearsion/rayo/component/component_node_spec.rb +110 -0
- data/spec/adhearsion/rayo/component/input_spec.rb +715 -0
- data/spec/adhearsion/rayo/component/output_spec.rb +1030 -0
- data/spec/adhearsion/rayo/component/prompt_spec.rb +171 -0
- data/spec/adhearsion/rayo/component/receive_fax_spec.rb +136 -0
- data/spec/adhearsion/rayo/component/record_spec.rb +497 -0
- data/spec/adhearsion/rayo/component/send_fax_spec.rb +144 -0
- data/spec/adhearsion/rayo/connection/asterisk_spec.rb +118 -0
- data/spec/adhearsion/rayo/connection/xmpp_spec.rb +449 -0
- data/spec/adhearsion/rayo/initializer_spec.rb +353 -0
- data/spec/adhearsion/rayo/ref_spec.rb +168 -0
- data/spec/adhearsion/rayo_spec.rb +7 -0
- data/spec/adhearsion/router/route_spec.rb +1 -1
- data/spec/adhearsion/statistics_spec.rb +2 -5
- data/spec/adhearsion/translator/asterisk/call_spec.rb +2047 -0
- data/spec/adhearsion/translator/asterisk/component/asterisk/agi_command_spec.rb +256 -0
- data/spec/adhearsion/translator/asterisk/component/asterisk/ami_action_spec.rb +151 -0
- data/spec/adhearsion/translator/asterisk/component/composed_prompt_spec.rb +257 -0
- data/spec/adhearsion/translator/asterisk/component/input_spec.rb +571 -0
- data/spec/adhearsion/translator/asterisk/component/mrcp_native_prompt_spec.rb +774 -0
- data/spec/adhearsion/translator/asterisk/component/mrcp_prompt_spec.rb +1244 -0
- data/spec/adhearsion/translator/asterisk/component/output_spec.rb +1850 -0
- data/spec/adhearsion/translator/asterisk/component/record_spec.rb +426 -0
- data/spec/adhearsion/translator/asterisk/component/stop_by_redirect_spec.rb +62 -0
- data/spec/adhearsion/translator/asterisk/component_spec.rb +83 -0
- data/spec/adhearsion/translator/asterisk_spec.rb +685 -0
- data/spec/adhearsion/uri_list_spec.rb +88 -0
- data/spec/adhearsion_spec.rb +89 -14
- data/spec/fixtures/locale/en.yml +13 -0
- data/spec/fixtures/locale/it.yml +13 -0
- data/spec/spec_helper.rb +18 -5
- data/spec/support/call_controller_test_helpers.rb +3 -2
- data/spec/support/initializer_stubs.rb +3 -1
- data/spec/support/punchblock_examples.rb +65 -0
- data/spec/support/punchblock_mocks.rb +12 -0
- metadata +412 -70
- data/features/cli_daemon.feature +0 -20
- data/features/cli_restart.feature +0 -52
- data/features/cli_stop.feature +0 -50
- data/lib/adhearsion/call_controller/menu_dsl.rb +0 -21
- data/lib/adhearsion/call_controller/menu_dsl/array_match_calculator.rb +0 -26
- data/lib/adhearsion/call_controller/menu_dsl/calculated_match.rb +0 -43
- data/lib/adhearsion/call_controller/menu_dsl/calculated_match_collection.rb +0 -45
- data/lib/adhearsion/call_controller/menu_dsl/fixnum_match_calculator.rb +0 -11
- data/lib/adhearsion/call_controller/menu_dsl/match_calculator.rb +0 -40
- data/lib/adhearsion/call_controller/menu_dsl/menu.rb +0 -207
- data/lib/adhearsion/call_controller/menu_dsl/menu_builder.rb +0 -92
- data/lib/adhearsion/call_controller/menu_dsl/range_match_calculator.rb +0 -60
- data/lib/adhearsion/call_controller/menu_dsl/string_match_calculator.rb +0 -25
- data/lib/adhearsion/call_controller/utility.rb +0 -77
- data/lib/adhearsion/foundation/custom_daemonizer.rb +0 -52
- data/lib/adhearsion/punchblock_plugin.rb +0 -63
- data/scripts/cloc-1.64.pl +0 -10483
- data/spec/adhearsion/call_controller/menu_dsl/array_match_calculator_spec.rb +0 -76
- data/spec/adhearsion/call_controller/menu_dsl/calculated_match_collection_spec.rb +0 -60
- data/spec/adhearsion/call_controller/menu_dsl/calculated_match_spec.rb +0 -61
- data/spec/adhearsion/call_controller/menu_dsl/fixnum_match_calculator_spec.rb +0 -39
- data/spec/adhearsion/call_controller/menu_dsl/match_calculator_spec.rb +0 -17
- data/spec/adhearsion/call_controller/menu_dsl/menu_builder_spec.rb +0 -165
- data/spec/adhearsion/call_controller/menu_dsl/menu_spec.rb +0 -420
- data/spec/adhearsion/call_controller/menu_dsl/range_match_calculator_spec.rb +0 -32
- data/spec/adhearsion/call_controller/menu_dsl/string_match_calculator_spec.rb +0 -40
- data/spec/adhearsion/call_controller/utility_spec.rb +0 -90
- data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +0 -356
- data/spec/adhearsion/punchblock_plugin_spec.rb +0 -59
@@ -0,0 +1,106 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Adhearsion::Event::Offer do
|
6
|
+
it 'registers itself' do
|
7
|
+
expect(Adhearsion::Rayo::RayoNode.class_from_registration(:offer, 'urn:xmpp:rayo:1')).to eq(described_class)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "from a stanza" do
|
11
|
+
let :stanza do
|
12
|
+
<<-MESSAGE
|
13
|
+
<offer xmlns='urn:xmpp:rayo:1'
|
14
|
+
to='tel:+18003211212'
|
15
|
+
from='tel:+13058881212'>
|
16
|
+
<!-- Signaling (e.g. SIP) Headers -->
|
17
|
+
<header name="X-skill" value="agent" />
|
18
|
+
<header name="X-customer-id" value="8877" />
|
19
|
+
</offer>
|
20
|
+
MESSAGE
|
21
|
+
end
|
22
|
+
|
23
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml parse_stanza(stanza).root, '9f00061', '1' }
|
24
|
+
|
25
|
+
it { is_expected.to be_instance_of described_class }
|
26
|
+
|
27
|
+
it_should_behave_like 'event'
|
28
|
+
|
29
|
+
describe '#to' do
|
30
|
+
subject { super().to }
|
31
|
+
it { is_expected.to eq('tel:+18003211212') }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#from' do
|
35
|
+
subject { super().from }
|
36
|
+
it { is_expected.to eq('tel:+13058881212') }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#headers' do
|
40
|
+
subject { super().headers }
|
41
|
+
it { is_expected.to eq({ 'X-skill' => 'agent', 'X-customer-id' => '8877' }) }
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with no headers provided" do
|
45
|
+
let(:stanza) { '<offer xmlns="urn:xmpp:rayo:1"/>' }
|
46
|
+
|
47
|
+
describe '#headers' do
|
48
|
+
subject { super().headers }
|
49
|
+
it { is_expected.to eq({}) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with multiple headers of the same name" do
|
54
|
+
let :stanza do
|
55
|
+
<<-MESSAGE
|
56
|
+
<offer xmlns='urn:xmpp:rayo:1'
|
57
|
+
to='tel:+18003211212'
|
58
|
+
from='tel:+13058881212'>
|
59
|
+
<!-- Signaling (e.g. SIP) Headers -->
|
60
|
+
<header name="X-skill" value="sales" />
|
61
|
+
<header name="X-skill" value="complaints" />
|
62
|
+
</offer>
|
63
|
+
MESSAGE
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#headers' do
|
67
|
+
subject { super().headers }
|
68
|
+
it { is_expected.to eq({'X-skill' => ['sales', 'complaints']}) }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "when setting options in initializer" do
|
74
|
+
subject do
|
75
|
+
described_class.new to: 'tel:+18003211212',
|
76
|
+
from: 'tel:+13058881212',
|
77
|
+
headers: { 'X-skill' => 'agent', 'X-customer-id' => '8877' }
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#to' do
|
81
|
+
subject { super().to }
|
82
|
+
it { is_expected.to eq('tel:+18003211212') }
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#from' do
|
86
|
+
subject { super().from }
|
87
|
+
it { is_expected.to eq('tel:+13058881212') }
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#headers' do
|
91
|
+
subject { super().headers }
|
92
|
+
it { is_expected.to eq({ 'X-skill' => 'agent', 'X-customer-id' => '8877' }) }
|
93
|
+
end
|
94
|
+
|
95
|
+
context "with headers set to nil" do
|
96
|
+
subject do
|
97
|
+
described_class.new headers: nil
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#headers' do
|
101
|
+
subject { super().headers }
|
102
|
+
it { is_expected.to eq({}) }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Adhearsion::Event::Ringing do
|
6
|
+
it 'registers itself' do
|
7
|
+
expect(Adhearsion::Rayo::RayoNode.class_from_registration(:ringing, 'urn:xmpp:rayo:1')).to eq(described_class)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "from a stanza" do
|
11
|
+
let :stanza do
|
12
|
+
<<-MESSAGE
|
13
|
+
<ringing xmlns='urn:xmpp:rayo:1'>
|
14
|
+
<!-- Signaling (e.g. SIP) Headers -->
|
15
|
+
<header name="X-skill" value="agent" />
|
16
|
+
<header name="X-customer-id" value="8877" />
|
17
|
+
</ringing>
|
18
|
+
MESSAGE
|
19
|
+
end
|
20
|
+
|
21
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml parse_stanza(stanza).root, '9f00061', '1' }
|
22
|
+
|
23
|
+
it { is_expected.to be_instance_of described_class }
|
24
|
+
|
25
|
+
it_should_behave_like 'event'
|
26
|
+
|
27
|
+
describe '#headers' do
|
28
|
+
subject { super().headers }
|
29
|
+
it { is_expected.to eq({ 'X-skill' => 'agent', 'X-customer-id' => '8877' }) }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with no headers provided" do
|
33
|
+
let(:stanza) { '<ringing xmlns="urn:xmpp:rayo:1"/>' }
|
34
|
+
|
35
|
+
describe '#headers' do
|
36
|
+
subject { super().headers }
|
37
|
+
it { is_expected.to eq({}) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "when setting options in initializer" do
|
43
|
+
subject { described_class.new headers: { 'X-skill' => 'agent', 'X-customer-id' => '8877' } }
|
44
|
+
|
45
|
+
describe '#headers' do
|
46
|
+
subject { super().headers }
|
47
|
+
it { is_expected.to eq({ 'X-skill' => 'agent', 'X-customer-id' => '8877' }) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Adhearsion::Event::StartedSpeaking do
|
6
|
+
it 'registers itself' do
|
7
|
+
expect(Adhearsion::Rayo::RayoNode.class_from_registration(:'started-speaking', 'urn:xmpp:rayo:1')).to eq(described_class)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "from a stanza" do
|
11
|
+
let :stanza do
|
12
|
+
'<started-speaking xmlns="urn:xmpp:rayo:1" call-id="x0yz4ye-lx7-6ai9njwvw8nsb"/>'
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml parse_stanza(stanza).root, '9f00061', '1' }
|
16
|
+
|
17
|
+
it { is_expected.to be_instance_of described_class }
|
18
|
+
|
19
|
+
it_should_behave_like 'event'
|
20
|
+
|
21
|
+
describe '#call_id' do
|
22
|
+
subject { super().call_id }
|
23
|
+
it { is_expected.to eq("x0yz4ye-lx7-6ai9njwvw8nsb") }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "when setting options in initializer" do
|
28
|
+
subject do
|
29
|
+
described_class.new :call_id => 'abc123'
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#call_id' do
|
33
|
+
subject { super().call_id }
|
34
|
+
it { is_expected.to eq('abc123') }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Adhearsion::Event::StoppedSpeaking do
|
6
|
+
it 'registers itself' do
|
7
|
+
expect(Adhearsion::Rayo::RayoNode.class_from_registration(:'stopped-speaking', 'urn:xmpp:rayo:1')).to eq(described_class)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "from a stanza" do
|
11
|
+
let :stanza do
|
12
|
+
'<stopped-speaking xmlns="urn:xmpp:rayo:1" call-id="x0yz4ye-lx7-6ai9njwvw8nsb"/>'
|
13
|
+
end
|
14
|
+
|
15
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml parse_stanza(stanza).root, '9f00061', '1' }
|
16
|
+
|
17
|
+
it { is_expected.to be_instance_of described_class }
|
18
|
+
|
19
|
+
it_should_behave_like 'event'
|
20
|
+
|
21
|
+
describe '#call_id' do
|
22
|
+
subject { super().call_id }
|
23
|
+
it { is_expected.to eq("x0yz4ye-lx7-6ai9njwvw8nsb") }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "when setting options in initializer" do
|
28
|
+
subject do
|
29
|
+
described_class.new :call_id => 'abc123'
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#call_id' do
|
33
|
+
subject { super().call_id }
|
34
|
+
it { is_expected.to eq('abc123') }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Adhearsion::Event::Unjoined do
|
6
|
+
it 'registers itself' do
|
7
|
+
expect(Adhearsion::Rayo::RayoNode.class_from_registration(:unjoined, 'urn:xmpp:rayo:1')).to eq(described_class)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "from a stanza" do
|
11
|
+
let(:stanza) { '<unjoined xmlns="urn:xmpp:rayo:1" call-uri="b" mixer-name="m" />' }
|
12
|
+
|
13
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml parse_stanza(stanza).root, '9f00061', '1' }
|
14
|
+
|
15
|
+
it { is_expected.to be_instance_of described_class }
|
16
|
+
|
17
|
+
it_should_behave_like 'event'
|
18
|
+
|
19
|
+
describe '#call_uri' do
|
20
|
+
subject { super().call_uri }
|
21
|
+
it { is_expected.to eq('b') }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#call_id' do
|
25
|
+
subject { super().call_id }
|
26
|
+
it { is_expected.to eq('b') }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#mixer_name' do
|
30
|
+
subject { super().mixer_name }
|
31
|
+
it { is_expected.to eq('m') }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "when setting options in initializer" do
|
36
|
+
subject { described_class.new :call_uri => 'abc123', :mixer_name => 'blah' }
|
37
|
+
|
38
|
+
describe '#call_id' do
|
39
|
+
subject { super().call_id }
|
40
|
+
it { is_expected.to eq('abc123') }
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#mixer_name' do
|
44
|
+
subject { super().mixer_name }
|
45
|
+
it { is_expected.to eq('blah') }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
File without changes
|
@@ -12,67 +12,52 @@ module Adhearsion
|
|
12
12
|
Events.refresh!
|
13
13
|
end
|
14
14
|
|
15
|
-
it "should have a GirlFriday::Queue to handle events" do
|
16
|
-
expect(Events.queue).to be_a GirlFriday::WorkQueue
|
17
|
-
end
|
18
|
-
|
19
15
|
it "should allow adding events to the queue and handle them appropriately" do
|
20
|
-
|
21
|
-
o = nil
|
16
|
+
e = nil
|
22
17
|
latch = CountDownLatch.new 1
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
Events.register_handler :event do |event|
|
20
|
+
logger.info "Received an event!"
|
21
|
+
e = event
|
27
22
|
latch.countdown!
|
28
23
|
end
|
29
24
|
|
30
25
|
Events.trigger :event, :foo
|
31
26
|
|
32
27
|
expect(latch.wait(2)).to be_truthy
|
33
|
-
expect(
|
34
|
-
expect(o).to eq(:foo)
|
28
|
+
expect(e).to eq(:foo)
|
35
29
|
end
|
36
30
|
|
37
31
|
it "should allow executing events immediately" do
|
38
|
-
|
39
|
-
o = nil
|
32
|
+
e = nil
|
40
33
|
|
41
|
-
|
34
|
+
Events.register_handler :event do |event|
|
42
35
|
sleep 0.25
|
43
|
-
|
44
|
-
o = message.object
|
36
|
+
e = event
|
45
37
|
end
|
46
38
|
|
47
39
|
Events.trigger_immediately :event, :foo
|
48
40
|
|
49
|
-
expect(
|
50
|
-
expect(o).to eq(:foo)
|
41
|
+
expect(e).to eq(:foo)
|
51
42
|
end
|
52
43
|
|
53
|
-
it "should handle
|
54
|
-
|
44
|
+
it "should handle exceptions in event processing by raising the exception as an event" do
|
45
|
+
e = nil
|
46
|
+
latch = CountDownLatch.new 1
|
55
47
|
|
56
|
-
Events.register_handler :
|
57
|
-
|
48
|
+
Events.register_handler :exception do |event|
|
49
|
+
e = event
|
50
|
+
latch.countdown!
|
58
51
|
end
|
59
52
|
|
60
|
-
Events.trigger_immediately :event, EventClass.new
|
61
|
-
|
62
|
-
expect(result).to eq(:foo)
|
63
|
-
|
64
|
-
Events.clear_handlers :event, EventClass
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should handle exceptions in event processing by raising the exception as an event" do
|
68
|
-
expect(Events.instance).to receive(:trigger).with(:exception, kind_of(ExceptionClass)).once
|
69
|
-
|
70
53
|
Events.register_handler :event, EventClass do |event|
|
71
54
|
raise ExceptionClass
|
72
55
|
end
|
73
56
|
|
74
57
|
Events.trigger_immediately :event, EventClass.new
|
75
|
-
|
58
|
+
|
59
|
+
expect(latch.wait(2)).to be_truthy
|
60
|
+
expect(e).to be_a(ExceptionClass)
|
76
61
|
end
|
77
62
|
|
78
63
|
it "should implicitly pass on all handlers" do
|
@@ -89,16 +74,6 @@ module Adhearsion
|
|
89
74
|
Events.trigger_immediately :event, EventClass.new
|
90
75
|
|
91
76
|
expect(result).to eq(:bar)
|
92
|
-
|
93
|
-
Events.clear_handlers :event, EventClass
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should respond_to? any methods corresponding to classes for which handlers are defined" do
|
97
|
-
Events.register_handler :event_type_1 do |event|
|
98
|
-
end
|
99
|
-
|
100
|
-
expect(Events).to respond_to(:event_type_1)
|
101
|
-
expect(Events).not_to respond_to(:event_type_2)
|
102
77
|
end
|
103
78
|
|
104
79
|
describe '#draw' do
|
@@ -106,6 +81,7 @@ module Adhearsion
|
|
106
81
|
result = nil
|
107
82
|
Events.draw do
|
108
83
|
event do
|
84
|
+
logger.info "Got an event!"
|
109
85
|
result = :foo
|
110
86
|
end
|
111
87
|
end
|
@@ -113,8 +89,6 @@ module Adhearsion
|
|
113
89
|
Events.trigger_immediately :event
|
114
90
|
|
115
91
|
expect(result).to eq(:foo)
|
116
|
-
|
117
|
-
Events.clear_handlers :event
|
118
92
|
end
|
119
93
|
end
|
120
94
|
|
@@ -18,7 +18,7 @@ describe Adhearsion::Initializer do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
after do
|
21
|
-
Adhearsion::Events.
|
21
|
+
Adhearsion::Events.refresh!
|
22
22
|
end
|
23
23
|
|
24
24
|
after :all do
|
@@ -40,115 +40,24 @@ describe Adhearsion::Initializer do
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
it "should create a pid file in the app's path when given 'true' as the pid_file hash key argument" do
|
44
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
45
|
-
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
46
|
-
ahn = Adhearsion::Initializer.start :pid_file => true
|
47
|
-
expect(ahn.pid_file[0, path.length]).to eq(path)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should NOT create a pid file in the app's path when given 'false' as the pid_file hash key argument" do
|
52
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
53
|
-
ahn = Adhearsion::Initializer.start :pid_file => false
|
54
|
-
expect(ahn.pid_file).to be nil
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should create a pid file in the app's path by default when daemonizing" do
|
59
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
60
|
-
expect(Adhearsion::CustomDaemonizer).to receive(:daemonize).and_yield '123'
|
61
|
-
expect(File).to receive(:open).once.with(File.join(path, 'adhearsion.pid'), 'w')
|
62
|
-
ahn = Adhearsion::Initializer.start :mode => :daemon
|
63
|
-
expect(ahn.pid_file[0, path.size]).to eq(path)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should NOT create a pid file in the app's path when daemonizing and :pid_file is given as false" do
|
68
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
69
|
-
expect(Adhearsion::CustomDaemonizer).to receive(:daemonize).and_yield '123'
|
70
|
-
ahn = Adhearsion::Initializer.start :mode => :daemon, :pid_file => false
|
71
|
-
expect(ahn.pid_file).to be nil
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should create a designated pid file when supplied a String path as :pid_file" do
|
76
|
-
random_file = "/tmp/AHN_TEST_#{rand 100000}.pid"
|
77
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
78
|
-
ahn = Adhearsion::Initializer.start :pid_file => random_file
|
79
|
-
expect(ahn.pid_file).to eq(random_file)
|
80
|
-
expect(File.exists?(random_file)).to be true
|
81
|
-
File.delete random_file
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should resolve the log file path to daemonize" do
|
86
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
87
|
-
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
88
|
-
ahn = Adhearsion::Initializer.start :pid_file => true
|
89
|
-
expect(ahn.resolve_log_file_path).to eq(path + Adhearsion.config.platform.logging.outputters[0])
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should resolve the log file path to daemonize when outputters is an Array" do
|
94
|
-
Adhearsion.config.platform.logging.outputters = ["log/my_application.log", "log/adhearsion.log"]
|
95
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
96
|
-
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
97
|
-
ahn = Adhearsion::Initializer.start :pid_file => true
|
98
|
-
expect(ahn.resolve_log_file_path).to eq(path + Adhearsion.config.platform.logging.outputters[0])
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should return a valid appenders array" do
|
103
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
104
|
-
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
105
|
-
ahn = Adhearsion::Initializer.start :pid_file => true
|
106
|
-
appenders = ahn.init_get_logging_appenders
|
107
|
-
expect(appenders.size).to eq(2)
|
108
|
-
expect(appenders[1]).to be_instance_of Logging::Appenders::Stdout
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should initialize properly the log paths" do
|
113
|
-
ahn = stub_behavior_for_initializer_with_no_path_changing_behavior do
|
114
|
-
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
115
|
-
Adhearsion::Initializer.start :pid_file => true
|
116
|
-
end
|
117
|
-
expect(Dir).to receive(:mkdir).with("log/")
|
118
|
-
ahn.initialize_log_paths
|
119
|
-
end
|
120
|
-
|
121
|
-
it "should initialize properly the log paths when outputters is an array" do
|
122
|
-
Adhearsion.config.platform.logging.outputters = ["log/my_application.log", "log/test/adhearsion.log"]
|
123
|
-
ahn = stub_behavior_for_initializer_with_no_path_changing_behavior do
|
124
|
-
expect(File).to receive(:open).with(File.join(path, 'adhearsion.pid'), 'w').at_least(:once)
|
125
|
-
Adhearsion::Initializer.start :pid_file => true
|
126
|
-
end
|
127
|
-
expect(Dir).to receive(:mkdir).with("log/").twice
|
128
|
-
expect(Dir).to receive(:mkdir).with("log/test/").once
|
129
|
-
ahn.initialize_log_paths
|
130
|
-
end
|
131
|
-
|
132
43
|
it "should set the adhearsion proc name" do
|
133
44
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
134
|
-
expect(
|
135
|
-
|
136
|
-
Adhearsion::Initializer.start :pid_file => true
|
45
|
+
expect(Adhearsion::LinuxProcName).to receive(:set_proc_name).with(Adhearsion.config.core.process_name)
|
46
|
+
Adhearsion::Initializer.start
|
137
47
|
end
|
138
48
|
end
|
139
49
|
|
140
50
|
it "should update the adhearsion proc name" do
|
141
51
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
142
|
-
Adhearsion::Initializer.start
|
52
|
+
Adhearsion::Initializer.start
|
143
53
|
end
|
144
|
-
expect($0).to eq(Adhearsion.config.
|
54
|
+
expect($0).to eq(Adhearsion.config.core.process_name)
|
145
55
|
end
|
146
56
|
end
|
147
57
|
|
148
58
|
describe "Initializing logger" do
|
149
59
|
before do
|
150
60
|
::Logging.reset
|
151
|
-
expect(::Logging::Appenders).to receive(:file).and_return(nil)
|
152
61
|
Adhearsion.config = nil
|
153
62
|
end
|
154
63
|
|
@@ -156,21 +65,20 @@ describe Adhearsion::Initializer do
|
|
156
65
|
::Logging.reset
|
157
66
|
Adhearsion::Logging.start
|
158
67
|
Adhearsion::Logging.silence!
|
159
|
-
Adhearsion::Events.
|
68
|
+
Adhearsion::Events.refresh!
|
160
69
|
end
|
161
70
|
|
162
71
|
it "should start logging with valid parameters" do
|
163
72
|
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
164
|
-
expect(
|
165
|
-
|
166
|
-
Adhearsion::Initializer.start :pid_file => true
|
73
|
+
expect(Adhearsion::Logging).to receive(:start).once.with(:info, nil).and_return('')
|
74
|
+
Adhearsion::Initializer.start
|
167
75
|
end
|
168
76
|
end
|
169
77
|
end
|
170
78
|
|
171
79
|
describe "#load_lib_folder" do
|
172
80
|
before do
|
173
|
-
Adhearsion.
|
81
|
+
Adhearsion.root = path
|
174
82
|
end
|
175
83
|
|
176
84
|
it "should load the contents of lib directory" do
|
@@ -179,100 +87,20 @@ describe Adhearsion::Initializer do
|
|
179
87
|
end
|
180
88
|
|
181
89
|
it "should return false if folder does not exist" do
|
182
|
-
Adhearsion.config.
|
90
|
+
Adhearsion.config.core.lib = "my_random_lib_directory"
|
183
91
|
expect(Adhearsion::Initializer.new.load_lib_folder).to eq(false)
|
184
92
|
end
|
185
93
|
|
186
94
|
it "should return false and not load any file if config folder is set to nil" do
|
187
|
-
Adhearsion.config.
|
95
|
+
Adhearsion.config.core.lib = nil
|
188
96
|
expect(Adhearsion::Initializer.new.load_lib_folder).to eq(false)
|
189
97
|
end
|
190
98
|
|
191
99
|
it "should load the contents of the preconfigured directory" do
|
192
|
-
Adhearsion.config.
|
100
|
+
Adhearsion.config.core.lib = "foo"
|
193
101
|
allow(File).to receive_messages directory?: true
|
194
102
|
expect(Dir).to receive(:chdir).with(File.join(path, "foo")).and_return []
|
195
103
|
Adhearsion::Initializer.new.load_lib_folder
|
196
104
|
end
|
197
105
|
end
|
198
106
|
end
|
199
|
-
|
200
|
-
describe "Updating RAILS_ENV variable" do
|
201
|
-
include InitializerStubs
|
202
|
-
|
203
|
-
before do
|
204
|
-
::Logging.reset
|
205
|
-
expect(Adhearsion::Logging).to receive(:start).once.and_return('')
|
206
|
-
expect(::Logging::Appenders).to receive(:file).and_return(nil)
|
207
|
-
Adhearsion.config = nil
|
208
|
-
end
|
209
|
-
|
210
|
-
before do
|
211
|
-
ENV['RAILS_ENV'] = nil
|
212
|
-
ENV['AHN_ENV'] = nil
|
213
|
-
end
|
214
|
-
|
215
|
-
after :all do
|
216
|
-
ENV['RAILS_ENV'] = nil
|
217
|
-
ENV['AHN_ENV'] = nil
|
218
|
-
end
|
219
|
-
|
220
|
-
describe "when neither RAILS_ENV nor AHN_ENV are set" do
|
221
|
-
[:development, :production, :staging, :test].each do |env|
|
222
|
-
it "should set the RAILS_ENV to #{env.to_s} when Adhearsion environment is set to #{env.to_s}" do
|
223
|
-
ahn = nil
|
224
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
225
|
-
Adhearsion.config.platform.environment = env
|
226
|
-
ahn = Adhearsion::Initializer.start
|
227
|
-
end
|
228
|
-
ahn.update_rails_env_var
|
229
|
-
expect(ENV['RAILS_ENV']).to eq(env.to_s)
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
context "when RAILS_ENV is set" do
|
235
|
-
before do
|
236
|
-
ENV['RAILS_ENV'] = "test"
|
237
|
-
end
|
238
|
-
|
239
|
-
context "if AHN_ENV is set" do
|
240
|
-
it "should preserve the RAILS_ENV value" do
|
241
|
-
ENV['AHN_ENV'] = "production"
|
242
|
-
ahn = nil
|
243
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
244
|
-
ahn = Adhearsion::Initializer.start
|
245
|
-
end
|
246
|
-
ahn.update_rails_env_var
|
247
|
-
expect(ENV['RAILS_ENV']).to eq("test")
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
context "if AHN_ENV is unset" do
|
252
|
-
it "should preserve the RAILS_ENV value" do
|
253
|
-
ahn = nil
|
254
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
255
|
-
ahn = Adhearsion::Initializer.start
|
256
|
-
end
|
257
|
-
ahn.update_rails_env_var
|
258
|
-
expect(ENV['RAILS_ENV']).to eq("test")
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
context "when RAILS_ENV is unset and AHN_ENV is set" do
|
264
|
-
before do
|
265
|
-
ENV['AHN_ENV'] = "production"
|
266
|
-
end
|
267
|
-
|
268
|
-
it "should define the RAILS_ENV value with the AHN_ENV value" do
|
269
|
-
ahn = nil
|
270
|
-
stub_behavior_for_initializer_with_no_path_changing_behavior do
|
271
|
-
ahn = Adhearsion::Initializer.start
|
272
|
-
end
|
273
|
-
ahn.update_rails_env_var
|
274
|
-
expect(ENV['RAILS_ENV']).to eq("production")
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
end
|