blythedunham-sms_on_rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/Manifest +101 -0
  3. data/README +163 -0
  4. data/README.rdoc +211 -0
  5. data/Rakefile +76 -0
  6. data/app/controllers/admin/sms_on_rails/base_controller.rb +11 -0
  7. data/app/controllers/admin/sms_on_rails/drafts_controller.rb +75 -0
  8. data/app/controllers/admin/sms_on_rails/outbounds_controller.rb +117 -0
  9. data/app/controllers/admin/sms_on_rails/phone_carriers_controller.rb +85 -0
  10. data/app/controllers/admin/sms_on_rails/phone_numbers_controller.rb +101 -0
  11. data/app/controllers/sms_on_rails/creation_support.rb +99 -0
  12. data/app/controllers/sms_on_rails_controller.rb +14 -0
  13. data/app/helpers/admin/sms_on_rails/drafts_helper.rb +2 -0
  14. data/app/helpers/admin/sms_on_rails/phone_carriers_helper.rb +2 -0
  15. data/app/helpers/sms_on_rails/phone_numbers_helper.rb +9 -0
  16. data/app/helpers/sms_on_rails/sms_helper.rb +44 -0
  17. data/app/models/sms_on_rails/draft.rb +9 -0
  18. data/app/models/sms_on_rails/outbound.rb +17 -0
  19. data/app/models/sms_on_rails/phone_carrier.rb +14 -0
  20. data/app/models/sms_on_rails/phone_number.rb +8 -0
  21. data/app/views/admin/sms_on_rails/base/index.html.erb +5 -0
  22. data/app/views/admin/sms_on_rails/drafts/_show.html.erb +34 -0
  23. data/app/views/admin/sms_on_rails/drafts/edit.html.erb +36 -0
  24. data/app/views/admin/sms_on_rails/drafts/index.html.erb +32 -0
  25. data/app/views/admin/sms_on_rails/drafts/new.html.erb +34 -0
  26. data/app/views/admin/sms_on_rails/drafts/send_sms.html.erb +3 -0
  27. data/app/views/admin/sms_on_rails/drafts/show.html.erb +4 -0
  28. data/app/views/admin/sms_on_rails/outbounds/edit.html.erb +68 -0
  29. data/app/views/admin/sms_on_rails/outbounds/index.html.erb +37 -0
  30. data/app/views/admin/sms_on_rails/outbounds/new.html.erb +54 -0
  31. data/app/views/admin/sms_on_rails/outbounds/show.html.erb +69 -0
  32. data/app/views/admin/sms_on_rails/phone_carriers/edit.html.erb +24 -0
  33. data/app/views/admin/sms_on_rails/phone_carriers/index.html.erb +24 -0
  34. data/app/views/admin/sms_on_rails/phone_carriers/new.html.erb +22 -0
  35. data/app/views/admin/sms_on_rails/phone_carriers/show.html.erb +24 -0
  36. data/app/views/admin/sms_on_rails/phone_numbers/edit.html.erb +33 -0
  37. data/app/views/admin/sms_on_rails/phone_numbers/index.html.erb +28 -0
  38. data/app/views/admin/sms_on_rails/phone_numbers/new.html.erb +31 -0
  39. data/app/views/admin/sms_on_rails/phone_numbers/show.html.erb +32 -0
  40. data/app/views/layouts/sms_on_rails/basic.html.erb +26 -0
  41. data/app/views/sms_on_rails/_phone_carrier_form_item.html.erb +6 -0
  42. data/app/views/sms_on_rails/_send_sms.html.erb +33 -0
  43. data/app/views/sms_on_rails/index.html.erb +8 -0
  44. data/app/views/sms_on_rails/send_sms.html.erb +3 -0
  45. data/app/views/sms_on_rails/show.html.erb +29 -0
  46. data/config/routes.rb +19 -0
  47. data/db/data/fixtures/sms_phone_carriers.yml +110 -0
  48. data/db/migrate/sms_on_rails_carrier_tables.rb +9 -0
  49. data/db/migrate/sms_on_rails_model_tables.rb +48 -0
  50. data/db/migrate/sms_on_rails_phone_number_tables.rb +11 -0
  51. data/db/seed_data.rb +16 -0
  52. data/generators/sms_on_rails/USAGE +31 -0
  53. data/generators/sms_on_rails/commands/inserts.rb +63 -0
  54. data/generators/sms_on_rails/commands/timestamps.rb +33 -0
  55. data/generators/sms_on_rails/runners/add_all_models.rb +6 -0
  56. data/generators/sms_on_rails/runners/dependencies.rb +1 -0
  57. data/generators/sms_on_rails/runners/remove_all_models.rb +5 -0
  58. data/generators/sms_on_rails/runners/sms_on_rails_routes.rb +14 -0
  59. data/generators/sms_on_rails/sms_on_rails_generator.rb +255 -0
  60. data/generators/sms_on_rails/templates/configuration/clickatell.rb +6 -0
  61. data/generators/sms_on_rails/templates/configuration/email_gateway.rb +7 -0
  62. data/generators/sms_on_rails/templates/migrate/schema_migration.rb +15 -0
  63. data/generators/sms_on_rails/templates/migrate/sms_on_rails_update_phone_numbers.rb +40 -0
  64. data/generators/sms_on_rails/templates/phone_number_collision.rb +2 -0
  65. data/init.rb +3 -0
  66. data/install.rb +1 -0
  67. data/lib/sms_on_rails.rb +8 -0
  68. data/lib/sms_on_rails/activerecord_extensions/acts_as_deliverable.rb +92 -0
  69. data/lib/sms_on_rails/activerecord_extensions/acts_as_substitutable.rb +80 -0
  70. data/lib/sms_on_rails/activerecord_extensions/has_a_sms_service_provider.rb +101 -0
  71. data/lib/sms_on_rails/activerecord_extensions/lockable_record.rb +186 -0
  72. data/lib/sms_on_rails/all_models.rb +3 -0
  73. data/lib/sms_on_rails/model_support/draft.rb +178 -0
  74. data/lib/sms_on_rails/model_support/outbound.rb +136 -0
  75. data/lib/sms_on_rails/model_support/phone_carrier.rb +77 -0
  76. data/lib/sms_on_rails/model_support/phone_number.rb +248 -0
  77. data/lib/sms_on_rails/model_support/phone_number_associations.rb +13 -0
  78. data/lib/sms_on_rails/schema_helper.rb +51 -0
  79. data/lib/sms_on_rails/service_providers/base.rb +222 -0
  80. data/lib/sms_on_rails/service_providers/clickatell.rb +52 -0
  81. data/lib/sms_on_rails/service_providers/dummy.rb +19 -0
  82. data/lib/sms_on_rails/service_providers/email_gateway.rb +68 -0
  83. data/lib/sms_on_rails/service_providers/email_gateway_support/errors.rb +20 -0
  84. data/lib/sms_on_rails/service_providers/email_gateway_support/sms_mailer.rb +21 -0
  85. data/lib/sms_on_rails/service_providers/email_gateway_support/sms_mailer/sms_through_gateway.erb +6 -0
  86. data/lib/sms_on_rails/util/sms_error.rb +12 -0
  87. data/lib/smsonrails.rb +1 -0
  88. data/public/images/sms_on_rails/railsYoDawg.jpg +0 -0
  89. data/public/stylesheets/sms_on_rails.css +137 -0
  90. data/sms_on_rails.gemspec +32 -0
  91. data/tasks/sms_on_rails_tasks.rake +67 -0
  92. data/test/active_record_extensions/delivery_and_locking_test.rb +84 -0
  93. data/test/models/draft_test.rb +72 -0
  94. data/test/models/outbound_test.rb +89 -0
  95. data/test/models/phone_number_test.rb +131 -0
  96. data/test/run.rb +18 -0
  97. data/test/service_providers/abstract_test_support.rb +104 -0
  98. data/test/service_providers/clickatell_test.rb +39 -0
  99. data/test/service_providers/email_gateway_test.rb +30 -0
  100. data/test/test_helper.rb +24 -0
  101. data/uninstall.rb +1 -0
  102. metadata +187 -0
@@ -0,0 +1,21 @@
1
+ require 'action_mailer'
2
+ module SmsOnRails
3
+ module ServiceProviders
4
+ module EmailGatewaySupport
5
+ class SmsMailer < ::ActionMailer::Base
6
+ def sms_through_gateway(recipient, message, phone_options={})
7
+ recipients recipient
8
+ bcc phone_options[:bcc]
9
+ from phone_options[:sender]
10
+ subject phone_options[:subject]
11
+ body :message => message, :options => phone_options
12
+ template phone_options[:template] if phone_options[:template]
13
+ content_type 'text/plain'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ SmsOnRails::ServiceProviders::EmailGatewaySupport::SmsMailer.template_root = File.dirname(__FILE__) + '/../../../'
21
+ SmsOnRails::ServiceProviders::EmailGatewaySupport::SmsMailer.logger ||= ActiveRecord::Base.logger
@@ -0,0 +1,6 @@
1
+ <%-# This can be configured to specify the way the sms_message should look
2
+ #@sms contains the sms object if any
3
+ #@options contain additional settings for this message
4
+ #@options[:sms] contains the sms if any
5
+ #@message contains the message -%>
6
+ <%= @message %>
@@ -0,0 +1,12 @@
1
+ module SmsOnRails
2
+ class SmsError < Exception
3
+ attr_reader :sub_status
4
+ def initialize(msg, new_sub_status = nil)
5
+ super msg
6
+ @sub_status = new_sub_status
7
+ end
8
+ end
9
+
10
+ class FatalSmsError < SmsError
11
+ end
12
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'sms_on_rails')
@@ -0,0 +1,137 @@
1
+ /* SmsOnRails Stylin'
2
+ Copyright (c) 2009 Blythe Dunham
3
+ MIT-LICENSE MartiniWare
4
+ If you like it, buy yourself a martini.
5
+ If you hate it, send me a better stylesheet! */
6
+
7
+ .smsOnRailsHtml {
8
+ background-color: #DDDDFF;
9
+ -moz-border-radius: 15px;
10
+ -webkit-border-radius: 15px;
11
+ padding: 15px;
12
+ font-family: Verdana, Arial, Helvetica, sans-serif;
13
+ font-size: 14px;
14
+ color:#333333;
15
+ }
16
+
17
+ .smsOnRailsHtml h1 {
18
+ background-color: #2F8BBB;
19
+ blah: #3366FF;
20
+ color: #DDDDDD;
21
+ text-align: center;
22
+ padding: 20px;
23
+ -moz-border-radius: 15px;
24
+ -webkit-border-radius: 15px;
25
+ }
26
+
27
+ .smsOnRailsHtml h2 {
28
+ text-align: center;
29
+ }
30
+
31
+ /* Links Start */
32
+ .smsOnRailsHtml a, .smsOnRailsHtml a:link, .smsOnRailsHtml a:visited {
33
+ color: #2F8BBB;
34
+ text-decoration: none;
35
+ }
36
+ .smsOnRailsHtml a:hover, .smsOnRailsHtml a:active {
37
+ /*text-decoration: underline;*/
38
+ color: #000000;
39
+ background: none;
40
+ text-decoration: underline;
41
+ }
42
+
43
+ .smsOnRailsHtml table {
44
+ -moz-border-radius: 15px;
45
+ -webkit-border-radius: 15px;
46
+ padding: 5px;
47
+ border-collapse: collapse;
48
+ background-color: #EBEBEB;
49
+ }
50
+
51
+ .smsOnRailsHtml th.long {
52
+ width:100%;
53
+ }
54
+ .smsOnRailsHtml th.short {
55
+ width:2px;
56
+ }
57
+
58
+ .smsOnRailsHtml th {
59
+ padding: 3px;
60
+ border: 0px;
61
+ text-align: left;
62
+ color: black;
63
+ padding-right: 20px;
64
+ width:20%;
65
+ }
66
+
67
+ .smsOnRailsHtml tr.odd {
68
+ background-color: #EBEBEB;
69
+ width:100%;
70
+ }
71
+
72
+ .smsOnRailsHtml tr.even {
73
+ background-color: #FFFFFF;
74
+ width:100%;
75
+ }
76
+
77
+ .smsOnRailsHtml td {
78
+ padding: 3px;
79
+ }
80
+
81
+
82
+ .smsOnRailsHtml table a {
83
+ display: block;
84
+ width:100%;
85
+ height:100%;
86
+ }
87
+
88
+ .smsOnRailsHtml p {
89
+ padding: 0 25%;
90
+ }
91
+
92
+ .smsFlashNotice {
93
+ color: #00CC99;
94
+ }
95
+ /* ERROR MESSAGES */
96
+ .smsOnRailsHtml .fieldWithErrors {
97
+ padding: 0 25%;
98
+ display: table;
99
+ color:#FF9966;
100
+ }
101
+
102
+ .smsOnRailsHtml #errorExplanation {
103
+ width: 500px;
104
+ border: 2px solid #FF9966;
105
+ padding: 7px;
106
+ padding-bottom: 12px;
107
+ margin-bottom: 20px;
108
+ background-color: #EBEBEB;
109
+ margin-left:20%;
110
+ -moz-border-radius: 18px;
111
+ -webkit-border-radius: 18px;
112
+ }
113
+
114
+ .smsOnRailsHtml #errorExplanation h2 {
115
+ text-align: left;
116
+ font-weight: bold;
117
+ padding: 5px 5px 5px 15px;
118
+ font-size: 12px;
119
+ margin: -7px;
120
+ background-color: #FF9966;
121
+ color: #fff;
122
+ -moz-border-radius: 15px 15px 0 0;
123
+ -webkit-border-radius: 15px 15px 0 0;
124
+ }
125
+
126
+ .smsOnRailsHtml #errorExplanation p {
127
+ color: #FF9966;
128
+ margin-bottom: 0;
129
+ padding: 5px;
130
+ }
131
+
132
+ .smsOnRailsHtml #errorExplanation ul li {
133
+ font-size: 13px;
134
+ }
135
+ .smsOnRailsImage {
136
+ background-image:url(/images/sms_on_rails/yoDawg.jpg);
137
+ }
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{sms_on_rails}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Blythe Dunham"]
9
+ s.date = %q{2009-05-19}
10
+ s.description = %q{Integrate your application with SMS through Clickatell or the Email Gateways}
11
+ s.email = %q{blythe@snowgiraffe.com}
12
+ s.extra_rdoc_files = ["lib/sms_on_rails/activerecord_extensions/acts_as_deliverable.rb", "lib/sms_on_rails/activerecord_extensions/acts_as_substitutable.rb", "lib/sms_on_rails/activerecord_extensions/has_a_sms_service_provider.rb", "lib/sms_on_rails/activerecord_extensions/lockable_record.rb", "lib/sms_on_rails/all_models.rb", "lib/sms_on_rails/model_support/draft.rb", "lib/sms_on_rails/model_support/outbound.rb", "lib/sms_on_rails/model_support/phone_carrier.rb", "lib/sms_on_rails/model_support/phone_number.rb", "lib/sms_on_rails/model_support/phone_number_associations.rb", "lib/sms_on_rails/schema_helper.rb", "lib/sms_on_rails/service_providers/base.rb", "lib/sms_on_rails/service_providers/clickatell.rb", "lib/sms_on_rails/service_providers/dummy.rb", "lib/sms_on_rails/service_providers/email_gateway.rb", "lib/sms_on_rails/service_providers/email_gateway_support/errors.rb", "lib/sms_on_rails/service_providers/email_gateway_support/sms_mailer/sms_through_gateway.erb", "lib/sms_on_rails/service_providers/email_gateway_support/sms_mailer.rb", "lib/sms_on_rails/util/sms_error.rb", "lib/sms_on_rails.rb", "lib/smsonrails.rb", "README", "README.rdoc", "tasks/sms_on_rails_tasks.rake"]
13
+ s.files = ["app/controllers/admin/sms_on_rails/base_controller.rb", "app/controllers/admin/sms_on_rails/drafts_controller.rb", "app/controllers/admin/sms_on_rails/outbounds_controller.rb", "app/controllers/admin/sms_on_rails/phone_carriers_controller.rb", "app/controllers/admin/sms_on_rails/phone_numbers_controller.rb", "app/controllers/sms_on_rails/creation_support.rb", "app/controllers/sms_on_rails_controller.rb", "app/helpers/admin/sms_on_rails/drafts_helper.rb", "app/helpers/admin/sms_on_rails/phone_carriers_helper.rb", "app/helpers/sms_on_rails/phone_numbers_helper.rb", "app/helpers/sms_on_rails/sms_helper.rb", "app/models/sms_on_rails/draft.rb", "app/models/sms_on_rails/outbound.rb", "app/models/sms_on_rails/phone_carrier.rb", "app/models/sms_on_rails/phone_number.rb", "app/views/admin/sms_on_rails/base/index.html.erb", "app/views/admin/sms_on_rails/drafts/_show.html.erb", "app/views/admin/sms_on_rails/drafts/edit.html.erb", "app/views/admin/sms_on_rails/drafts/index.html.erb", "app/views/admin/sms_on_rails/drafts/new.html.erb", "app/views/admin/sms_on_rails/drafts/send_sms.html.erb", "app/views/admin/sms_on_rails/drafts/show.html.erb", "app/views/admin/sms_on_rails/outbounds/edit.html.erb", "app/views/admin/sms_on_rails/outbounds/index.html.erb", "app/views/admin/sms_on_rails/outbounds/new.html.erb", "app/views/admin/sms_on_rails/outbounds/show.html.erb", "app/views/admin/sms_on_rails/phone_carriers/edit.html.erb", "app/views/admin/sms_on_rails/phone_carriers/index.html.erb", "app/views/admin/sms_on_rails/phone_carriers/new.html.erb", "app/views/admin/sms_on_rails/phone_carriers/show.html.erb", "app/views/admin/sms_on_rails/phone_numbers/edit.html.erb", "app/views/admin/sms_on_rails/phone_numbers/index.html.erb", "app/views/admin/sms_on_rails/phone_numbers/new.html.erb", "app/views/admin/sms_on_rails/phone_numbers/show.html.erb", "app/views/layouts/sms_on_rails/basic.html.erb", "app/views/sms_on_rails/_phone_carrier_form_item.html.erb", "app/views/sms_on_rails/_send_sms.html.erb", "app/views/sms_on_rails/index.html.erb", "app/views/sms_on_rails/send_sms.html.erb", "app/views/sms_on_rails/show.html.erb", "config/routes.rb", "db/data/fixtures/sms_phone_carriers.yml", "db/migrate/sms_on_rails_carrier_tables.rb", "db/migrate/sms_on_rails_model_tables.rb", "db/migrate/sms_on_rails_phone_number_tables.rb", "db/seed_data.rb", "generators/sms_on_rails/commands/inserts.rb", "generators/sms_on_rails/commands/timestamps.rb", "generators/sms_on_rails/runners/add_all_models.rb", "generators/sms_on_rails/runners/dependencies.rb", "generators/sms_on_rails/runners/remove_all_models.rb", "generators/sms_on_rails/runners/sms_on_rails_routes.rb", "generators/sms_on_rails/sms_on_rails_generator.rb", "generators/sms_on_rails/templates/configuration/clickatell.rb", "generators/sms_on_rails/templates/configuration/email_gateway.rb", "generators/sms_on_rails/templates/migrate/schema_migration.rb", "generators/sms_on_rails/templates/migrate/sms_on_rails_update_phone_numbers.rb", "generators/sms_on_rails/templates/phone_number_collision.rb", "generators/sms_on_rails/USAGE", "init.rb", "install.rb", "lib/sms_on_rails/activerecord_extensions/acts_as_deliverable.rb", "lib/sms_on_rails/activerecord_extensions/acts_as_substitutable.rb", "lib/sms_on_rails/activerecord_extensions/has_a_sms_service_provider.rb", "lib/sms_on_rails/activerecord_extensions/lockable_record.rb", "lib/sms_on_rails/all_models.rb", "lib/sms_on_rails/model_support/draft.rb", "lib/sms_on_rails/model_support/outbound.rb", "lib/sms_on_rails/model_support/phone_carrier.rb", "lib/sms_on_rails/model_support/phone_number.rb", "lib/sms_on_rails/model_support/phone_number_associations.rb", "lib/sms_on_rails/schema_helper.rb", "lib/sms_on_rails/service_providers/base.rb", "lib/sms_on_rails/service_providers/clickatell.rb", "lib/sms_on_rails/service_providers/dummy.rb", "lib/sms_on_rails/service_providers/email_gateway.rb", "lib/sms_on_rails/service_providers/email_gateway_support/errors.rb", "lib/sms_on_rails/service_providers/email_gateway_support/sms_mailer/sms_through_gateway.erb", "lib/sms_on_rails/service_providers/email_gateway_support/sms_mailer.rb", "lib/sms_on_rails/util/sms_error.rb", "lib/sms_on_rails.rb", "lib/smsonrails.rb", "Manifest", "MIT-LICENSE", "public/images/sms_on_rails/railsYoDawg.jpg", "public/stylesheets/sms_on_rails.css", "Rakefile", "README", "README.rdoc", "sms_on_rails.gemspec", "tasks/sms_on_rails_tasks.rake", "test/active_record_extensions/delivery_and_locking_test.rb", "test/models/draft_test.rb", "test/models/outbound_test.rb", "test/models/phone_number_test.rb", "test/run.rb", "test/service_providers/abstract_test_support.rb", "test/service_providers/clickatell_test.rb", "test/service_providers/email_gateway_test.rb", "test/test_helper.rb", "uninstall.rb"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/blythedunham/smsonrails}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Sms_on_rails", "--main", "README"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{sms_on_rails}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{Integrate your application with SMS through Clickatell or the Email Gateways}
21
+ s.test_files = ["test/active_record_extensions/delivery_and_locking_test.rb", "test/models/draft_test.rb", "test/models/outbound_test.rb", "test/models/phone_number_test.rb", "test/service_providers/clickatell_test.rb", "test/service_providers/email_gateway_test.rb", "test/test_helper.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end
@@ -0,0 +1,67 @@
1
+ require 'active_support'
2
+ require File.dirname(__FILE__) + '/../lib/sms_on_rails/schema_helper'
3
+
4
+ namespace :sms do
5
+ desc 'Reset the Sms data'
6
+ task :reset => [ :teardown, :setup ]
7
+
8
+ desc 'Create Tables and seed them'
9
+ task :setup => [ :create_tables, :seed_tables ]
10
+
11
+ desc 'Teardown'
12
+ task :teardown => [:drop_tables]
13
+ schema_tables = %w(sms_on_rails_carrier_tables sms_on_rails_phone_number_tables sms_on_rails_model_tables)
14
+
15
+ [:create, :drop].each do |command|
16
+ schema_tables.each do |table|
17
+
18
+ desc "#{command.to_s.titleize} #{table.titleize}"
19
+ task "#{command}_#{table}".to_sym => :environment do
20
+ eval SmsOnRails::SchemaHelper.schema(command, table, :safe => true)
21
+ end
22
+
23
+ end
24
+ desc '#{command.to_s.titleize} All SMS database tables'
25
+ task "#{command}_tables".to_sym => schema_tables.collect{|t| "sms:#{command}_#{t}"}
26
+ end
27
+
28
+
29
+ desc 'Seed tables'
30
+ task :seed_tables => :environment do
31
+ puts "Seeding SMS tables..."
32
+ load File.dirname(__FILE__) + '/../db/seed_data.rb'
33
+ end
34
+
35
+ desc 'Create New Specialized Gateway Template'
36
+ task :create_email_template => :environment do
37
+ raise "Task unavailable to this database (no migration support)" unless ActiveRecord::Base.connection.supports_migrations?
38
+
39
+ default_path = 'sms_on_rails/service_providers/email_gateway_support/sms_mailer'
40
+ default_template_name = 'sms_through_gateway.erb'
41
+ dest_path = File.join(ActionMailer::Base.template_root, default_path)
42
+ FileUtils.mkdir_p(dest_path)
43
+
44
+ dest = File.join(dest_path, default_template_name)
45
+ unless File.exists?(dest)
46
+ src = File.join(File.dirname(__FILE__), '../lib', default_path, 'sms_through_gateway.erb')
47
+ FileUtils.cp(src, dest)
48
+ end
49
+
50
+ config = "\n# Place email gateway templates in the default view directory"
51
+ config << "\n# To configure your sms messages, edit file:"
52
+ config << "\n# #{dest.gsub(RAILS_ROOT, '')} "
53
+
54
+ #relative_root = File.expand_path(ActionMailer::Base.template_root.to_s)
55
+ #relative_root.gsub!(RAILS_ROOT+'/', '/..')
56
+ #config << "File.dirname(__FILE__) + #{relative_root.inspect}\n\n"
57
+ config << "\nSmsOnRails::ServiceProviders::EmailGatewaySupport::SmsMailer.template_root= "
58
+ config << "ActionMailer::Base.template_root\n\n"
59
+
60
+ File.open(File.join(RAILS_ROOT, 'config/environment.rb'), 'a') {|file| file.puts config }
61
+
62
+ puts "environment.rb has been updated to set your new template path."
63
+ puts "Please edit the template in the file:\n #{dest}"
64
+
65
+ end
66
+
67
+ end
@@ -0,0 +1,84 @@
1
+ require File.dirname(__FILE__)+'/../test_helper'
2
+
3
+ #require 'ruby-debug'
4
+
5
+ class SmsOnRails::Outbound < ActiveRecord::Base
6
+ def deliver_message_with_exception(options={})
7
+ raise Exception.new('asdf')
8
+ end
9
+ end
10
+
11
+ class SmsOnRails::DeliveryAndLockingTest < Test::Unit::TestCase
12
+
13
+ def setup
14
+ super
15
+ SmsOnRails::ServiceProviders::Base.default_service_provider = SmsOnRails::ServiceProviders::Dummy.instance
16
+ end
17
+
18
+ def test_failed_delivery_with_exception
19
+ SmsOnRails::Outbound.send :alias_method_chain, :deliver_message, :exception
20
+ SmsOnRails::Outbound.delete_all
21
+
22
+ sms = nil
23
+ assert_raises(Exception) {
24
+ sms = SmsOnRails::Outbound.send_immediately! 'hi', '2065552476'
25
+ }
26
+
27
+ sms = SmsOnRails::Outbound.find :first
28
+ assert(sms)
29
+
30
+ assert_equal('FAILED', sms.status)
31
+ #assert(sms.processed_on.to_i <= Time.now.to_i)
32
+ ensure
33
+ SmsOnRails::Outbound.send :alias_method, :deliver_message, :deliver_message_without_exception
34
+ end
35
+
36
+
37
+ def test_failed_delivery_with_errors
38
+ SmsOnRails::Outbound.send :alias_method_chain, :deliver_message, :exception
39
+ SmsOnRails::Outbound.delete_all
40
+
41
+ sms = SmsOnRails::Outbound.send_immediately 'hi', '2065552476'
42
+ assert(sms, "SHOULD create and SMS object")
43
+ assert(sms.errors.any?, "Expecting deliver errors.")
44
+
45
+ assert_equal(sms.errors.on(:base), 'Unable to send message.')
46
+ sms = SmsOnRails::Outbound.find :first
47
+ assert(sms)
48
+
49
+ assert_equal('FAILED', sms.status)
50
+ assert(sms.processed_on.to_i <= Time.now.to_i)
51
+ ensure
52
+ SmsOnRails::Outbound.send :alias_method, :deliver_message, :deliver_message_without_exception
53
+ end
54
+
55
+ def test_deliver_stale_record_should_raise_unlockable_error
56
+ SmsOnRails::Outbound.delete_all
57
+
58
+ #get the sms instance
59
+ sms = SmsOnRails::Outbound.create_sms 'hi', '2065552476'
60
+
61
+ #change the lock id
62
+ same_sms = SmsOnRails::Outbound.find :first
63
+ same_sms.notes = 'something fun'
64
+ same_sms.save!
65
+
66
+ #attempt to deliver should catch stale record and raise unable to lock
67
+ assert_raises(SmsOnRails::LockableRecord::UnableToLockRecord) { sms.deliver! }
68
+ end
69
+
70
+ def test_deliver_already_processed_record_should_raise_already_processed_error
71
+
72
+ SmsOnRails::Outbound.delete_all
73
+
74
+ #get the sms instance
75
+ sms = SmsOnRails::Outbound.create_sms 'hi', '2065552476'
76
+
77
+ sms.status = 'PROCESSING'
78
+ sms.save!
79
+
80
+ #should be unlockable because status is not set to NOT_PROCESSED
81
+ assert_raises(SmsOnRails::LockableRecord::AlreadyProcessed) { sms.deliver! }
82
+ end
83
+ end
84
+
@@ -0,0 +1,72 @@
1
+ require File.dirname(__FILE__)+'/../test_helper'
2
+
3
+ #require 'ruby-debug'
4
+
5
+ class SmsOnRails::DraftTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ super
9
+ SmsOnRails::PhoneNumber.delete_all
10
+ end
11
+
12
+ def test_create_draft_with_nested_params_with_existing_phone
13
+ phone = SmsOnRails::PhoneNumber.create!(:number => '12065557777')
14
+ test_create_draft_with_nested_params
15
+ end
16
+
17
+ def test_create_draft_with_nested_params
18
+ draft = SmsOnRails::Draft.create_sms(test_params)
19
+
20
+ validate_draft draft
21
+ end
22
+
23
+ def test_create_draft_with_exception
24
+ args = test_params.dup
25
+ args['outbounds_attributes']['0']['phone_number_attributes'].update('number' => 'ss' )
26
+ assert_raises(ActiveRecord::RecordInvalid) { SmsOnRails::Draft.create_sms!(args) }
27
+
28
+ end
29
+
30
+ def test_create_draft_with_nested_params_with_error
31
+ args = test_params.dup
32
+ args['outbounds_attributes']['0']['phone_number_attributes'].update('number' => 'ss' )
33
+
34
+ draft = SmsOnRails::Draft.create_sms(args)
35
+
36
+ assert(draft)
37
+ assert(draft.errors.any?)
38
+ assert(draft.new_record?)
39
+ assert('Test Draft', draft.message)
40
+
41
+ assert(draft.outbounds)
42
+ assert_equal(1, draft.outbounds.length)
43
+ assert('NOT PROCESSED', draft.outbounds.first.status)
44
+ assert(draft.outbounds.first.new_record?)
45
+
46
+ assert(draft.outbounds.first.phone_number)
47
+ assert(draft.outbounds.first.phone_number.new_record?)
48
+ assert('12065557777', draft.outbounds.first.phone_number.number)
49
+
50
+ end
51
+
52
+ def test_params
53
+ params = {"draft"=>{"deliver_after(1i)"=>"", "message"=>"Test Draft", "deliver_after(2i)"=>"", "outbounds_attributes"=>{"0"=>{"phone_number_attributes"=>{"number"=>"12065557777", "carrier_id"=>"5"}}}, "deliver_after(3i)"=>"", "deliver_after(4i)"=>"", "deliver_after(5i)"=>""}, "commit"=>"Send Sms", "authenticity_token"=>"XGchwHjmN2j77X27pgxhxOq/hOKWmouy27oMrPWhlUA=", "send_immediately"=>"true", "previous_action"=>"new"}
54
+ params['draft']
55
+ end
56
+
57
+ protected
58
+ def validate_draft(draft, options={})
59
+ assert(draft)
60
+ assert(!draft.new_record?)
61
+ assert('Test Draft', draft.message)
62
+
63
+ assert(draft.outbounds)
64
+ assert_equal(1, draft.outbounds.length)
65
+ assert('NOT PROCESSED', draft.outbounds.first.status)
66
+ assert(!draft.outbounds.first.new_record?)
67
+
68
+ assert(draft.outbounds.first.phone_number)
69
+ assert(!draft.outbounds.first.phone_number.new_record?)
70
+ assert('12065557777', draft.outbounds.first.phone_number.number)
71
+ end
72
+ end
@@ -0,0 +1,89 @@
1
+ require File.dirname(__FILE__)+'/../test_helper'
2
+
3
+ #require 'ruby-debug'
4
+
5
+ class SmsOnRails::OutboundTest < Test::Unit::TestCase
6
+
7
+ def test_outbound_create_sms_simple
8
+ SmsOnRails::Outbound.delete_all
9
+ sms = SmsOnRails::Outbound.create_sms 'hi', '2065552476'
10
+ assert(sms)
11
+ assert(sms.is_a?(ActiveRecord::Base))
12
+
13
+ validate_new_sms('12065552476', 'hi')
14
+ end
15
+
16
+
17
+ def test_outbound_create_sms_multiple
18
+ SmsOnRails::Outbound.delete_all
19
+ smses = SmsOnRails::Outbound.create_sms 'multi test', ['2065552476', '206.555.1234', '1(415)5551234']
20
+ assert(smses)
21
+ assert_equal(3, smses.length)
22
+
23
+ ['12065552476', '12065551234', '14155551234'].each do |number|
24
+ validate_new_sms(number, 'multi test')
25
+ end
26
+ end
27
+
28
+ def test_outbound_send_immediately
29
+ SmsOnRails::Outbound.delete_all
30
+ sms = SmsOnRails::Outbound.send_immediately 'hi', '2065552476'
31
+
32
+ sms = SmsOnRails::Outbound.find :first
33
+ assert(sms)
34
+ assert_equal('PROCESSED', sms.status)
35
+ assert(sms.processed_on.to_i <= Time.now.to_i)
36
+ end
37
+
38
+ def test_outbound_send_immediately_for_multiple
39
+ SmsOnRails::Outbound.delete_all
40
+ smses = SmsOnRails::Outbound.send_immediately 'hi', ['2065552476', '4155553456']
41
+
42
+ smses = SmsOnRails::Outbound.find :all
43
+ assert(smses.length, 2)
44
+ smses.each{|sms| assert('PROCESSED', sms.status)
45
+ assert(sms.processed_on.to_i <= Time.now.to_i)
46
+ assert_equal(SmsOnRails::ServiceProviders::Base.default_service_provider,
47
+ sms.sms_service_provider)
48
+ }
49
+ end
50
+
51
+
52
+ def test_outbound_substitution
53
+ SmsOnRails::Outbound.delete_all
54
+ time = Time.now
55
+ sms = SmsOnRails::Outbound.create_sms '$TIME$', '2065552476'
56
+ time_sub = Time.parse sms.full_message
57
+ assert(time_sub.to_i >= time.to_i)
58
+
59
+ sms = SmsOnRails::Outbound.create_sms 'Format phone: $PHONE_NUMBER_DIGITS$ end', '2065552476'
60
+ assert_equal('Format phone: 12065552476 end', sms.full_message)
61
+
62
+ sms = SmsOnRails::Outbound.create_sms 'Format phone human: $PHONE_NUMBER$ end', '2065552476'
63
+ assert_equal('Format phone human: (206) 555-2476 end', sms.full_message)
64
+
65
+ end
66
+
67
+ def test_send_to_invalid_number
68
+ assert_raise(ActiveRecord::RecordInvalid){
69
+ sms = SmsOnRails::Outbound.create_sms 'some test message #{Time.now.to_s(:db)}', 'ss', :find => {:create => :create!}
70
+ }
71
+ end
72
+
73
+ protected
74
+
75
+ def validate_new_sms(phone_number, message)
76
+ phone = SmsOnRails::PhoneNumber.find_by_number phone_number
77
+ assert(phone)
78
+
79
+ outbound = SmsOnRails::Outbound.find_by_sms_phone_number_id phone
80
+ assert(outbound)
81
+ assert(outbound.draft)
82
+ assert(SmsOnRails::ServiceProviders::Dummy.provider_id, outbound.sms_service_provider_id)
83
+ assert_nil(outbound.sms_service_provider)
84
+ assert_equal(message, outbound.draft.message)
85
+ assert_equal('NOT_PROCESSED', outbound.status)
86
+ outbound
87
+ end
88
+ end
89
+