action_smser 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +61 -9
- data/app/controllers/action_smser/delivery_reports_controller.rb +21 -4
- data/app/models/action_smser/delivery_report.rb +35 -2
- data/app/views/action_smser/delivery_reports/index.html.erb +46 -62
- data/app/views/action_smser/delivery_reports/list.html.erb +52 -0
- data/app/views/layouts/action_smser/delivery_reports.html.erb +7 -2
- data/config/routes.rb +3 -1
- data/db/migrate/20120102215215_create_action_smser_delivery_reports.rb +4 -0
- data/lib/action_smser.rb +12 -3
- data/lib/action_smser/base.rb +15 -8
- data/lib/action_smser/delivery_methods/nexmo.rb +67 -0
- data/lib/action_smser/delivery_methods/simple_http.rb +5 -3
- data/lib/action_smser/version.rb +1 -1
- data/test/dummy/app/mailers/hello_smser.rb +5 -0
- data/test/dummy/config/initializers/action_smser.rb +11 -0
- data/test/dummy/config/initializers/git_ignored_passwords.rb +5 -0
- data/test/dummy/db/production.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +1 -14
- data/test/dummy/log/development.log +44 -0
- data/test/dummy/log/production.log +1 -0
- data/test/dummy/log/test.log +17502 -0
- data/test/functional/action_smser/delivery_reports_controller_test.rb +35 -10
- data/test/unit/action_smser/base_test.rb +12 -2
- data/test/unit/action_smser/delivery_methods/nexmo_test.rb +93 -0
- data/test/unit/action_smser/delivery_methods/simple_http_test.rb +0 -4
- data/test/unit/action_smser/delivery_report_test.rb +44 -0
- metadata +16 -6
@@ -23,6 +23,15 @@ class ActionSmser::DeliveryReportsControllerTest < ActionController::TestCase
|
|
23
23
|
|
24
24
|
return processable_array
|
25
25
|
end
|
26
|
+
|
27
|
+
def self.after_gateway_commit(delivery_reports)
|
28
|
+
return true
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
setup do
|
34
|
+
ActionSmser.delivery_options[:gateway_commit_observers] = []
|
26
35
|
end
|
27
36
|
|
28
37
|
test "gateway_commit with existing dr" do
|
@@ -30,13 +39,16 @@ class ActionSmser::DeliveryReportsControllerTest < ActionController::TestCase
|
|
30
39
|
@dr = ActionSmser::DeliveryReport.create(:msg_id => @msg_id, :status => 'ORIGINAL_STATUS')
|
31
40
|
|
32
41
|
ActionSmser.delivery_options[:gateway_commit] = {'test_gateway' => SmsTestSetup}
|
42
|
+
ActionSmser.gateway_commit_observer_add(SmsTestSetup)
|
43
|
+
|
44
|
+
SmsTestSetup.expects(:after_gateway_commit).once.with(){|var| var.is_a?(Array) && var.first.is_a?(ActionSmser::DeliveryReport)}
|
33
45
|
|
34
46
|
get 'gateway_commit', :use_route => :action_smser, :gateway => 'test_gateway',
|
35
47
|
"DeliveryReport"=>{"message"=>{"id"=>@msg_id, "donedate"=>"2012/01/03 14:20:45", "sentdate"=>"2012/01/03 14:20:40", "status"=>"DELIVERED"}}
|
36
48
|
|
37
49
|
|
38
50
|
assert_response :success
|
39
|
-
assert @response.body.downcase.include?("update"), "should have
|
51
|
+
assert @response.body.downcase.include?("update"), "should have responsed about saving"
|
40
52
|
@dr.reload
|
41
53
|
assert_equal "DELIVERED", @dr.status
|
42
54
|
end
|
@@ -89,30 +101,43 @@ class ActionSmser::DeliveryReportsControllerTest < ActionController::TestCase
|
|
89
101
|
assert_template nil
|
90
102
|
end
|
91
103
|
|
92
|
-
test "index with
|
104
|
+
test "index with admin_access lambda with right login info" do
|
105
|
+
default = ActionSmser.delivery_options[:admin_access]
|
106
|
+
ActionSmser.delivery_options[:admin_access] = SmsTestSetup
|
93
107
|
2.times do
|
94
108
|
ActionSmser::DeliveryReport.create(:msg_id => "idtest_#{rand(10)}")
|
95
109
|
end
|
96
|
-
|
110
|
+
session[:admin_logged] = true
|
97
111
|
get 'index', :use_route => :action_smser
|
112
|
+
|
98
113
|
assert_response :success
|
99
114
|
assert_template :index
|
115
|
+
|
116
|
+
ActionSmser.delivery_options[:admin_access] = default
|
117
|
+
|
100
118
|
end
|
101
119
|
|
102
|
-
|
103
|
-
|
104
|
-
ActionSmser.delivery_options[:admin_access] = SmsTestSetup
|
120
|
+
|
121
|
+
test "index with always enabled admin" do
|
105
122
|
2.times do
|
106
123
|
ActionSmser::DeliveryReport.create(:msg_id => "idtest_#{rand(10)}")
|
107
124
|
end
|
108
|
-
|
125
|
+
ActionSmser::DeliveryReportsController.any_instance.stubs(:admin_access_only).returns(true)
|
109
126
|
get 'index', :use_route => :action_smser
|
110
|
-
|
111
127
|
assert_response :success
|
112
128
|
assert_template :index
|
129
|
+
end
|
113
130
|
|
114
|
-
|
115
|
-
|
131
|
+
test "list with always enabled admin" do
|
132
|
+
2.times do
|
133
|
+
ActionSmser::DeliveryReport.create(:msg_id => "idtest_#{rand(10)}")
|
134
|
+
end
|
135
|
+
ActionSmser::DeliveryReportsController.any_instance.stubs(:admin_access_only).returns(true)
|
136
|
+
get 'list', :use_route => :action_smser
|
137
|
+
assert_response :success
|
138
|
+
assert_template :list
|
116
139
|
end
|
117
140
|
|
141
|
+
|
142
|
+
|
118
143
|
end
|
@@ -7,9 +7,14 @@ class ActionSmser::BaseTest < ActiveSupport::TestCase
|
|
7
7
|
sms(:to => to, :from => from, :body => body)
|
8
8
|
end
|
9
9
|
|
10
|
+
def before_delivery
|
11
|
+
return true
|
12
|
+
end
|
13
|
+
|
10
14
|
def after_delivery(result)
|
11
|
-
|
15
|
+
return true
|
12
16
|
end
|
17
|
+
|
13
18
|
end
|
14
19
|
|
15
20
|
setup do
|
@@ -65,7 +70,12 @@ class ActionSmser::BaseTest < ActiveSupport::TestCase
|
|
65
70
|
assert_equal ActionSmser::DeliveryMethods::TestArray, @sms.delivery_method
|
66
71
|
end
|
67
72
|
|
68
|
-
test "
|
73
|
+
test "before delivery should be called if it's present" do
|
74
|
+
@sms.expects(:before_delivery).once
|
75
|
+
assert @sms.deliver
|
76
|
+
end
|
77
|
+
|
78
|
+
test "after delivery should be called if it's present" do
|
69
79
|
@sms.expects(:after_delivery).once
|
70
80
|
assert @sms.deliver
|
71
81
|
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class ActionSmser::NexmoTest < ActiveSupport::TestCase
|
5
|
+
class MockSms<ActionSmser::Base
|
6
|
+
def basic_sms(to, from, body)
|
7
|
+
sms(:to => to, :from => from, :body => body)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
setup do
|
12
|
+
@receivers = ["555123555", "123555123"]
|
13
|
+
@sender = "555666"
|
14
|
+
@body = "Body with ääkköset end"
|
15
|
+
@sms = MockSms.basic_sms(@receivers, @sender, @body)
|
16
|
+
|
17
|
+
@sms.delivery_options[:delivery_method] = :nexmo
|
18
|
+
@sms.delivery_options[:nexmo] = {:username => 'user', :password => 'pass'}
|
19
|
+
assert_equal ActionSmser::DeliveryMethods::Nexmo, @sms.delivery_method, "cant run tests, wrong delivery method"
|
20
|
+
|
21
|
+
http_mock = stub(
|
22
|
+
:body => '{"message-count":"1","messages":[{"message-price":"0.02500000","status":"0","message-id":"0778DE88","remaining-balance":"1.77500000"}]}')
|
23
|
+
ActionSmser::DeliveryMethods::Nexmo.stubs(:deliver_http_request).returns(http_mock)
|
24
|
+
end
|
25
|
+
|
26
|
+
test "should be able to deliver" do
|
27
|
+
@sms_delivery = @sms.deliver
|
28
|
+
assert @sms_delivery
|
29
|
+
assert_equal 1, @sms_delivery.count
|
30
|
+
end
|
31
|
+
|
32
|
+
test "with saving delivery_reports" do
|
33
|
+
@sms.delivery_options[:save_delivery_reports] = true
|
34
|
+
@delivery_reports_count = ActionSmser::DeliveryReport.count
|
35
|
+
|
36
|
+
http_mock = stub(
|
37
|
+
:body => '{"message-count":"1","messages":[{"message-price":"0.02500000","status":"0","message-id":"0778DE88","remaining-balance":"1.77500000"},{"error-text":"Message rejected by upstream path","message-price":"0.02500000","status":"6","message-id":"0778D302","remaining-balance":"1.87500000"}]}')
|
38
|
+
ActionSmser::DeliveryMethods::Nexmo.stubs(:deliver_http_request).returns(http_mock)
|
39
|
+
|
40
|
+
@sms_delivery = @sms.deliver
|
41
|
+
|
42
|
+
assert @sms_delivery.is_a?(Array)
|
43
|
+
assert @sms_delivery.first.is_a?(ActionSmser::DeliveryReport), "should return delivery report array"
|
44
|
+
|
45
|
+
assert_equal @delivery_reports_count + 2, ActionSmser::DeliveryReport.count, "should have saved 2 delivery reports"
|
46
|
+
|
47
|
+
@dr1 = @sms_delivery.first
|
48
|
+
assert_equal "nexmo", @dr1.gateway
|
49
|
+
assert_equal "555123555", @dr1.to, "receiver wrong"
|
50
|
+
assert_equal "LOCAL_SENT", @dr1.status
|
51
|
+
|
52
|
+
@dr2 = @sms_delivery.last
|
53
|
+
assert_equal "123555123", @dr2.to, "receiver wrong"
|
54
|
+
assert_equal "0778D302", @dr2.msg_id, "id wrong"
|
55
|
+
assert_equal "SENT_ERROR_6", @dr2.status
|
56
|
+
end
|
57
|
+
|
58
|
+
test "gateway process_delivery_report(params)" do
|
59
|
+
@msg_id = "msg_id_asdf"
|
60
|
+
|
61
|
+
result_array = ActionSmser::DeliveryMethods::Nexmo.process_delivery_report(
|
62
|
+
{"messageId" => @msg_id, "status" => "EXPIRED"} )
|
63
|
+
|
64
|
+
assert_equal @msg_id, result_array.first['msg_id']
|
65
|
+
assert_equal "EXPIRED", result_array.first['status']
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# curl -is "http://rest.nexmo.com/sms/json?username=...&password=...&from=ActionSmser&to=...&text=msg"
|
71
|
+
NEXMO_ERROR_RESPONSE_BODY='{"message-count":"1","messages":[{"error-text":"Message rejected by upstream path","message-price":"0.02500000","status":"6","message-id":"0778D302","remaining-balance":"1.87500000"}]}'
|
72
|
+
NEXMO_ERROR_RESPONSE=<<eos
|
73
|
+
HTTP/1.1 200 OK
|
74
|
+
Cache-Control: max-age=1
|
75
|
+
Content-Type: application/json;charset=ISO-8859-1
|
76
|
+
Transfer-Encoding: chunked
|
77
|
+
Server: Jetty(7.5.1.v20110908)
|
78
|
+
|
79
|
+
{"message-count":"1","messages":[{"error-text":"Message rejected by upstream path","message-price":"0.02500000","status":"6","message-id":"0778D302","remaining-balance":"1.87500000"}]}
|
80
|
+
eos
|
81
|
+
NEXMO_OK_RESPONSE_BODY='{"message-count":"1","messages":[{"message-price":"0.02500000","status":"0","message-id":"0778DE88","remaining-balance":"1.77500000"}]}'
|
82
|
+
NEXMO_OK_RESPONSE=<<eos
|
83
|
+
HTTP/1.1 200 OK
|
84
|
+
Cache-Control: max-age=1
|
85
|
+
Content-Type: application/json;charset=ISO-8859-1
|
86
|
+
Transfer-Encoding: chunked
|
87
|
+
Server: Jetty(7.5.1.v20110908)
|
88
|
+
|
89
|
+
{"message-count":"1","messages":[{"message-price":"0.02500000","status":"0","message-id":"0778DE88","remaining-balance":"1.77500000"}]}
|
90
|
+
eos
|
91
|
+
|
92
|
+
|
93
|
+
end
|
@@ -45,8 +45,4 @@ class ActionSmser::SimpleHttpTest < ActiveSupport::TestCase
|
|
45
45
|
assert_equal "id_6666", @dr.msg_id, "id wrong"
|
46
46
|
end
|
47
47
|
|
48
|
-
# There are better frameworks for testing http requests
|
49
|
-
# http://railscasts.com/episodes/276-testing-time-web-requests
|
50
|
-
# https://github.com/chrisk/fakeweb
|
51
|
-
|
52
48
|
end
|
@@ -10,6 +10,7 @@ class ActionSmser::DeliveryReportTest < ActiveSupport::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
setup do
|
13
|
+
ActionSmser.delivery_options[:save_delivery_reports] = false
|
13
14
|
@receivers = ["555123555", "", "123555123"]
|
14
15
|
@sender = "555666"
|
15
16
|
@body = "Body with ääkköset end"
|
@@ -51,4 +52,47 @@ class ActionSmser::DeliveryReportTest < ActiveSupport::TestCase
|
|
51
52
|
assert @dr.save
|
52
53
|
end
|
53
54
|
|
55
|
+
test "to_sms" do
|
56
|
+
@dr = ActionSmser::DeliveryReport.create_from_sms(@sms, "123", "msg_id_a")
|
57
|
+
|
58
|
+
@dr = ActionSmser::DeliveryReport.find(@dr.id)
|
59
|
+
new_sms = @dr.to_sms
|
60
|
+
|
61
|
+
assert_equal @sender, @dr.from, "from info wrong"
|
62
|
+
assert_equal "123", @dr.to, "to info wrong"
|
63
|
+
assert_equal @body, @dr.body, "body info wrong"
|
64
|
+
assert_equal @sms.sms_type, @dr.sms_type
|
65
|
+
end
|
66
|
+
|
67
|
+
test "re_deliver with simple_http" do
|
68
|
+
ActionSmser.delivery_options[:save_delivery_reports] = true
|
69
|
+
|
70
|
+
@dr = ActionSmser::DeliveryReport.create_from_sms(@sms, "123", "msg_id_a")
|
71
|
+
@dr.gateway = "some_delivery"
|
72
|
+
@dr.save
|
73
|
+
|
74
|
+
@dr = ActionSmser::DeliveryReport.find(@dr.id)
|
75
|
+
|
76
|
+
result = @dr.re_deliver(:test_array)
|
77
|
+
|
78
|
+
assert @dr.re_delivered
|
79
|
+
assert ActionSmser::DeliveryReport.find(@dr.id).re_delivered?
|
80
|
+
|
81
|
+
assert result.is_a?(Array)
|
82
|
+
assert result.first.is_a?(ActionSmser::Base)
|
83
|
+
assert result.second.is_a?(Array)
|
84
|
+
assert result.second.first.is_a?(ActionSmser::DeliveryReport)
|
85
|
+
|
86
|
+
@dr_redelivery = ActionSmser::DeliveryReport.last
|
87
|
+
|
88
|
+
assert_equal @sender, @dr_redelivery.from, "from info wrong"
|
89
|
+
assert_equal "#{@sms.sms_type}.re_delivery", @dr_redelivery.sms_type
|
90
|
+
|
91
|
+
assert_equal @dr.id, @dr_redelivery.re_delivery_of_delivery_report_id, "should set new reports re_delivery_of_delivery_report_id"
|
92
|
+
assert_equal @dr.re_deliveries.first, @dr_redelivery
|
93
|
+
assert_equal @dr, @dr_redelivery.re_delivery_of
|
94
|
+
end
|
95
|
+
|
96
|
+
|
54
97
|
end
|
98
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_smser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Olli Huotari
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01-
|
18
|
+
date: 2012-01-20 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rails
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
version: "0"
|
61
61
|
type: :development
|
62
62
|
version_requirements: *id003
|
63
|
-
description: Simple way to use SMS (Short Message Service) in the same way as ActionMailer
|
63
|
+
description: ActionSmser == SMS && ActionMailer. Simple way to use SMS (Short Message Service) in the same way as ActionMailer. Includes also delivery reports and easy way to add custom gateways (simple http and nexmo by default).
|
64
64
|
email:
|
65
65
|
- olli.huotari@iki.fi
|
66
66
|
executables: []
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- app/controllers/action_smser/application_controller.rb
|
74
74
|
- app/controllers/action_smser/delivery_reports_controller.rb
|
75
75
|
- app/views/action_smser/delivery_reports/index.html.erb
|
76
|
+
- app/views/action_smser/delivery_reports/list.html.erb
|
76
77
|
- app/views/layouts/action_smser/delivery_reports.html.erb
|
77
78
|
- app/models/action_smser/delivery_report.rb
|
78
79
|
- app/assets/javascripts/action_smser/delivery_reports.js
|
@@ -85,6 +86,7 @@ files:
|
|
85
86
|
- lib/action_smser/engine.rb
|
86
87
|
- lib/action_smser/delivery_methods/simple_http.rb
|
87
88
|
- lib/action_smser/delivery_methods/test_array.rb
|
89
|
+
- lib/action_smser/delivery_methods/nexmo.rb
|
88
90
|
- lib/action_smser/version.rb
|
89
91
|
- lib/action_smser/base.rb
|
90
92
|
- lib/action_smser.rb
|
@@ -95,12 +97,14 @@ files:
|
|
95
97
|
- test/action_smser_test.rb
|
96
98
|
- test/dummy/script/rails
|
97
99
|
- test/dummy/db/development.sqlite3
|
100
|
+
- test/dummy/db/production.sqlite3
|
98
101
|
- test/dummy/db/test.sqlite3
|
99
102
|
- test/dummy/db/schema.rb
|
100
103
|
- test/dummy/config/boot.rb
|
101
104
|
- test/dummy/config/locales/en.yml
|
102
105
|
- test/dummy/config/initializers/secret_token.rb
|
103
106
|
- test/dummy/config/initializers/mime_types.rb
|
107
|
+
- test/dummy/config/initializers/action_smser.rb
|
104
108
|
- test/dummy/config/initializers/inflections.rb
|
105
109
|
- test/dummy/config/initializers/session_store.rb
|
106
110
|
- test/dummy/config/initializers/wrap_parameters.rb
|
@@ -120,6 +124,7 @@ files:
|
|
120
124
|
- test/dummy/public/404.html
|
121
125
|
- test/dummy/log/development.log
|
122
126
|
- test/dummy/log/test.log
|
127
|
+
- test/dummy/log/production.log
|
123
128
|
- test/dummy/app/helpers/application_helper.rb
|
124
129
|
- test/dummy/app/mailers/hello_smser.rb
|
125
130
|
- test/dummy/app/controllers/application_controller.rb
|
@@ -130,6 +135,7 @@ files:
|
|
130
135
|
- test/test_helper.rb
|
131
136
|
- test/unit/action_smser/delivery_methods/simple_http_test.rb
|
132
137
|
- test/unit/action_smser/delivery_methods/test_array_test.rb
|
138
|
+
- test/unit/action_smser/delivery_methods/nexmo_test.rb
|
133
139
|
- test/unit/action_smser/base_test.rb
|
134
140
|
- test/unit/action_smser/delivery_report_test.rb
|
135
141
|
- test/functional/action_smser/delivery_reports_controller_test.rb
|
@@ -165,18 +171,20 @@ rubyforge_project:
|
|
165
171
|
rubygems_version: 1.8.6
|
166
172
|
signing_key:
|
167
173
|
specification_version: 3
|
168
|
-
summary: Simple way to use SMS (Short Message Service) in the same way as ActionMailer
|
174
|
+
summary: ActionSmser == SMS && ActionMailer. Simple way to use SMS (Short Message Service) in the same way as ActionMailer. Includes also delivery reports and easy way to add custom gateways (simple http and nexmo by default).
|
169
175
|
test_files:
|
170
176
|
- test/integration/navigation_test.rb
|
171
177
|
- test/action_smser_test.rb
|
172
178
|
- test/dummy/script/rails
|
173
179
|
- test/dummy/db/development.sqlite3
|
180
|
+
- test/dummy/db/production.sqlite3
|
174
181
|
- test/dummy/db/test.sqlite3
|
175
182
|
- test/dummy/db/schema.rb
|
176
183
|
- test/dummy/config/boot.rb
|
177
184
|
- test/dummy/config/locales/en.yml
|
178
185
|
- test/dummy/config/initializers/secret_token.rb
|
179
186
|
- test/dummy/config/initializers/mime_types.rb
|
187
|
+
- test/dummy/config/initializers/action_smser.rb
|
180
188
|
- test/dummy/config/initializers/inflections.rb
|
181
189
|
- test/dummy/config/initializers/session_store.rb
|
182
190
|
- test/dummy/config/initializers/wrap_parameters.rb
|
@@ -196,6 +204,7 @@ test_files:
|
|
196
204
|
- test/dummy/public/404.html
|
197
205
|
- test/dummy/log/development.log
|
198
206
|
- test/dummy/log/test.log
|
207
|
+
- test/dummy/log/production.log
|
199
208
|
- test/dummy/app/helpers/application_helper.rb
|
200
209
|
- test/dummy/app/mailers/hello_smser.rb
|
201
210
|
- test/dummy/app/controllers/application_controller.rb
|
@@ -206,6 +215,7 @@ test_files:
|
|
206
215
|
- test/test_helper.rb
|
207
216
|
- test/unit/action_smser/delivery_methods/simple_http_test.rb
|
208
217
|
- test/unit/action_smser/delivery_methods/test_array_test.rb
|
218
|
+
- test/unit/action_smser/delivery_methods/nexmo_test.rb
|
209
219
|
- test/unit/action_smser/base_test.rb
|
210
220
|
- test/unit/action_smser/delivery_report_test.rb
|
211
221
|
- test/functional/action_smser/delivery_reports_controller_test.rb
|