Skip to content

Commit

Permalink
Allow setting barge per-prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed May 1, 2015
1 parent 7611beb commit c7ec557
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/adhearsion-ivr/ivr_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,15 @@ def run
deliver_prompt true
end

def deliver_prompt(interruptible = self.class.barge)
def deliver_prompt(interruptible = nil)
prompt = prompts[@errors] || prompts.last
prompt = instance_exec(&prompt) if prompt.respond_to? :call
logger.debug "Prompt: #{prompt.inspect}"

if interruptible.nil?
interruptible = self.barge
end

if grammar
ask_options = { grammar: grammar, mode: :voice }
elsif grammar_url
Expand Down Expand Up @@ -188,6 +192,20 @@ def prompts
self.class.prompts
end

def barge(val = nil)
if val.nil?
if @barge.nil?
self.class.barge
else
old = @barge
@barge = nil
old
end
else
@barge = val
end
end

def max_attempts
self.class.max_attempts
end
Expand Down
28 changes: 28 additions & 0 deletions spec/adhearsion-ivr/ivr_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -677,5 +677,33 @@ def grammar
controller.run
end
end

context 'when overriding barge per-prompt' do
context 'with default barge behaviour' do # Only first prompt bargeable
let(:controller_class) do
Class.new(Adhearsion::IVRController) do
prompts << -> { 'first' } # Bargeable
prompts << -> { 'second' } # Unbargeable
prompts << -> { self.barge true; 'third' } # Bargeable

on_complete do |result|
say "Let's go to #{result.utterance}"
end

def grammar
:some_grammar
end
end
end

it 'allows interruption of each prompt correctly' do
controller.should_receive(:ask).once.with('first', grammar: :some_grammar, mode: :voice, interruptible: true).and_return noinput_result
controller.should_receive(:ask).once.with('second', grammar: :some_grammar, mode: :voice, interruptible: false).and_return noinput_result
controller.should_receive(:ask).once.with('third', grammar: :some_grammar, mode: :voice, interruptible: true).and_return match_result
controller.should_receive(:say).once.with "Let's go to Paris"
controller.run
end
end
end
end
end

0 comments on commit c7ec557

Please sign in to comment.