Didn't handle case of no user found gracefully

This commit is contained in:
epall 2008-06-07 17:15:12 -07:00 committed by Eric Allen
parent 8783beb280
commit 920507441d
2 changed files with 10 additions and 0 deletions

View file

@ -2,6 +2,8 @@ class SMSGateway < ActionMailer::Base
CONTEXT_NAME = 'Inbox'
def receive(email)
user = User.find(:first, :include => [:preference], :conditions => ["preferences.sms_email = ?", email.from[0].strip])
logger.info "Receiving SMS task from #{email.from[0].strip} For user #{user.nil? nil : user.login}"
return if user.nil?
context = user.prefs.sms_context
description = nil

View file

@ -48,4 +48,12 @@ class SMSGatewayTest < Test::Rails::TestCase
assert_equal(@user, message_todo.user)
assert_equal("This is the message body", message_todo.notes)
end
def test_no_user
todo_count = Todo.count
badmessage = File.read(File.join(RAILS_ROOT, 'test', 'fixtures', 'sample_sms.txt'))
badmessage.gsub!("5555555555", "notauser")
SMSGateway.receive(badmessage)
assert_equal(todo_count, Todo.count)
end
end