Permalink
Browse files

Modify argument signature of CallInProgress#initialize, and so ttt_ca…

…ll().

An options hash instead of multiple "could be nil" args is neater and will better support addition of more options.
  • Loading branch information...
1 parent 5b00760 commit 0d4ee8353f94f05060857993538d4b3977fabfa5 Jon Gilbraith committed Jan 25, 2013
Showing with 19 additions and 12 deletions.
  1. +5 −2 README.md
  2. +7 −5 lib/twilio-test-toolkit/call_in_progress.rb
  3. +6 −4 lib/twilio-test-toolkit/dsl.rb
  4. +1 −1 spec/requests/dsl_spec.rb
View
@@ -91,13 +91,16 @@ ttt_call
The *ttt_call* method is the main entry point for working with TTT. You call this method to initiate a "Twilio phone call" to your controller actions. TTT simulates Twilio's behavior by POSTing to your action with the expected Twilio parameters (From, To, CallSid, etc).
-*ttt_call* has three required parameters, and two optional ones:
+*ttt_call* has three required parameters and an options hash:
- @call = ttt_call(action_path, from_number, to_number, call_sid = nil, is_machine = false)
+ @call = ttt_call(action_path, from_number, to_number, options = {})
* **action_path**. Where to POST your request. It should be obvious by now, but whatever action you specify here should be a POST action.
* **from_number**. What to fill params[:From] with. If you don't care about this value, you can pass a blank one, as this is only used to pass along to your actions.
* **to_number**. What to fill params[:To] with.
+
+Options are:
+
* **call_sid**. Specify an optional fixed value to be passed as params[:CallSid]. This is useful if you are expecting a specific SID. For instance, a common pattern is to initiate a call, store the SID in your database, and look up the call when you get the callback. If you don't pass a SID, TTT will generate one for you that's just a UUID.
* **is_machine**. Controls params[:AnsweredBy]. See Twilio's documentation for more information on how Twilio uses this.
@@ -3,19 +3,21 @@
module TwilioTestToolkit
# Models a call
class CallInProgress < CallScope
- # Init the call
- def initialize(initial_path, from_number, to_number, call_sid, is_machine)
+ # Initiate a call. Options:
+ # * :call_sid - specify an optional fixed value to be passed as params[:CallSid]
+ # * :is_machine - controls params[:AnsweredBy]
+ def initialize(initial_path, from_number, to_number, options = {})
# Save our variables for later
@initial_path = initial_path
@from_number = from_number
@to_number = to_number
- @is_machine = is_machine
+ @is_machine = options[:is_machine]
# Generate an initial call SID if we don't have one
- if (call_sid.nil?)
+ if (options[:call_sid].nil?)
@sid = UUIDTools::UUID.random_create.to_s
else
- @sid = call_sid
+ @sid = options[:call_sid]
end
# We are the root call
@@ -2,11 +2,13 @@ module TwilioTestToolkit
require 'twilio-test-toolkit/call_in_progress'
# Adds the `ttt_call` method to the top-level namespace.
- module DSL
- # call = ttt_call(inbound_phone_index_path, "+12065551212")
- def ttt_call(initial_path, from_number, to_number, call_sid = nil, is_machine = false)
+ module DSL
+ # Initiate a call. Options:
+ # * :call_sid - specify an optional fixed value to be passed as params[:CallSid]
+ # * :is_machine - controls params[:AnsweredBy]
+ def ttt_call(initial_path, from_number, to_number, options = {})
# Make a new call in progress
- return CallInProgress.new(initial_path, from_number, to_number, call_sid, is_machine)
+ return CallInProgress.new(initial_path, from_number, to_number, options)
end
end
end
@@ -31,7 +31,7 @@
describe "with a sid and machine override" do
before(:each) do
@mysid = "1234567"
- @call = ttt_call(test_start_twilio_index_path, @our_number, @their_number, @mysid, true)
+ @call = ttt_call(test_start_twilio_index_path, @our_number, @their_number, :call_sid => @mysid, :is_machine => true)
end
it "should have the right sid" do

0 comments on commit 0d4ee83

Please sign in to comment.