diff options
| author | Brendan G. Lim | 2008-03-31 18:18:40 -0400 |
|---|---|---|
| committer | Brendan G. Lim | 2008-03-31 18:18:40 -0400 |
| commit | 5ecbaaee4d38543a66767b02d5b41ef9e885f2d5 (patch) | |
| tree | 6f571ca5e88dab97907f30e57e9cda6b31e6130f | |
| parent | cb0138f5f1f637bcd5065e548b0dac04d413acd8 (diff) | |
| download | sms-fu-5ecbaaee4d38543a66767b02d5b41ef9e885f2d5.tar.bz2 | |
Fixed some of the tests
| -rw-r--r-- | lib/sms_fu.rb | 11 | ||||
| -rw-r--r-- | lib/sms_notifier.rb | 2 | ||||
| -rw-r--r-- | templates/sms_fu.yml | 8 | ||||
| -rw-r--r-- | test/sms_fu_test.rb | 8 |
4 files changed, 17 insertions, 12 deletions
diff --git a/lib/sms_fu.rb b/lib/sms_fu.rb index 9dd958b..5932d4a 100644 --- a/lib/sms_fu.rb +++ b/lib/sms_fu.rb @@ -21,7 +21,10 @@ require 'yaml' # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. module SMSFu - @@config = YAML::load(File.open("#{RAILS_ROOT}/config/sms_fu.yml")) + + RAILS_CONFIG_ROOT = defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/config" : "#{File.dirname(__FILE__)}/../templates" + @config = YAML::load(File.open("#{RAILS_CONFIG_ROOT}/sms_fu.yml")) + @@carriers = @config['carriers'] def deliver_sms(number,carrier,message,options={}) number = format_number(number) @@ -44,7 +47,7 @@ module SMSFu def format_number(number) pre_formatted = number.gsub("-","").strip - formatted = (pre_formatted.length == 11) ? pre_formatted[1..pre_formatted.length] : pre_formatted + formatted = (pre_formatted.length == 11 && pre_formatted[0,1] == "1") ? pre_formatted[1..pre_formatted.length] : pre_formatted return is_valid?(formatted) ? formatted : (raise SMSFuException.new("Phone number (#{number}) is not formatted correctly")) end @@ -54,8 +57,8 @@ module SMSFu end def determine_sms_email(phone_number, carrier) - if @@config['carriers'].has_key?(carrier.downcase) - "#{phone_number}#{@@config['carriers'][carrier.downcase]}" + if @@carriers.has_key?(carrier.downcase) + "#{phone_number}#{@@carriers[carrier.downcase]}" else raise SMSFuException.new("Specified carrier, #{carrier} is not supported.") end diff --git a/lib/sms_notifier.rb b/lib/sms_notifier.rb index 127f35b..cf698c8 100644 --- a/lib/sms_notifier.rb +++ b/lib/sms_notifier.rb @@ -22,7 +22,7 @@ require 'yaml' class SmsNotifier < ActionMailer::Base @config = YAML::load(File.open("#{RAILS_ROOT}/config/sms_fu.yml")) - @@from_address = @config['from_address'] + @@from_address = @config['config']['from_address'] cattr_accessor :from_address def sms_message(recipient, message) diff --git a/templates/sms_fu.yml b/templates/sms_fu.yml index 5835f54..8ae0a0a 100644 --- a/templates/sms_fu.yml +++ b/templates/sms_fu.yml @@ -1,5 +1,6 @@ -from_address: noreply@domain.com - +config: + from_address: noreply@domain.com + carriers: # US Carriers alltell: @message.alltell.com @@ -10,6 +11,7 @@ carriers: boost: @myboostmobile.com cellularsouth: @csouth1.com metropcs: @mymetropcs.com + powertel: @ptel.net pscwireless: @sms.pscel.com qwest: @qwestmp.com southernlink: @page.southernlinc.com @@ -38,5 +40,3 @@ carriers: vodafone-jp-touhoku: @h.vodafone.ne.jp vodafone-jp-niigata: @h.vodafone.ne.jp vodafone-jp-toukai: @h.vodafone.ne.jp - -
\ No newline at end of file diff --git a/test/sms_fu_test.rb b/test/sms_fu_test.rb index 1b783ee..043763a 100644 --- a/test/sms_fu_test.rb +++ b/test/sms_fu_test.rb @@ -1,16 +1,18 @@ require 'test/unit' require 'sms_fu' -require 'sms_notifier' -require 'action_mailer' class SmsFuTest < Test::Unit::TestCase include SMSFu def test_validity_of_number - assert_raise(SMSFuException) { deliver_sms("123456789011","AT&T","Message") } + assert_raise(SMSFuException) { deliver_sms("456789011","AT&T","Message") } assert_equal("5555555555@txt.att.net", get_sms_address("1-555-555-5555","AT&T")) end + def test_international_number + assert_equal("+445555555555@txt.att.net", get_sms_address("+44-555-555-5555","AT&T")) + end + def test_handling_of_blank_message assert_raise(SMSFuException) { deliver_sms("1234567890","AT&T","") } end |
