Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jacob Rothstein
committed
Dec 1, 2009
1 parent
c94bbbe
commit 04ab27d
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class SmsHandler | ||
attr_reader :message, :connection | ||
|
||
def initialize(message) | ||
@connection = Clickatell::API.authenticate settings["api_id"], | ||
settings["username"], settings["password"] | ||
|
||
@message = message | ||
end | ||
|
||
def settings | ||
BREAKGLASS_SETTINGS['sms'] | ||
end | ||
|
||
def contact(person) | ||
Rails.logger.info "Sending sms: #{message.text} to: #{person.sms}" | ||
connection.send_message "1#{person.sms}", message.text | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'test_helper' | ||
|
||
class SmsHandlerTest < ActiveSupport::TestCase | ||
context 'with test settings' do | ||
setup do | ||
@settings = BREAKGLASS_SETTINGS['sms'] = { | ||
'api_id' => 'my id', | ||
'username' => 'username', | ||
'password' => 'password' | ||
} | ||
|
||
@message = messages :hello_world | ||
@person = people :lara | ||
end | ||
|
||
context 'initialization' do | ||
should 'authenticate with clickatell' do | ||
flexmock(Clickatell::API).should_receive(:authenticate).once. | ||
with @settings['api_id'], @settings['username'], @settings['password'] | ||
SmsHandler.new @message | ||
end | ||
end | ||
|
||
context 'with a handler' do | ||
setup do | ||
flexmock(Clickatell::API).should_receive(:authenticate). | ||
and_return(@connection = :connection) | ||
@handler = SmsHandler.new @message | ||
end | ||
|
||
should 'have the right message' do | ||
assert_message @message, @handler | ||
end | ||
|
||
should 'have the right connection' do | ||
assert_connection @connection, @handler | ||
end | ||
end | ||
|
||
context 'contact' do | ||
should 'contact clickatell with the right number and text' do | ||
@connection = flexmock do |conn| | ||
conn.should_receive(:send_message).once. | ||
with "1#{@person.sms}", @message.text | ||
end | ||
|
||
flexmock(Clickatell::API).should_receive(:authenticate). | ||
and_return(@connection) | ||
|
||
SmsHandler.new(@message).contact @person | ||
end | ||
end | ||
end | ||
end |