Skip to content

Don't force the account_sid and auth_token to be passed when initializing a client incase they were set in the block configuration #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 20 additions & 23 deletions lib/sms_spec/drivers/twilio-ruby.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
require 'twilio-ruby'

module Twilio
module REST
class Client

def initialize(account_sid, auth_token)
$account_sid = account_sid
class Client
def account
Account.new(nil, self, sid: @account_sid)
end
end

class Messages
include SmsSpec::Helpers
class Messages
include SmsSpec::Helpers

def create(opts={})
to = opts[:to]
body = opts[:body]
from = opts[:from]
add_message SmsSpec::Message.new(:number => to, :from => from, :body => body)
end
def create(opts={})
to = opts[:to]
body = opts[:body]
from = opts[:from]
add_message SmsSpec::Message.new(:number => to, :from => from, :body => body)
end
end

class Account
def sms
Sms.new
end

def messages
Messages.new
end
class Account
def sms
Sms.new
end

def account
account = Account.new
account.class.send(:define_method, :sid, lambda { $account_sid })
account
def messages
Messages.new
end
end

end
end
13 changes: 13 additions & 0 deletions spec/drivers/twilio_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,18 @@
expect(current_text_message.from).to eq('+14159341234')
end

it 'allows the account_sid and auth_token to be set via the block configuration' do
account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

Twilio.configure do |config|
config.account_sid = account_sid
config.auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
end

@client = Twilio::REST::Client.new

expect(@client.account.sid).to be(account_sid)
end

end
end