Skip to content

Commit

Permalink
More appropriate callback names
Browse files Browse the repository at this point in the history
Fixes #385
  • Loading branch information
benlangfeld committed Dec 4, 2015
1 parent d1eb2bd commit e8119af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions lib/adhearsion/call_controller.rb
Expand Up @@ -18,7 +18,7 @@ class CallController

class_attribute :callbacks

self.callbacks = {:before_call => [], :after_call => [], :on_error => []}
self.callbacks = {:before => [], :after => [], :on_error => []}

self.callbacks.keys.each do |name|
class_eval <<-STOP
Expand Down Expand Up @@ -113,15 +113,15 @@ def exec_with_callback(completion_callback = nil)
# @private
def execute!(*options)
call.async.register_controller self
execute_callbacks :before_call
execute_callbacks :before
run
rescue Call::Hangup, Call::ExpiredError
rescue SyntaxError, StandardError => e
Events.trigger :exception, [e, logger]
on_error e
raise
ensure
after_call
after
logger.debug "Finished executing controller #{self.inspect}"
end

Expand Down Expand Up @@ -189,8 +189,8 @@ def execute_callbacks(type)
end

# @private
def after_call
@after_call ||= execute_callbacks :after_call
def after
@after ||= execute_callbacks :after
end

# @private
Expand Down Expand Up @@ -234,7 +234,7 @@ def answer(*args)
end

#
# Hangup the call, and execute after_call callbacks
# Hangup the call, and execute after callbacks
#
# @param [Hash] headers
#
Expand Down
18 changes: 9 additions & 9 deletions spec/adhearsion/call_controller_spec.rb
Expand Up @@ -200,7 +200,7 @@ def second_controller
describe "#pass" do
let(:pass_controller) do
Class.new CallController do
after_call :foobar
after :foobar

def run
before
Expand Down Expand Up @@ -237,7 +237,7 @@ def foobar
subject.exec
end

it "should execute after_call callbacks before passing control" do
it "should execute after callbacks before passing control" do
expect(subject).to receive(:before).once.ordered
expect(subject).to receive(:foobar).once.ordered
expect(call).to receive(:answer).once.ordered
Expand Down Expand Up @@ -622,11 +622,11 @@ def run
end

class ExampleCallController < Adhearsion::CallController
before_call { setup_models }
before_call :setup_models
before { setup_models }
before :setup_models

after_call { clean_up_models }
after_call :clean_up_models
after { clean_up_models }
after :clean_up_models

on_error { apologize_for_failure }
on_error :apologize_for_failure
Expand Down Expand Up @@ -661,13 +661,13 @@ def foobar
allow(call.wrapped_object).to receive_messages :write_and_await_response => nil
end

it "should execute the before_call callbacks before processing the call" do
it "should execute the before callbacks before processing the call" do
expect(subject).to receive(:setup_models).twice.ordered
expect(subject).to receive(:join_to_conference).once.ordered
subject.exec
end

it "should execute the after_call callbacks after the call is hung up" do
it "should execute the after callbacks after the call is hung up" do
expect(subject).to receive(:join_to_conference).once.ordered
expect(subject).to receive(:clean_up_models).twice.ordered
expect(subject).to receive(:foobar).never
Expand Down Expand Up @@ -695,7 +695,7 @@ def foobar
end

describe "when the controller finishes without a hangup" do
it "should execute the after_call callbacks" do
it "should execute the after callbacks" do
subject[:skip_hangup] = true
expect(subject).to receive(:join_to_conference).once.ordered
expect(subject).to receive(:foobar).once.ordered
Expand Down

0 comments on commit e8119af

Please sign in to comment.