Rename to MessageGateway since it's really not SMS-specific.

This commit is contained in:
Eric Allen 2008-09-20 19:15:12 -07:00
parent 8238e488a2
commit ca4255332f
4 changed files with 18 additions and 19 deletions

View file

@ -1,5 +1,4 @@
class SMSGateway < ActionMailer::Base
CONTEXT_NAME = 'Inbox'
class MessageGateway < ActionMailer::Base
def receive(email)
user = User.find(:first, :include => [:preference], :conditions => ["preferences.sms_email = ?", email.from[0].strip])
if user.nil?

View file

@ -19,8 +19,8 @@
<li><strong>refresh:</strong> automatic refresh interval for each of the pages (in minutes)</li>
<li><strong>verbose action descriptor:</strong> when true, show project/context name in action listing; when false show [P]/[C] with tool tips</li>
<li><strong>mobile todos per page:</strong> the maximum number of actions to show on a single page in the mobile view</li>
<li><strong>SMS email:</string> the email address of your cell phone for sending text messages to your Tracks account</li>
<li><string>SMS context:</string> the context to which tasks sent in via SMS should be added</li>
<li><strong>From email:</string> the email address you use for sending todos as email or SMS messages to your Tracks account</li>
<li><string>Message context:</string> the context to which tasks sent in via email or SMS should be added</li>
</ul>
</div>

View file

@ -28,8 +28,8 @@
<li>Refresh interval (in minutes): <span class="highlight"><%= prefs.refresh %></span></li>
<li>Verbose action descriptors: <span class="highlight"><%= prefs.verbose_action_descriptors %></span></li>
<li>Actions per page (Mobile View): <span class="highlight"><%= prefs.mobile_todos_per_page %></span></li>
<li>SMS email address: <span class="highlight"><%= prefs.sms_email %></span></li>
<li>SMS context: <span class="highlight"><%= prefs.sms_context.nil? ? "None" : prefs.sms_context.name %></span></li>
<li>From email: <span class="highlight"><%= prefs.sms_email %></span></li>
<li>Message context: <span class="highlight"><%= prefs.sms_context.nil? ? "None" : prefs.sms_context.name %></span></li>
</ul>
<div class="actions">
<%= link_to "Edit preferences &raquo;", { :controller => 'preferences', :action => 'edit'}, :class => 'edit_link' %>

View file

@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
class SMSGatewayTest < Test::Rails::TestCase
class MessageGatewayTest < Test::Rails::TestCase
fixtures :users, :contexts
def setup
@ -9,7 +9,7 @@ class SMSGatewayTest < Test::Rails::TestCase
end
def load_message(filename)
SMSGateway.receive(File.read(File.join(RAILS_ROOT, 'test', 'fixtures', filename)))
MessageGateway.receive(File.read(File.join(RAILS_ROOT, 'test', 'fixtures', filename)))
end
def test_sms_with_no_subject
@ -53,7 +53,7 @@ class SMSGatewayTest < Test::Rails::TestCase
todo_count = Todo.count
badmessage = File.read(File.join(RAILS_ROOT, 'test', 'fixtures', 'sample_sms.txt'))
badmessage.gsub!("5555555555", "notauser")
SMSGateway.receive(badmessage)
MessageGateway.receive(badmessage)
assert_equal(todo_count, Todo.count)
end
@ -63,12 +63,12 @@ class SMSGatewayTest < Test::Rails::TestCase
valid_context_msg = message.gsub('message_content', 'anothercontext: this is a task')
invalid_context_msg = message.gsub('message_content', 'notacontext: this is a task')
SMSGateway.receive(valid_context_msg)
MessageGateway.receive(valid_context_msg)
valid_context_todo = Todo.find(:first, :conditions => {:description => "this is a task"})
assert_not_nil(valid_context_todo)
assert_equal(contexts(:anothercontext), valid_context_todo.context)
SMSGateway.receive(invalid_context_msg)
MessageGateway.receive(invalid_context_msg)
invalid_context_todo = Todo.find(:first, :conditions => {:description => 'notacontext: this is a task'})
assert_not_nil(invalid_context_todo)
assert_equal(@inbox, invalid_context_todo.context)
@ -82,22 +82,22 @@ class SMSGatewayTest < Test::Rails::TestCase
valid_due_msg3 = message.gsub('message_content', 'due:1/28/2008 funky!')
invalid_due_msg1 = message.gsub('message_content', 'do something tomorrow due:xxxx and remember it!')
SMSGateway.receive(valid_due_msg1)
MessageGateway.receive(valid_due_msg1)
valid_due_todo1 = Todo.find(:first, :conditions => {:description => "do something tomorrow"})
assert_not_nil(valid_due_todo1)
assert_equal(Date.civil(2008, 6, 15), valid_due_todo1.due)
SMSGateway.receive(valid_due_msg2)
MessageGateway.receive(valid_due_msg2)
valid_due_todo2 = Todo.find(:first, :conditions => {:description => "do something tomorrow and remember it!"})
assert_not_nil(valid_due_todo2)
assert_equal(Date.civil(2008, 6, 28), valid_due_todo2.due)
SMSGateway.receive(valid_due_msg3)
MessageGateway.receive(valid_due_msg3)
valid_due_todo3 = Todo.find(:first, :conditions => {:description => "funky!"})
assert_not_nil(valid_due_todo3)
assert_equal(Date.civil(2008, 1, 28), valid_due_todo3.due)
SMSGateway.receive(invalid_due_msg1)
MessageGateway.receive(invalid_due_msg1)
invalid_due_todo1 = Todo.find(:first, :conditions => {:description => "do something tomorrow due:xxxx and remember it!"})
assert_not_nil(invalid_due_todo1)
assert_nil(invalid_due_todo1.due)
@ -111,23 +111,23 @@ class SMSGatewayTest < Test::Rails::TestCase
valid_show_msg3 = message.gsub('message_content', "show:#{Date.tomorrow.to_s} alternative format")
invalid_show_msg1 = message.gsub('message_content', 'do something tomorrow show:xxxx and remember it!')
SMSGateway.receive(valid_show_msg1)
MessageGateway.receive(valid_show_msg1)
valid_show_todo1 = Todo.find(:first, :conditions => {:description => "do something tomorrow"})
assert_not_nil(valid_show_todo1)
assert_equal(Date.tomorrow, valid_show_todo1.show_from)
SMSGateway.receive(valid_show_msg2)
MessageGateway.receive(valid_show_msg2)
valid_show_todo2 = Todo.find(:first, :conditions => {:description => "do something next week and remember it!"})
assert_not_nil(valid_show_todo2)
assert_equal(Date.today.next_week, valid_show_todo2.show_from)
SMSGateway.receive(valid_show_msg3)
MessageGateway.receive(valid_show_msg3)
valid_show_todo3 = Todo.find(:first, :conditions => {:description => "alternative format"})
# p @user.todos.last
assert_not_nil(valid_show_todo3)
assert_equal(Date.tomorrow, valid_show_todo3.show_from)
SMSGateway.receive(invalid_show_msg1)
MessageGateway.receive(invalid_show_msg1)
invalid_show_todo1 = Todo.find(:first, :conditions => {:description => "do something tomorrow show:xxxx and remember it!"})
assert_not_nil(invalid_show_todo1)
assert_nil(invalid_show_todo1.show_from)