postageapp 1.2.0 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +14 -1
- data/README.md +1 -1
- data/generators/postageapp/postageapp_generator.rb +3 -3
- data/generators/postageapp/templates/postageapp_tasks.rake +57 -24
- data/lib/generators/postageapp/postageapp_generator.rb +6 -6
- data/lib/postageapp.rb +3 -1
- data/lib/postageapp/configuration.rb +52 -40
- data/lib/postageapp/failed_request.rb +4 -4
- data/lib/postageapp/mailer.rb +3 -86
- data/lib/postageapp/mailer/mailer_4.rb +7 -10
- data/lib/postageapp/request.rb +124 -11
- data/lib/postageapp/response.rb +4 -1
- data/lib/postageapp/utils.rb +27 -22
- data/lib/postageapp/version.rb +1 -1
- data/postageapp.gemspec +15 -5
- data/script/with +116 -0
- data/test/configuration_test.rb +1 -1
- data/test/failed_request_test.rb +32 -17
- data/test/gemfiles/Gemfile.rails-2.3.x +5 -1
- data/test/gemfiles/Gemfile.rails-3.0.x +6 -1
- data/test/gemfiles/Gemfile.rails-3.1.x +1 -1
- data/test/gemfiles/Gemfile.rails-3.2.x +2 -1
- data/test/gemfiles/Gemfile.rails-4.0.x +2 -1
- data/test/gemfiles/Gemfile.rails-4.1.x +2 -1
- data/test/gemfiles/Gemfile.rails-4.2.x +2 -1
- data/test/gemfiles/Gemfile.ruby +1 -0
- data/test/helper.rb +12 -5
- data/test/live_test.rb +36 -17
- data/test/mailer_2_test.rb +4 -5
- data/test/mailer_3_test.rb +8 -6
- data/test/mailer_4_test.rb +14 -6
- data/test/request_test.rb +8 -6
- data/test/response_test.rb +2 -1
- metadata +35 -14
- checksums.yaml +0 -7
data/test/configuration_test.rb
CHANGED
@@ -20,7 +20,7 @@ class ConfigurationTest < MiniTest::Test
|
|
20
20
|
assert_equal nil, config.project_root
|
21
21
|
assert_equal 'production', config.environment
|
22
22
|
assert_equal nil, config.logger
|
23
|
-
assert_equal '
|
23
|
+
assert_equal 'Ruby', config.framework
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_initialization_overrides
|
data/test/failed_request_test.rb
CHANGED
@@ -8,23 +8,25 @@ class FailedRequestTest < MiniTest::Test
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_store_and_initialize
|
11
|
-
assert_match
|
11
|
+
assert_match(/.*?\/tmp\/postageapp_failed_requests/, PostageApp::FailedRequest.store_path)
|
12
12
|
|
13
13
|
request = PostageApp::Request.new(:send_message, {
|
14
|
-
:
|
14
|
+
headers: {
|
15
15
|
'from' => 'sender@test.test',
|
16
16
|
'subject' => 'Test Message'
|
17
17
|
},
|
18
|
-
:
|
19
|
-
:
|
18
|
+
recipients: 'test@test.test',
|
19
|
+
content: {
|
20
20
|
'text/plain' => 'text content',
|
21
21
|
'text/html' => 'html content'
|
22
22
|
}
|
23
23
|
})
|
24
24
|
|
25
25
|
assert PostageApp::FailedRequest.store(request)
|
26
|
+
|
26
27
|
file_path = File.join(PostageApp::FailedRequest.store_path, request.uid)
|
27
|
-
|
28
|
+
|
29
|
+
assert File.exist?(file_path)
|
28
30
|
|
29
31
|
stored_request = PostageApp::FailedRequest.initialize_request(request.uid)
|
30
32
|
|
@@ -54,6 +56,7 @@ class FailedRequestTest < MiniTest::Test
|
|
54
56
|
|
55
57
|
def test_store_with_no_file_path_defined
|
56
58
|
PostageApp.configuration.project_root = nil
|
59
|
+
|
57
60
|
assert !PostageApp::FailedRequest.store_path
|
58
61
|
assert !PostageApp::FailedRequest.store('something')
|
59
62
|
end
|
@@ -62,12 +65,12 @@ class FailedRequestTest < MiniTest::Test
|
|
62
65
|
mock_failed_send
|
63
66
|
|
64
67
|
request = PostageApp::Request.new(:send_message, {
|
65
|
-
:
|
68
|
+
headers: {
|
66
69
|
'from' => 'sender@test.test',
|
67
70
|
'subject' => 'Test Message'
|
68
71
|
},
|
69
|
-
:
|
70
|
-
:
|
72
|
+
recipients: 'test@test.test',
|
73
|
+
content: {
|
71
74
|
'text/plain' => 'text content',
|
72
75
|
'text/html' => 'html content'
|
73
76
|
}
|
@@ -77,44 +80,56 @@ class FailedRequestTest < MiniTest::Test
|
|
77
80
|
assert response.fail?
|
78
81
|
|
79
82
|
file_path = File.join(PostageApp::FailedRequest.store_path, request.uid)
|
80
|
-
assert File.
|
83
|
+
assert File.exist?(file_path)
|
81
84
|
|
82
85
|
mock_successful_send
|
83
86
|
|
84
87
|
request = PostageApp::Request.new(:get_project_info)
|
85
88
|
|
86
|
-
message_receipt_response = stub(
|
89
|
+
message_receipt_response = stub(
|
90
|
+
:fail? => false,
|
91
|
+
:ok? => false,
|
92
|
+
:not_found? => true
|
93
|
+
)
|
94
|
+
|
87
95
|
message_receipt_request = stub(:send => message_receipt_response)
|
88
|
-
|
96
|
+
|
97
|
+
PostageApp::Request.stubs(:new).with do |a,b|
|
98
|
+
a == :get_message_receipt
|
99
|
+
end.returns(message_receipt_request)
|
89
100
|
|
90
101
|
response = request.send
|
102
|
+
|
91
103
|
assert response.ok?
|
92
104
|
|
93
|
-
assert !File.
|
105
|
+
assert !File.exist?(file_path)
|
94
106
|
end
|
95
107
|
|
96
108
|
def test_resend_all_failure
|
97
109
|
mock_failed_send
|
98
110
|
request = PostageApp::Request.new(:send_message, {
|
99
|
-
:
|
111
|
+
headers: {
|
100
112
|
'from' => 'sender@test.test',
|
101
113
|
'subject' => 'Test Message'
|
102
114
|
},
|
103
|
-
:
|
104
|
-
:
|
115
|
+
recipients: 'test@test.test',
|
116
|
+
content: {
|
105
117
|
'text/plain' => 'text content',
|
106
118
|
'text/html' => 'html content'
|
107
119
|
}
|
108
120
|
})
|
109
121
|
|
110
122
|
response = request.send
|
123
|
+
|
111
124
|
assert response.fail?
|
125
|
+
|
112
126
|
file_path = File.join(PostageApp::FailedRequest.store_path, request.uid)
|
113
|
-
|
127
|
+
|
128
|
+
assert File.exist?(file_path)
|
114
129
|
|
115
130
|
# Forcing to resend. Should quit right away as we can't connect
|
116
131
|
PostageApp::FailedRequest.resend_all
|
117
132
|
|
118
|
-
assert File.
|
133
|
+
assert File.exist?(file_path)
|
119
134
|
end
|
120
135
|
end
|
@@ -1,12 +1,16 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
+
# rubygems 1.8.30
|
4
|
+
|
5
|
+
gem 'rails', '~> 2.3.0'
|
6
|
+
|
3
7
|
gem 'json'
|
4
8
|
gem 'mail'
|
9
|
+
gem 'mime-types', '2.99.1' # Locked for 1.9 compatibility
|
5
10
|
|
6
11
|
group :test do
|
7
12
|
gem 'rake'
|
8
13
|
gem 'minitest'
|
9
14
|
gem 'minitest-reporters'
|
10
|
-
gem 'rails', '~> 2.3.0'
|
11
15
|
gem 'mocha'
|
12
16
|
end
|
@@ -1,12 +1,17 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
+
# rubygems 1.8.30
|
4
|
+
|
5
|
+
gem 'bundler', '1.0.22'
|
6
|
+
gem 'rails', '~> 3.0.0'
|
7
|
+
|
3
8
|
gem 'json'
|
4
9
|
gem 'mail'
|
10
|
+
gem 'mime-types', '~> 1.16' # Rails 3.0.x dependency
|
5
11
|
|
6
12
|
group :test do
|
7
13
|
gem 'rake'
|
8
14
|
gem 'minitest'
|
9
15
|
gem 'minitest-reporters'
|
10
|
-
gem 'rails', '~> 3.0.0'
|
11
16
|
gem 'mocha'
|
12
17
|
end
|
data/test/gemfiles/Gemfile.ruby
CHANGED
data/test/helper.rb
CHANGED
@@ -21,6 +21,12 @@ require 'postageapp/mailer'
|
|
21
21
|
require 'mocha/setup'
|
22
22
|
require 'with_environment'
|
23
23
|
|
24
|
+
# This fixes an issue in Rails 3.2.22.2 where HashWithIndifferentAccess isn't
|
25
|
+
# being loaded properly during testing.
|
26
|
+
if (defined?(ActiveSupport) and !defined?(HashWithIndifferentAccess))
|
27
|
+
require 'active_support/hash_with_indifferent_access'
|
28
|
+
end
|
29
|
+
|
24
30
|
class MiniTest::Test
|
25
31
|
include WithEnvironment
|
26
32
|
|
@@ -67,12 +73,12 @@ class MiniTest::Test
|
|
67
73
|
def mock_successful_send(status = 'ok')
|
68
74
|
Net::HTTP.any_instance.stubs(:post).returns(Net::HTTPResponse.new(nil, nil, nil))
|
69
75
|
Net::HTTPResponse.any_instance.stubs(:body).returns({
|
70
|
-
:
|
71
|
-
:
|
72
|
-
:
|
76
|
+
response: {
|
77
|
+
uid: 'sha1hashuid23456789012345678901234567890',
|
78
|
+
status: status
|
73
79
|
},
|
74
|
-
:
|
75
|
-
:
|
80
|
+
data: {
|
81
|
+
message: { id: 999 }
|
76
82
|
}
|
77
83
|
}.to_json)
|
78
84
|
end
|
@@ -84,6 +90,7 @@ class MiniTest::Test
|
|
84
90
|
# Briefly substitutes a new object in place of an existing constant.
|
85
91
|
def const_replace(name, object)
|
86
92
|
original = Object.const_defined?(name) && Object.const_get(name)
|
93
|
+
|
87
94
|
Object.send(:remove_const, name) if (original)
|
88
95
|
Object.const_set(name, object)
|
89
96
|
|
data/test/live_test.rb
CHANGED
@@ -9,9 +9,9 @@ class LiveTest < MiniTest::Test
|
|
9
9
|
super
|
10
10
|
|
11
11
|
PostageApp.configure do |config|
|
12
|
-
config.secure
|
13
|
-
config.host
|
14
|
-
config.api_key
|
12
|
+
config.secure = false
|
13
|
+
config.host = 'api.postageapp.local'
|
14
|
+
config.api_key = 'PROJECT_API_KEY'
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -21,55 +21,74 @@ class LiveTest < MiniTest::Test
|
|
21
21
|
|
22
22
|
assert_equal 'PostageApp::Response', response.class.name
|
23
23
|
assert_equal 'ok', response.status
|
24
|
-
assert_match
|
24
|
+
assert_match(/^\w{40}$/, response.uid)
|
25
25
|
assert_equal nil, response.message
|
26
|
-
assert_equal
|
27
|
-
|
28
|
-
|
26
|
+
assert_equal(
|
27
|
+
{
|
28
|
+
'methods' => 'get_account_info, get_message_receipt, get_method_list, get_project_info, send_message'
|
29
|
+
},
|
30
|
+
response.data
|
31
|
+
)
|
29
32
|
end
|
30
33
|
|
31
34
|
def test_request_send_message
|
32
35
|
request = PostageApp::Request.new(:send_message, {
|
33
|
-
:
|
36
|
+
headers: {
|
34
37
|
'from' => 'sender@example.com',
|
35
38
|
'subject' => 'Test Message'
|
36
39
|
},
|
37
|
-
:
|
38
|
-
:
|
40
|
+
recipients: 'recipient@example.net',
|
41
|
+
content: {
|
39
42
|
'text/plain' => 'text content',
|
40
43
|
'text/html' => 'html content'
|
41
44
|
}
|
42
45
|
})
|
46
|
+
|
43
47
|
response = request.send
|
48
|
+
|
44
49
|
assert_equal 'PostageApp::Response', response.class.name
|
45
50
|
assert_equal 'ok', response.status
|
46
|
-
|
51
|
+
|
52
|
+
assert_match(/^\w{40}$/, response.uid)
|
47
53
|
assert_equal nil, response.message
|
48
|
-
assert_match
|
54
|
+
assert_match(/\d+/, response.data['message']['id'].to_s)
|
55
|
+
|
56
|
+
receipt = PostageApp::Request.new(
|
57
|
+
:get_message_receipt,
|
58
|
+
uid: response.uid
|
59
|
+
).send
|
49
60
|
|
50
|
-
receipt = PostageApp::Request.new(:get_message_receipt, :uid => response.uid).send
|
51
61
|
assert receipt.ok?
|
52
62
|
|
53
|
-
receipt = PostageApp::Request.new(
|
63
|
+
receipt = PostageApp::Request.new(
|
64
|
+
:get_message_receipt,
|
65
|
+
uid: 'bogus'
|
66
|
+
).send
|
67
|
+
|
54
68
|
assert receipt.not_found?
|
55
69
|
end
|
56
70
|
|
57
71
|
def test_request_non_existant_method
|
58
72
|
request = PostageApp::Request.new(:non_existant)
|
73
|
+
|
59
74
|
response = request.send
|
75
|
+
|
60
76
|
assert_equal 'PostageApp::Response', response.class.name
|
61
77
|
assert_equal 'internal_server_error', response.status
|
62
|
-
assert_match
|
63
|
-
|
78
|
+
assert_match(/\A\w{40}$/, response.uid)
|
79
|
+
assert_match(/\ANo action responded to non_existant/, response.message)
|
64
80
|
assert_equal nil, response.data
|
65
81
|
end
|
66
82
|
|
67
83
|
# Testable under ruby 1.9.2 Probably OK in production too... Probably
|
68
84
|
# Lunchtime reading: http://ph7spot.com/musings/system-timer
|
69
85
|
def test_request_timeout
|
70
|
-
PostageApp.configuration.host = '
|
86
|
+
PostageApp.configuration.host = '127.0.0.254'
|
87
|
+
|
71
88
|
request = PostageApp::Request.new(:get_method_list)
|
89
|
+
|
72
90
|
response = request.send
|
91
|
+
|
73
92
|
assert_equal 'PostageApp::Response', response.class.name
|
74
93
|
assert_equal 'fail', response.status
|
75
94
|
end
|
data/test/mailer_2_test.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require File.expand_path('helper', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
# tests for ActionMailer bundled with Rails 2
|
4
3
|
class Mailer2Test < MiniTest::Test
|
5
4
|
require_action_mailer(2) do
|
6
5
|
require File.expand_path('mailer/action_mailer_2/notifier', File.dirname(__FILE__))
|
@@ -19,7 +18,7 @@ class Mailer2Test < MiniTest::Test
|
|
19
18
|
assert mail = Notifier.create_with_no_content
|
20
19
|
|
21
20
|
assert_equal 'recipient@example.net', mail.arguments['recipients']
|
22
|
-
assert_equal
|
21
|
+
assert_equal({ 'from' => 'sender@example.com', 'subject' => 'Test Email' }, mail.arguments['headers'])
|
23
22
|
assert mail.arguments['content'].blank?
|
24
23
|
end
|
25
24
|
|
@@ -77,9 +76,9 @@ class Mailer2Test < MiniTest::Test
|
|
77
76
|
assert_equal 'custom_uid', mail.uid
|
78
77
|
assert_equal 'custom_api_key', mail.api_key
|
79
78
|
assert_equal 'test-template', mail.arguments['template']
|
80
|
-
assert_equal
|
81
|
-
assert_equal
|
82
|
-
'test1@example.net' => { 'name' => 'Test 1'}}
|
79
|
+
assert_equal({ 'variable' => 'value' }, mail.arguments['variables'])
|
80
|
+
assert_equal({ 'test2@example.net' => { 'name' => 'Test 2'},
|
81
|
+
'test1@example.net' => { 'name' => 'Test 1'}}, mail.arguments['recipients'])
|
83
82
|
assert_equal 'text content', mail.arguments['content']['text/plain']
|
84
83
|
assert_equal 'html content', mail.arguments['content']['text/html']
|
85
84
|
end
|
data/test/mailer_3_test.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require File.expand_path('helper', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
# tests for ActionMailer bundled with Rails 3
|
4
3
|
class Mailer3Test < MiniTest::Test
|
5
4
|
require_action_mailer(3) do
|
6
5
|
require File.expand_path('mailer/action_mailer_3/notifier', File.dirname(__FILE__))
|
@@ -72,13 +71,16 @@ class Mailer3Test < MiniTest::Test
|
|
72
71
|
|
73
72
|
args = args['arguments']
|
74
73
|
|
75
|
-
assert_equal
|
76
|
-
|
77
|
-
|
78
|
-
|
74
|
+
assert_equal(
|
75
|
+
{
|
76
|
+
'test1@example.net' => { 'name' => 'Test 1' },
|
77
|
+
'test2@example.net' => { 'name' => 'Test 2' }
|
78
|
+
},
|
79
|
+
args['recipients']
|
80
|
+
)
|
79
81
|
|
80
82
|
assert_equal 'test-template', args['template']
|
81
|
-
assert_equal
|
83
|
+
assert_equal({ 'variable' => 'value' }, args['variables'])
|
82
84
|
assert_equal 'CustomValue1', args['headers']['CustomHeader1']
|
83
85
|
assert_equal 'CustomValue2', args['headers']['CustomHeader2']
|
84
86
|
assert_equal 'text content', args['content']['text/plain']
|