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,111 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Adhearsion::Rayo::Component::Asterisk::AGI::Command do
|
6
|
+
it 'registers itself' do
|
7
|
+
expect(Adhearsion::Rayo::RayoNode.class_from_registration(:command, 'urn:xmpp:rayo:asterisk:agi:1')).to eq(described_class)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "from a stanza" do
|
11
|
+
let :stanza do
|
12
|
+
<<-MESSAGE
|
13
|
+
<command xmlns="urn:xmpp:rayo:asterisk:agi:1" name="GET VARIABLE">
|
14
|
+
<param value="UNIQUEID"/>
|
15
|
+
</command>
|
16
|
+
MESSAGE
|
17
|
+
end
|
18
|
+
|
19
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml parse_stanza(stanza).root, '9f00061', '1' }
|
20
|
+
|
21
|
+
it { is_expected.to be_instance_of described_class }
|
22
|
+
|
23
|
+
it_should_behave_like 'event'
|
24
|
+
|
25
|
+
describe '#name' do
|
26
|
+
subject { super().name }
|
27
|
+
it { is_expected.to eq('GET VARIABLE') }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#params' do
|
31
|
+
subject { super().params }
|
32
|
+
it { is_expected.to eq(['UNIQUEID']) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "when setting options in initializer" do
|
37
|
+
subject do
|
38
|
+
described_class.new name: 'GET VARIABLE',
|
39
|
+
params: ['UNIQUEID']
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#name' do
|
43
|
+
subject { super().name }
|
44
|
+
it { is_expected.to eq('GET VARIABLE') }
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#params' do
|
48
|
+
subject { super().params }
|
49
|
+
it { is_expected.to eq(['UNIQUEID']) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe described_class::Complete::Success do
|
54
|
+
let :stanza do
|
55
|
+
<<-MESSAGE
|
56
|
+
<complete xmlns="urn:xmpp:rayo:ext:1">
|
57
|
+
<success xmlns="urn:xmpp:rayo:asterisk:agi:complete:1">
|
58
|
+
<code>200</code>
|
59
|
+
<result>0</result>
|
60
|
+
<data>1187188485.0</data>
|
61
|
+
</success>
|
62
|
+
</complete>
|
63
|
+
MESSAGE
|
64
|
+
end
|
65
|
+
|
66
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml(parse_stanza(stanza).root).reason }
|
67
|
+
|
68
|
+
it { is_expected.to be_instance_of described_class }
|
69
|
+
|
70
|
+
describe '#name' do
|
71
|
+
subject { super().name }
|
72
|
+
it { is_expected.to eq(:success) }
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#code' do
|
76
|
+
subject { super().code }
|
77
|
+
it { is_expected.to eq(200) }
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#result' do
|
81
|
+
subject { super().result }
|
82
|
+
it { is_expected.to eq(0) }
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#data' do
|
86
|
+
subject { super().data }
|
87
|
+
it { is_expected.to eq('1187188485.0') }
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "when setting options in initializer" do
|
91
|
+
subject do
|
92
|
+
described_class.new code: 200, result: 0, data: '1187188485.0'
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#code' do
|
96
|
+
subject { super().code }
|
97
|
+
it { is_expected.to eq(200) }
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#result' do
|
101
|
+
subject { super().result }
|
102
|
+
it { is_expected.to eq(0) }
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#data' do
|
106
|
+
subject { super().data }
|
107
|
+
it { is_expected.to eq('1187188485.0') }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Adhearsion::Rayo::Component::Asterisk::AMI::Action do
|
6
|
+
it 'registers itself' do
|
7
|
+
expect(Adhearsion::Rayo::RayoNode.class_from_registration(:action, 'urn:xmpp:rayo:asterisk:ami:1')).to eq(described_class)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "from a stanza" do
|
11
|
+
let :stanza do
|
12
|
+
<<-MESSAGE
|
13
|
+
<action xmlns="urn:xmpp:rayo:asterisk:ami:1" name="Originate">
|
14
|
+
<param name="Channel" value="SIP/101test"/>
|
15
|
+
<param name="Context" value="default"/>
|
16
|
+
<param name="Exten" value="8135551212"/>
|
17
|
+
<param name="Priority" value="1"/>
|
18
|
+
<param name="Callerid" value="3125551212"/>
|
19
|
+
<param name="Timeout" value="30000"/>
|
20
|
+
<param name="Variable" value="var1=23|var2=24|var3=25"/>
|
21
|
+
<param name="Async" value="1"/>
|
22
|
+
</action>
|
23
|
+
MESSAGE
|
24
|
+
end
|
25
|
+
|
26
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml parse_stanza(stanza).root, '9f00061', '1' }
|
27
|
+
|
28
|
+
it { is_expected.to be_instance_of described_class }
|
29
|
+
|
30
|
+
it_should_behave_like 'event'
|
31
|
+
|
32
|
+
describe '#name' do
|
33
|
+
subject { super().name }
|
34
|
+
it { is_expected.to eq('Originate') }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#params' do
|
38
|
+
subject { super().params }
|
39
|
+
it { is_expected.to eq({ 'Channel' => 'SIP/101test',
|
40
|
+
'Context' => 'default',
|
41
|
+
'Exten' => '8135551212',
|
42
|
+
'Priority' => '1',
|
43
|
+
'Callerid' => '3125551212',
|
44
|
+
'Timeout' => '30000',
|
45
|
+
'Variable' => 'var1=23|var2=24|var3=25',
|
46
|
+
'Async' => '1'}) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "testing equality" do
|
51
|
+
context "with the same name and params" do
|
52
|
+
it "should be equal" do
|
53
|
+
expect(described_class.new(:name => 'Originate', :params => { :channel => 'SIP/101test' })).to eq(described_class.new(:name => 'Originate', :params => { :channel => 'SIP/101test' }))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with the same name and different params" do
|
58
|
+
it "should be equal" do
|
59
|
+
expect(described_class.new(:name => 'Originate', :params => { :channel => 'SIP/101' })).not_to eq(described_class.new(:name => 'Originate', :params => { :channel => 'SIP/101test' }))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "with a different name and the same params" do
|
64
|
+
it "should be equal" do
|
65
|
+
expect(described_class.new(:name => 'Hangup', :params => { :channel => 'SIP/101test' })).not_to eq(described_class.new(:name => 'Originate', :params => { :channel => 'SIP/101test' }))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "when setting options in initializer" do
|
71
|
+
subject do
|
72
|
+
described_class.new :name => 'Originate',
|
73
|
+
:params => { 'Channel' => 'SIP/101test' }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#name' do
|
77
|
+
subject { super().name }
|
78
|
+
it { is_expected.to eq('Originate') }
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#params' do
|
82
|
+
subject { super().params }
|
83
|
+
it { is_expected.to eq({ 'Channel' => 'SIP/101test' }) }
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "exporting to Rayo" do
|
87
|
+
it "should export to XML that can be understood by its parser" do
|
88
|
+
new_instance = Adhearsion::Rayo::RayoNode.from_xml subject.to_rayo
|
89
|
+
expect(new_instance).to be_instance_of described_class
|
90
|
+
expect(new_instance.name).to eq('Originate')
|
91
|
+
expect(new_instance.params).to eq({ 'Channel' => 'SIP/101test' })
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should render to a parent node if supplied" do
|
95
|
+
doc = Nokogiri::XML::Document.new
|
96
|
+
parent = Nokogiri::XML::Node.new 'foo', doc
|
97
|
+
doc.root = parent
|
98
|
+
rayo_doc = subject.to_rayo(parent)
|
99
|
+
expect(rayo_doc).to eq(parent)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe described_class::Complete::Success do
|
105
|
+
let :stanza do
|
106
|
+
<<-MESSAGE
|
107
|
+
<complete xmlns="urn:xmpp:rayo:ext:1">
|
108
|
+
<success xmlns="urn:xmpp:rayo:asterisk:ami:complete:1">
|
109
|
+
<message>Originate successfully queued</message>
|
110
|
+
<text-body>Some thing happened</text-body>
|
111
|
+
<attribute name="Channel" value="SIP/101-3f3f"/>
|
112
|
+
<attribute name="State" value="Ring"/>
|
113
|
+
</success>
|
114
|
+
</complete>
|
115
|
+
MESSAGE
|
116
|
+
end
|
117
|
+
|
118
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml(parse_stanza(stanza).root).reason }
|
119
|
+
|
120
|
+
it { is_expected.to be_instance_of described_class }
|
121
|
+
|
122
|
+
describe '#name' do
|
123
|
+
subject { super().name }
|
124
|
+
it { is_expected.to eq(:success) }
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#message' do
|
128
|
+
subject { super().message }
|
129
|
+
it { is_expected.to eq("Originate successfully queued") }
|
130
|
+
end
|
131
|
+
|
132
|
+
describe '#text_body' do
|
133
|
+
subject { super().text_body }
|
134
|
+
it { is_expected.to eq('Some thing happened') }
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#headers' do
|
138
|
+
subject { super().headers }
|
139
|
+
it { is_expected.to eq({'Channel' => 'SIP/101-3f3f', 'State' => 'Ring'}) }
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '#attributes' do
|
143
|
+
subject { super().attributes }
|
144
|
+
it { is_expected.to eq({'Channel' => 'SIP/101-3f3f', 'State' => 'Ring'}) }
|
145
|
+
end # For BC
|
146
|
+
|
147
|
+
describe "when setting options in initializer" do
|
148
|
+
subject do
|
149
|
+
described_class.new message: 'Originate successfully queued', text_body: 'Some thing happened', headers: {'Channel' => 'SIP/101-3f3f', 'State' => 'Ring'}
|
150
|
+
end
|
151
|
+
|
152
|
+
describe '#message' do
|
153
|
+
subject { super().message }
|
154
|
+
it { is_expected.to eq('Originate successfully queued') }
|
155
|
+
end
|
156
|
+
|
157
|
+
describe '#text_body' do
|
158
|
+
subject { super().text_body }
|
159
|
+
it { is_expected.to eq('Some thing happened') }
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '#headers' do
|
163
|
+
subject { super().headers }
|
164
|
+
it { is_expected.to eq({'Channel' => 'SIP/101-3f3f', 'State' => 'Ring'}) }
|
165
|
+
end
|
166
|
+
|
167
|
+
describe '#attributes' do
|
168
|
+
subject { super().attributes }
|
169
|
+
it { is_expected.to eq({'Channel' => 'SIP/101-3f3f', 'State' => 'Ring'}) }
|
170
|
+
end # For BC
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Adhearsion::Rayo::Component::ComponentNode do
|
6
|
+
subject do
|
7
|
+
Class.new(described_class) { register 'foo'}.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it { is_expected.to be_new }
|
11
|
+
|
12
|
+
describe "#add_event" do
|
13
|
+
let(:event) { Adhearsion::Event::Complete.new }
|
14
|
+
|
15
|
+
before do
|
16
|
+
subject.request!
|
17
|
+
subject.execute!
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:add_event) { subject.add_event event }
|
21
|
+
|
22
|
+
describe "with a complete event" do
|
23
|
+
it "should set the complete event resource" do
|
24
|
+
add_event
|
25
|
+
expect(subject.complete_event(0.5)).to eq(event)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should call #complete!" do
|
29
|
+
expect(subject).to receive(:complete!).once
|
30
|
+
add_event
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "with another event" do
|
35
|
+
let(:event) { Adhearsion::Event::Answered.new }
|
36
|
+
|
37
|
+
it "should not set the complete event resource" do
|
38
|
+
add_event
|
39
|
+
expect(subject).not_to be_complete
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end # #add_event
|
43
|
+
|
44
|
+
describe "#trigger_event_handler" do
|
45
|
+
let(:event) { Adhearsion::Event::Complete.new }
|
46
|
+
|
47
|
+
before do
|
48
|
+
subject.request!
|
49
|
+
subject.execute!
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "with an event handler set" do
|
53
|
+
let(:handler) { double 'Response' }
|
54
|
+
|
55
|
+
before do
|
56
|
+
expect(handler).to receive(:call).once.with(event)
|
57
|
+
subject.register_event_handler { |event| handler.call event }
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should trigger the callback" do
|
61
|
+
subject.trigger_event_handler event
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end # #trigger_event_handler
|
65
|
+
|
66
|
+
describe "#response=" do
|
67
|
+
before do
|
68
|
+
subject.request!
|
69
|
+
subject.client = Adhearsion::Rayo::Client.new
|
70
|
+
end
|
71
|
+
|
72
|
+
let(:uri) { 'xmpp:callid@server/abc123' }
|
73
|
+
|
74
|
+
let :ref do
|
75
|
+
Adhearsion::Rayo::Ref.new uri: uri
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should set the component ID from the ref" do
|
79
|
+
subject.response = ref
|
80
|
+
expect(subject.component_id).to eq('abc123')
|
81
|
+
expect(subject.source_uri).to eq(uri)
|
82
|
+
expect(subject.client.find_component_by_uri(uri)).to be subject
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "#complete_event=" do
|
87
|
+
before do
|
88
|
+
subject.request!
|
89
|
+
subject.client = Adhearsion::Rayo::Client.new
|
90
|
+
subject.response = Adhearsion::Rayo::Ref.new uri: 'abc'
|
91
|
+
expect(subject.client.find_component_by_uri('abc')).to be subject
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should set the command to executing status" do
|
95
|
+
subject.complete_event = :foo
|
96
|
+
expect(subject).to be_complete
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should be a no-op if the response has already been set" do
|
100
|
+
subject.complete_event = :foo
|
101
|
+
expect { subject.complete_event = :bar }.not_to raise_error
|
102
|
+
expect(subject.complete_event(0.5)).to eq(:foo)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should remove the component from the registry" do
|
106
|
+
subject.complete_event = :foo
|
107
|
+
expect(subject.client.find_component_by_uri('abc')).to be_nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,715 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Adhearsion::Rayo::Component::Input do
|
6
|
+
it 'registers itself' do
|
7
|
+
expect(Adhearsion::Rayo::RayoNode.class_from_registration(:input, 'urn:xmpp:rayo:input:1')).to eq(described_class)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "when setting options in initializer" do
|
11
|
+
subject do
|
12
|
+
described_class.new grammar: {value: '[5 DIGITS]', content_type: 'application/grammar+custom'},
|
13
|
+
:mode => :voice,
|
14
|
+
:terminator => '#',
|
15
|
+
:max_silence => 1000,
|
16
|
+
:recognizer => 'default',
|
17
|
+
:language => 'en-US',
|
18
|
+
:initial_timeout => 2000,
|
19
|
+
:inter_digit_timeout => 2000,
|
20
|
+
:recognition_timeout => 0,
|
21
|
+
:sensitivity => 0.5,
|
22
|
+
:min_confidence => 0.5,
|
23
|
+
:headers => { 'Confidence-Threshold' => '0.5', 'Sensitivity-Level' => '0.2' }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#grammars' do
|
27
|
+
subject { super().grammars }
|
28
|
+
it { is_expected.to eq([described_class::Grammar.new(:value => '[5 DIGITS]', :content_type => 'application/grammar+custom')]) }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#mode' do
|
32
|
+
subject { super().mode }
|
33
|
+
it { is_expected.to eq(:voice) }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#terminator' do
|
37
|
+
subject { super().terminator }
|
38
|
+
it { is_expected.to eq('#') }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#max_silence' do
|
42
|
+
subject { super().max_silence }
|
43
|
+
it { is_expected.to eq(1000) }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#recognizer' do
|
47
|
+
subject { super().recognizer }
|
48
|
+
it { is_expected.to eq('default') }
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#language' do
|
52
|
+
subject { super().language }
|
53
|
+
it { is_expected.to eq('en-US') }
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#initial_timeout' do
|
57
|
+
subject { super().initial_timeout }
|
58
|
+
it { is_expected.to eq(2000) }
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#inter_digit_timeout' do
|
62
|
+
subject { super().inter_digit_timeout }
|
63
|
+
it { is_expected.to eq(2000) }
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#recognition_timeout' do
|
67
|
+
subject { super().recognition_timeout }
|
68
|
+
it { is_expected.to eq(0) }
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#sensitivity' do
|
72
|
+
subject { super().sensitivity }
|
73
|
+
it { is_expected.to eq(0.5) }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#min_confidence' do
|
77
|
+
subject { super().min_confidence }
|
78
|
+
it { is_expected.to eq(0.5) }
|
79
|
+
end
|
80
|
+
|
81
|
+
context "with multiple grammars" do
|
82
|
+
subject do
|
83
|
+
described_class.new :grammars => [
|
84
|
+
{:value => '[5 DIGITS]', :content_type => 'application/grammar+custom'},
|
85
|
+
{:value => '[10 DIGITS]', :content_type => 'application/grammar+custom'}
|
86
|
+
]
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#grammars' do
|
90
|
+
subject { super().grammars }
|
91
|
+
it { is_expected.to eq([
|
92
|
+
described_class::Grammar.new(:value => '[5 DIGITS]', :content_type => 'application/grammar+custom'),
|
93
|
+
described_class::Grammar.new(:value => '[10 DIGITS]', :content_type => 'application/grammar+custom')
|
94
|
+
])}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "with a nil grammar" do
|
99
|
+
it "removes all grammars" do
|
100
|
+
subject.grammar = nil
|
101
|
+
expect(subject.grammars).to eq([])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context "without any grammars" do
|
106
|
+
subject { described_class.new }
|
107
|
+
|
108
|
+
describe '#grammars' do
|
109
|
+
subject { super().grammars }
|
110
|
+
it { is_expected.to eq([]) }
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#headers' do
|
115
|
+
subject { super().headers }
|
116
|
+
it { is_expected.to eq({ 'Confidence-Threshold' => '0.5', 'Sensitivity-Level' => '0.2' }) }
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "exporting to Rayo" do
|
120
|
+
it "should export to XML that can be understood by its parser" do
|
121
|
+
new_instance = Adhearsion::Rayo::RayoNode.from_xml subject.to_rayo
|
122
|
+
expect(new_instance).to be_instance_of described_class
|
123
|
+
expect(new_instance.grammars).to eq([described_class::Grammar.new(value: '[5 DIGITS]', content_type: 'application/grammar+custom')])
|
124
|
+
expect(new_instance.mode).to eq(:voice)
|
125
|
+
expect(new_instance.terminator).to eq('#')
|
126
|
+
expect(new_instance.max_silence).to eq(1000)
|
127
|
+
expect(new_instance.recognizer).to eq('default')
|
128
|
+
expect(new_instance.language).to eq('en-US')
|
129
|
+
expect(new_instance.initial_timeout).to eq(2000)
|
130
|
+
expect(new_instance.inter_digit_timeout).to eq(2000)
|
131
|
+
expect(new_instance.recognition_timeout).to eq(0)
|
132
|
+
expect(new_instance.sensitivity).to eq(0.5)
|
133
|
+
expect(new_instance.min_confidence).to eq(0.5)
|
134
|
+
expect(new_instance.headers).to eq({ 'Confidence-Threshold' => '0.5', 'Sensitivity-Level' => '0.2' })
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should wrap the grammar value in CDATA" do
|
138
|
+
grammar_node = subject.to_rayo.at_xpath('ns:grammar', ns: described_class.registered_ns)
|
139
|
+
expect(grammar_node.children.first).to be_a Nokogiri::XML::CDATA
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should render to a parent node if supplied" do
|
143
|
+
doc = Nokogiri::XML::Document.new
|
144
|
+
parent = Nokogiri::XML::Node.new 'foo', doc
|
145
|
+
doc.root = parent
|
146
|
+
rayo_doc = subject.to_rayo(parent)
|
147
|
+
expect(rayo_doc).to eq(parent)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "from a stanza" do
|
153
|
+
let :stanza do
|
154
|
+
<<-MESSAGE
|
155
|
+
<input xmlns="urn:xmpp:rayo:input:1"
|
156
|
+
mode="voice"
|
157
|
+
terminator="#"
|
158
|
+
max-silence="1000"
|
159
|
+
recognizer="default"
|
160
|
+
language="en-US"
|
161
|
+
initial-timeout="2000"
|
162
|
+
inter-digit-timeout="2000"
|
163
|
+
recognition-timeout="0"
|
164
|
+
sensitivity="0.5"
|
165
|
+
min-confidence="0.5">
|
166
|
+
<grammar content-type="application/grammar+custom">
|
167
|
+
<![CDATA[ [5 DIGITS] ]]>
|
168
|
+
</grammar>
|
169
|
+
<grammar content-type="application/grammar+custom">
|
170
|
+
<![CDATA[ [10 DIGITS] ]]>
|
171
|
+
</grammar>
|
172
|
+
<header xmlns='urn:xmpp:rayo:1' name="Confidence-Threshold" value="0.5" />
|
173
|
+
<header xmlns='urn:xmpp:rayo:1' name="Sensitivity-Level" value="0.2" />
|
174
|
+
</input>
|
175
|
+
MESSAGE
|
176
|
+
end
|
177
|
+
|
178
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml parse_stanza(stanza).root, '9f00061', '1' }
|
179
|
+
|
180
|
+
it { is_expected.to be_instance_of described_class }
|
181
|
+
|
182
|
+
describe '#grammars' do
|
183
|
+
subject { super().grammars }
|
184
|
+
it { is_expected.to eq([described_class::Grammar.new(:value => '[5 DIGITS]', :content_type => 'application/grammar+custom'), described_class::Grammar.new(:value => '[10 DIGITS]', :content_type => 'application/grammar+custom')]) }
|
185
|
+
end
|
186
|
+
|
187
|
+
describe '#mode' do
|
188
|
+
subject { super().mode }
|
189
|
+
it { is_expected.to eq(:voice) }
|
190
|
+
end
|
191
|
+
|
192
|
+
describe '#terminator' do
|
193
|
+
subject { super().terminator }
|
194
|
+
it { is_expected.to eq('#') }
|
195
|
+
end
|
196
|
+
|
197
|
+
describe '#max_silence' do
|
198
|
+
subject { super().max_silence }
|
199
|
+
it { is_expected.to eq(1000) }
|
200
|
+
end
|
201
|
+
|
202
|
+
describe '#recognizer' do
|
203
|
+
subject { super().recognizer }
|
204
|
+
it { is_expected.to eq('default') }
|
205
|
+
end
|
206
|
+
|
207
|
+
describe '#language' do
|
208
|
+
subject { super().language }
|
209
|
+
it { is_expected.to eq('en-US') }
|
210
|
+
end
|
211
|
+
|
212
|
+
describe '#initial_timeout' do
|
213
|
+
subject { super().initial_timeout }
|
214
|
+
it { is_expected.to eq(2000) }
|
215
|
+
end
|
216
|
+
|
217
|
+
describe '#inter_digit_timeout' do
|
218
|
+
subject { super().inter_digit_timeout }
|
219
|
+
it { is_expected.to eq(2000) }
|
220
|
+
end
|
221
|
+
|
222
|
+
describe '#recognition_timeout' do
|
223
|
+
subject { super().recognition_timeout }
|
224
|
+
it { is_expected.to eq(0) }
|
225
|
+
end
|
226
|
+
|
227
|
+
describe '#sensitivity' do
|
228
|
+
subject { super().sensitivity }
|
229
|
+
it { is_expected.to eq(0.5) }
|
230
|
+
end
|
231
|
+
|
232
|
+
describe '#min_confidence' do
|
233
|
+
subject { super().min_confidence }
|
234
|
+
it { is_expected.to eq(0.5) }
|
235
|
+
end
|
236
|
+
|
237
|
+
context "without any grammars" do
|
238
|
+
let(:stanza) { '<input xmlns="urn:xmpp:rayo:input:1"/>' }
|
239
|
+
|
240
|
+
describe '#grammars' do
|
241
|
+
subject { super().grammars }
|
242
|
+
it { is_expected.to eq([]) }
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe '#headers' do
|
247
|
+
subject { super().headers }
|
248
|
+
it { is_expected.to eq({ 'Confidence-Threshold' => '0.5', 'Sensitivity-Level' => '0.2' }) }
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
def grxml_doc(mode = :dtmf)
|
253
|
+
RubySpeech::GRXML.draw :mode => mode.to_s, :root => 'digits' do
|
254
|
+
rule id: 'digits' do
|
255
|
+
one_of do
|
256
|
+
0.upto(1) { |d| item { d.to_s } }
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
describe described_class::Grammar do
|
263
|
+
describe "when not passing a content type" do
|
264
|
+
subject { described_class.new :value => grxml_doc }
|
265
|
+
|
266
|
+
describe '#content_type' do
|
267
|
+
subject { super().content_type }
|
268
|
+
it { is_expected.to eq('application/srgs+xml') }
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
describe 'with a GRXML grammar' do
|
273
|
+
subject { described_class.new :value => grxml_doc, :content_type => 'application/srgs+xml' }
|
274
|
+
|
275
|
+
describe '#content_type' do
|
276
|
+
subject { super().content_type }
|
277
|
+
it { is_expected.to eq('application/srgs+xml') }
|
278
|
+
end
|
279
|
+
|
280
|
+
describe '#value' do
|
281
|
+
subject { super().value }
|
282
|
+
it { is_expected.to eq(grxml_doc) }
|
283
|
+
end
|
284
|
+
|
285
|
+
describe "comparison" do
|
286
|
+
let(:grammar2) { described_class.new :value => grxml_doc }
|
287
|
+
let(:grammar3) { described_class.new :value => grxml_doc(:voice) }
|
288
|
+
|
289
|
+
it { is_expected.to eq(grammar2) }
|
290
|
+
it { is_expected.not_to eq(grammar3) }
|
291
|
+
end
|
292
|
+
|
293
|
+
it "has children nested inside" do
|
294
|
+
expect(subject.to_rayo.children.first).to be_a Nokogiri::XML::CDATA
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
describe 'with a grammar reference by URL' do
|
299
|
+
let(:url) { 'http://foo.com/bar.grxml' }
|
300
|
+
|
301
|
+
subject { described_class.new :url => url }
|
302
|
+
|
303
|
+
describe '#url' do
|
304
|
+
subject { super().url }
|
305
|
+
it { is_expected.to eq(url) }
|
306
|
+
end
|
307
|
+
|
308
|
+
describe '#content_type' do
|
309
|
+
subject { super().content_type }
|
310
|
+
it { is_expected.to be nil}
|
311
|
+
end
|
312
|
+
|
313
|
+
describe "comparison" do
|
314
|
+
it "should be the same with the same url" do
|
315
|
+
expect(described_class.new(:url => url)).to eq(described_class.new(:url => url))
|
316
|
+
end
|
317
|
+
|
318
|
+
it "should be different with a different url" do
|
319
|
+
expect(described_class.new(:url => url)).not_to eq(described_class.new(:url => 'http://doo.com/dah'))
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
describe "with a CPA grammar" do
|
325
|
+
subject { described_class.new url: "urn:xmpp:rayo:cpa:beep:1" }
|
326
|
+
|
327
|
+
it "has no children" do
|
328
|
+
expect(subject.to_rayo.children.count).to eq(0)
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
describe "actions" do
|
334
|
+
let(:mock_client) { double 'Client' }
|
335
|
+
let(:command) { described_class.new grammar: {value: '[5 DIGITS]', content_type: 'application/grammar+custom'} }
|
336
|
+
|
337
|
+
before do
|
338
|
+
command.component_id = 'abc123'
|
339
|
+
command.target_call_id = '123abc'
|
340
|
+
command.client = mock_client
|
341
|
+
end
|
342
|
+
|
343
|
+
describe '#stop_action' do
|
344
|
+
subject { command.stop_action }
|
345
|
+
|
346
|
+
describe '#to_xml' do
|
347
|
+
subject { super().to_xml }
|
348
|
+
it { is_expected.to eq('<stop xmlns="urn:xmpp:rayo:ext:1"/>') }
|
349
|
+
end
|
350
|
+
|
351
|
+
describe '#component_id' do
|
352
|
+
subject { super().component_id }
|
353
|
+
it { is_expected.to eq('abc123') }
|
354
|
+
end
|
355
|
+
|
356
|
+
describe '#target_call_id' do
|
357
|
+
subject { super().target_call_id }
|
358
|
+
it { is_expected.to eq('123abc') }
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
describe '#stop!' do
|
363
|
+
describe "when the command is executing" do
|
364
|
+
before do
|
365
|
+
command.request!
|
366
|
+
command.execute!
|
367
|
+
end
|
368
|
+
|
369
|
+
it "should send its command properly" do
|
370
|
+
expect(mock_client).to receive(:execute_command).with(command.stop_action, :target_call_id => '123abc', :component_id => 'abc123')
|
371
|
+
command.stop!
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
describe "when the command is not executing" do
|
376
|
+
it "should raise an error" do
|
377
|
+
expect { command.stop! }.to raise_error(Adhearsion::Rayo::Component::InvalidActionError, "Cannot stop a Input that is new")
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
describe described_class::Complete::Match do
|
384
|
+
let :nlsml_string do
|
385
|
+
'''
|
386
|
+
<result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight">
|
387
|
+
<interpretation confidence="0.60">
|
388
|
+
<input mode="voice">I want to go to Pittsburgh</input>
|
389
|
+
<instance>
|
390
|
+
<airline>
|
391
|
+
<to_city>Pittsburgh</to_city>
|
392
|
+
</airline>
|
393
|
+
</instance>
|
394
|
+
</interpretation>
|
395
|
+
<interpretation confidence="0.40">
|
396
|
+
<input>I want to go to Stockholm</input>
|
397
|
+
<instance>
|
398
|
+
<airline>
|
399
|
+
<to_city>Stockholm</to_city>
|
400
|
+
</airline>
|
401
|
+
</instance>
|
402
|
+
</interpretation>
|
403
|
+
</result>
|
404
|
+
'''
|
405
|
+
end
|
406
|
+
|
407
|
+
let :stanza do
|
408
|
+
<<-MESSAGE
|
409
|
+
<complete xmlns='urn:xmpp:rayo:ext:1'>
|
410
|
+
<match xmlns="urn:xmpp:rayo:input:complete:1" content-type="application/nlsml+xml">
|
411
|
+
<![CDATA[#{nlsml_string}]]>
|
412
|
+
</match>
|
413
|
+
</complete>
|
414
|
+
MESSAGE
|
415
|
+
end
|
416
|
+
|
417
|
+
let :expected_nlsml do
|
418
|
+
RubySpeech.parse nlsml_string
|
419
|
+
end
|
420
|
+
|
421
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml(parse_stanza(stanza).root).reason }
|
422
|
+
|
423
|
+
it { is_expected.to be_instance_of described_class }
|
424
|
+
|
425
|
+
describe '#name' do
|
426
|
+
subject { super().name }
|
427
|
+
it { is_expected.to eq(:match) }
|
428
|
+
end
|
429
|
+
|
430
|
+
describe '#content_type' do
|
431
|
+
subject { super().content_type }
|
432
|
+
it { is_expected.to eq('application/nlsml+xml') }
|
433
|
+
end
|
434
|
+
|
435
|
+
describe '#nlsml' do
|
436
|
+
subject { super().nlsml }
|
437
|
+
it { is_expected.to eq(expected_nlsml) }
|
438
|
+
end
|
439
|
+
|
440
|
+
describe '#mode' do
|
441
|
+
subject { super().mode }
|
442
|
+
it { is_expected.to eq(:voice) }
|
443
|
+
end
|
444
|
+
|
445
|
+
describe '#confidence' do
|
446
|
+
subject { super().confidence }
|
447
|
+
it { is_expected.to eq(0.6) }
|
448
|
+
end
|
449
|
+
|
450
|
+
describe '#interpretation' do
|
451
|
+
subject { super().interpretation }
|
452
|
+
it { is_expected.to eq({ airline: { to_city: 'Pittsburgh' } }) }
|
453
|
+
end
|
454
|
+
|
455
|
+
describe '#utterance' do
|
456
|
+
subject { super().utterance }
|
457
|
+
it { is_expected.to eq('I want to go to Pittsburgh') }
|
458
|
+
end
|
459
|
+
|
460
|
+
describe "when creating from an NLSML document" do
|
461
|
+
subject do
|
462
|
+
described_class.new :nlsml => expected_nlsml
|
463
|
+
end
|
464
|
+
|
465
|
+
describe '#content_type' do
|
466
|
+
subject { super().content_type }
|
467
|
+
it { is_expected.to eq('application/nlsml+xml') }
|
468
|
+
end
|
469
|
+
|
470
|
+
describe '#nlsml' do
|
471
|
+
subject { super().nlsml }
|
472
|
+
it { is_expected.to eq(expected_nlsml) }
|
473
|
+
end
|
474
|
+
|
475
|
+
describe '#mode' do
|
476
|
+
subject { super().mode }
|
477
|
+
it { is_expected.to eq(:voice) }
|
478
|
+
end
|
479
|
+
|
480
|
+
describe '#confidence' do
|
481
|
+
subject { super().confidence }
|
482
|
+
it { is_expected.to eq(0.6) }
|
483
|
+
end
|
484
|
+
|
485
|
+
describe '#interpretation' do
|
486
|
+
subject { super().interpretation }
|
487
|
+
it { is_expected.to eq({ airline: { to_city: 'Pittsburgh' } }) }
|
488
|
+
end
|
489
|
+
|
490
|
+
describe '#utterance' do
|
491
|
+
subject { super().utterance }
|
492
|
+
it { is_expected.to eq('I want to go to Pittsburgh') }
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
context "when not enclosed in CDATA, but escaped" do
|
497
|
+
let :stanza do
|
498
|
+
<<-MESSAGE
|
499
|
+
<complete xmlns='urn:xmpp:rayo:ext:1'>
|
500
|
+
<match xmlns="urn:xmpp:rayo:input:complete:1" content-type="application/nlsml+xml">
|
501
|
+
<result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight"/>
|
502
|
+
</match>
|
503
|
+
</complete>
|
504
|
+
MESSAGE
|
505
|
+
end
|
506
|
+
|
507
|
+
it "should parse the NLSML correctly" do
|
508
|
+
expect(subject.nlsml.grammar).to eq("http://flight")
|
509
|
+
end
|
510
|
+
end
|
511
|
+
|
512
|
+
context "when nested directly" do
|
513
|
+
let :stanza do
|
514
|
+
<<-MESSAGE
|
515
|
+
<complete xmlns='urn:xmpp:rayo:ext:1'>
|
516
|
+
<match xmlns="urn:xmpp:rayo:input:complete:1" content-type="application/nlsml+xml">
|
517
|
+
#{nlsml_string}
|
518
|
+
</match>
|
519
|
+
</complete>
|
520
|
+
MESSAGE
|
521
|
+
end
|
522
|
+
|
523
|
+
it "should parse the NLSML correctly" do
|
524
|
+
expect(subject.nlsml.grammar).to eq("http://flight")
|
525
|
+
end
|
526
|
+
end
|
527
|
+
|
528
|
+
describe "comparison" do
|
529
|
+
context "with the same nlsml" do
|
530
|
+
it "should be equal" do
|
531
|
+
expect(subject).to eq(Adhearsion::Rayo::RayoNode.from_xml(parse_stanza(stanza).root).reason)
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
535
|
+
context "with different nlsml" do
|
536
|
+
let :other_stanza do
|
537
|
+
<<-MESSAGE
|
538
|
+
<complete xmlns='urn:xmpp:rayo:ext:1'>
|
539
|
+
<match xmlns="urn:xmpp:rayo:input:complete:1">
|
540
|
+
<![CDATA[<result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight"/>]]>
|
541
|
+
</match>
|
542
|
+
</complete>
|
543
|
+
MESSAGE
|
544
|
+
end
|
545
|
+
|
546
|
+
it "should not be equal" do
|
547
|
+
expect(subject).not_to eq(Adhearsion::Rayo::RayoNode.from_xml(parse_stanza(other_stanza).root).reason)
|
548
|
+
end
|
549
|
+
end
|
550
|
+
end
|
551
|
+
end
|
552
|
+
|
553
|
+
describe described_class::Complete::NoMatch do
|
554
|
+
let :stanza do
|
555
|
+
<<-MESSAGE
|
556
|
+
<complete xmlns='urn:xmpp:rayo:ext:1'>
|
557
|
+
<nomatch xmlns='urn:xmpp:rayo:input:complete:1' />
|
558
|
+
</complete>
|
559
|
+
MESSAGE
|
560
|
+
end
|
561
|
+
|
562
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml(parse_stanza(stanza).root).reason }
|
563
|
+
|
564
|
+
it { is_expected.to be_instance_of described_class }
|
565
|
+
|
566
|
+
describe '#name' do
|
567
|
+
subject { super().name }
|
568
|
+
it { is_expected.to eq(:nomatch) }
|
569
|
+
end
|
570
|
+
end
|
571
|
+
|
572
|
+
describe described_class::Complete::NoInput do
|
573
|
+
let :stanza do
|
574
|
+
<<-MESSAGE
|
575
|
+
<complete xmlns='urn:xmpp:rayo:ext:1'>
|
576
|
+
<noinput xmlns='urn:xmpp:rayo:input:complete:1' />
|
577
|
+
</complete>
|
578
|
+
MESSAGE
|
579
|
+
end
|
580
|
+
|
581
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml(parse_stanza(stanza).root).reason }
|
582
|
+
|
583
|
+
it { is_expected.to be_instance_of described_class }
|
584
|
+
|
585
|
+
describe '#name' do
|
586
|
+
subject { super().name }
|
587
|
+
it { is_expected.to eq(:noinput) }
|
588
|
+
end
|
589
|
+
end
|
590
|
+
|
591
|
+
describe described_class::Signal do
|
592
|
+
let :stanza do
|
593
|
+
<<-MESSAGE
|
594
|
+
<signal xmlns="urn:xmpp:rayo:cpa:1" type="urn:xmpp:rayo:cpa:beep:1" duration="1000" value="8000"/>
|
595
|
+
MESSAGE
|
596
|
+
end
|
597
|
+
|
598
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml(parse_stanza(stanza).root) }
|
599
|
+
|
600
|
+
it { is_expected.to be_instance_of described_class }
|
601
|
+
it { is_expected.to be_a Adhearsion::Event }
|
602
|
+
|
603
|
+
describe '#name' do
|
604
|
+
subject { super().name }
|
605
|
+
it { is_expected.to eq(:signal) }
|
606
|
+
end
|
607
|
+
|
608
|
+
describe '#type' do
|
609
|
+
subject { super().type }
|
610
|
+
it { is_expected.to eq('urn:xmpp:rayo:cpa:beep:1') }
|
611
|
+
end
|
612
|
+
|
613
|
+
describe '#duration' do
|
614
|
+
subject { super().duration }
|
615
|
+
it { is_expected.to eq(1000) }
|
616
|
+
end
|
617
|
+
|
618
|
+
describe '#value' do
|
619
|
+
subject { super().value }
|
620
|
+
it { is_expected.to eq('8000') }
|
621
|
+
end
|
622
|
+
|
623
|
+
describe "when creating from options" do
|
624
|
+
subject do
|
625
|
+
described_class.new type: 'urn:xmpp:rayo:cpa:beep:1', duration: 1000, value: '8000'
|
626
|
+
end
|
627
|
+
|
628
|
+
describe '#name' do
|
629
|
+
subject { super().name }
|
630
|
+
it { is_expected.to eq(:signal) }
|
631
|
+
end
|
632
|
+
|
633
|
+
describe '#type' do
|
634
|
+
subject { super().type }
|
635
|
+
it { is_expected.to eq('urn:xmpp:rayo:cpa:beep:1') }
|
636
|
+
end
|
637
|
+
|
638
|
+
describe '#duration' do
|
639
|
+
subject { super().duration }
|
640
|
+
it { is_expected.to eq(1000) }
|
641
|
+
end
|
642
|
+
|
643
|
+
describe '#value' do
|
644
|
+
subject { super().value }
|
645
|
+
it { is_expected.to eq('8000') }
|
646
|
+
end
|
647
|
+
end
|
648
|
+
|
649
|
+
context "when in a complete event" do
|
650
|
+
let :stanza do
|
651
|
+
<<-MESSAGE
|
652
|
+
<complete xmlns='urn:xmpp:rayo:ext:1'>
|
653
|
+
<signal xmlns="urn:xmpp:rayo:cpa:1" type="urn:xmpp:rayo:cpa:beep:1" duration="1000" value="8000"/>
|
654
|
+
</complete>
|
655
|
+
MESSAGE
|
656
|
+
end
|
657
|
+
|
658
|
+
subject { Adhearsion::Rayo::RayoNode.from_xml(parse_stanza(stanza).root).reason }
|
659
|
+
|
660
|
+
it { is_expected.to be_instance_of described_class }
|
661
|
+
|
662
|
+
describe '#name' do
|
663
|
+
subject { super().name }
|
664
|
+
it { is_expected.to eq(:signal) }
|
665
|
+
end
|
666
|
+
|
667
|
+
describe '#type' do
|
668
|
+
subject { super().type }
|
669
|
+
it { is_expected.to eq('urn:xmpp:rayo:cpa:beep:1') }
|
670
|
+
end
|
671
|
+
|
672
|
+
describe '#duration' do
|
673
|
+
subject { super().duration }
|
674
|
+
it { is_expected.to eq(1000) }
|
675
|
+
end
|
676
|
+
|
677
|
+
describe '#value' do
|
678
|
+
subject { super().value }
|
679
|
+
it { is_expected.to eq('8000') }
|
680
|
+
end
|
681
|
+
end
|
682
|
+
|
683
|
+
describe "comparison" do
|
684
|
+
context "with the same options" do
|
685
|
+
it "should be equal" do
|
686
|
+
expect(subject).to eq(Adhearsion::Rayo::RayoNode.from_xml(parse_stanza(stanza).root))
|
687
|
+
end
|
688
|
+
end
|
689
|
+
|
690
|
+
context "with different type" do
|
691
|
+
let(:other_stanza) { '<signal xmlns="urn:xmpp:rayo:cpa:1" type="urn:xmpp:rayo:cpa:ring:1" duration="1000" value="8000"/>' }
|
692
|
+
|
693
|
+
it "should not be equal" do
|
694
|
+
expect(subject).not_to eq(Adhearsion::Rayo::RayoNode.from_xml(parse_stanza(other_stanza).root))
|
695
|
+
end
|
696
|
+
end
|
697
|
+
|
698
|
+
context "with different duration" do
|
699
|
+
let(:other_stanza) { '<signal xmlns="urn:xmpp:rayo:cpa:1" type="urn:xmpp:rayo:cpa:beep:1" duration="100" value="8000"/>' }
|
700
|
+
|
701
|
+
it "should not be equal" do
|
702
|
+
expect(subject).not_to eq(Adhearsion::Rayo::RayoNode.from_xml(parse_stanza(other_stanza).root))
|
703
|
+
end
|
704
|
+
end
|
705
|
+
|
706
|
+
context "with different value" do
|
707
|
+
let(:other_stanza) { '<signal xmlns="urn:xmpp:rayo:cpa:1" type="urn:xmpp:rayo:cpa:beep:1" duration="1000" value="7000"/>' }
|
708
|
+
|
709
|
+
it "should not be equal" do
|
710
|
+
expect(subject).not_to eq(Adhearsion::Rayo::RayoNode.from_xml(parse_stanza(other_stanza).root))
|
711
|
+
end
|
712
|
+
end
|
713
|
+
end
|
714
|
+
end
|
715
|
+
end
|