postageapp 1.0.24 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.travis.yml +13 -12
- data/Gemfile +6 -1
- data/LICENSE +1 -1
- data/README.md +122 -70
- data/Rakefile +19 -4
- data/generators/postageapp/postageapp_generator.rb +5 -7
- data/lib/generators/postageapp/postageapp_generator.rb +15 -9
- data/lib/postageapp.rb +42 -36
- data/lib/postageapp/configuration.rb +34 -21
- data/lib/postageapp/failed_request.rb +60 -36
- data/lib/postageapp/logger.rb +6 -7
- data/lib/postageapp/mail.rb +3 -0
- data/lib/postageapp/mail/arguments.rb +75 -0
- data/lib/postageapp/mail/delivery_method.rb +32 -0
- data/lib/postageapp/mail/extensions.rb +21 -0
- data/lib/postageapp/mailer.rb +72 -20
- data/lib/postageapp/mailer/mailer_2.rb +65 -22
- data/lib/postageapp/mailer/mailer_3.rb +45 -28
- data/lib/postageapp/mailer/mailer_4.rb +72 -40
- data/lib/postageapp/rails/rails.rb +17 -7
- data/lib/postageapp/rails/railtie.rb +22 -7
- data/lib/postageapp/request.rb +67 -43
- data/lib/postageapp/response.rb +11 -8
- data/lib/postageapp/utils.rb +11 -3
- data/lib/postageapp/version.rb +2 -2
- data/postageapp.gemspec +13 -11
- data/rails/init.rb +1 -1
- data/test/configuration_test.rb +35 -38
- data/test/failed_request_test.rb +33 -18
- data/test/gemfiles/Gemfile.rails-2.3.x +4 -1
- data/test/gemfiles/Gemfile.rails-3.0.x +4 -1
- data/test/gemfiles/Gemfile.rails-3.1.x +4 -1
- data/test/gemfiles/Gemfile.rails-3.2.x +4 -1
- data/test/gemfiles/Gemfile.rails-4.0.x +4 -1
- data/test/gemfiles/Gemfile.rails-4.1.x +12 -0
- data/test/gemfiles/Gemfile.rails-4.2.x +12 -0
- data/test/gemfiles/Gemfile.ruby +11 -0
- data/test/helper.rb +52 -33
- data/test/live_test.rb +11 -8
- data/test/mail_delivery_method_test.rb +161 -0
- data/test/mailer/action_mailer_2/notifier.rb +37 -28
- data/test/mailer/action_mailer_3/notifier.rb +28 -22
- data/test/mailer_2_test.rb +20 -16
- data/test/mailer_3_test.rb +16 -22
- data/test/mailer_4_test.rb +28 -28
- data/test/mailer_helper_methods_test.rb +17 -14
- data/test/postageapp_test.rb +8 -9
- data/test/rails_initialization_test.rb +14 -14
- data/test/request_test.rb +35 -35
- data/test/response_test.rb +20 -19
- data/test/travis_test.rb +168 -0
- data/test/with_environment.rb +27 -0
- metadata +23 -17
data/test/failed_request_test.rb
CHANGED
@@ -1,28 +1,33 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('helper', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
class FailedRequestTest <
|
3
|
+
class FailedRequestTest < MiniTest::Test
|
4
4
|
def setup
|
5
5
|
super
|
6
|
-
|
6
|
+
|
7
|
+
PostageApp.configuration.project_root = File.dirname(__FILE__)
|
7
8
|
end
|
8
9
|
|
9
10
|
def test_store_and_initialize
|
10
11
|
assert_match /.*?\/tmp\/postageapp_failed_requests/, PostageApp::FailedRequest.store_path
|
11
12
|
|
12
13
|
request = PostageApp::Request.new(:send_message, {
|
13
|
-
:headers
|
14
|
-
|
14
|
+
:headers => {
|
15
|
+
'from' => 'sender@test.test',
|
16
|
+
'subject' => 'Test Message'
|
17
|
+
},
|
15
18
|
:recipients => 'test@test.test',
|
16
|
-
:content
|
17
|
-
'text/plain'
|
18
|
-
'text/html'
|
19
|
+
:content => {
|
20
|
+
'text/plain' => 'text content',
|
21
|
+
'text/html' => 'html content'
|
19
22
|
}
|
20
23
|
})
|
24
|
+
|
21
25
|
assert PostageApp::FailedRequest.store(request)
|
22
26
|
file_path = File.join(PostageApp::FailedRequest.store_path, request.uid)
|
23
27
|
assert File.exists?(file_path)
|
24
28
|
|
25
29
|
stored_request = PostageApp::FailedRequest.initialize_request(request.uid)
|
30
|
+
|
26
31
|
assert stored_request.is_a?(PostageApp::Request)
|
27
32
|
assert_equal request.url, stored_request.url
|
28
33
|
assert_equal request.uid, stored_request.uid
|
@@ -35,12 +40,15 @@ class FailedRequestTest < Minitest::Test
|
|
35
40
|
|
36
41
|
def test_initialize_requests_with_bad_file
|
37
42
|
file_path = File.join(PostageApp::FailedRequest.store_path, '1234567890')
|
43
|
+
|
38
44
|
FileUtils.touch(file_path)
|
45
|
+
|
39
46
|
assert !PostageApp::FailedRequest.initialize_request('1234567890')
|
40
47
|
end
|
41
48
|
|
42
49
|
def test_store_for_wrong_call_type
|
43
50
|
request = PostageApp::Request.new(:get_project_info)
|
51
|
+
|
44
52
|
assert !PostageApp::FailedRequest.store(request)
|
45
53
|
end
|
46
54
|
|
@@ -54,16 +62,20 @@ class FailedRequestTest < Minitest::Test
|
|
54
62
|
mock_failed_send
|
55
63
|
|
56
64
|
request = PostageApp::Request.new(:send_message, {
|
57
|
-
:headers
|
58
|
-
|
65
|
+
:headers => {
|
66
|
+
'from' => 'sender@test.test',
|
67
|
+
'subject' => 'Test Message'
|
68
|
+
},
|
59
69
|
:recipients => 'test@test.test',
|
60
|
-
:content
|
61
|
-
'text/plain'
|
62
|
-
'text/html'
|
70
|
+
:content => {
|
71
|
+
'text/plain' => 'text content',
|
72
|
+
'text/html' => 'html content'
|
63
73
|
}
|
64
74
|
})
|
75
|
+
|
65
76
|
response = request.send
|
66
77
|
assert response.fail?
|
78
|
+
|
67
79
|
file_path = File.join(PostageApp::FailedRequest.store_path, request.uid)
|
68
80
|
assert File.exists?(file_path)
|
69
81
|
|
@@ -84,14 +96,17 @@ class FailedRequestTest < Minitest::Test
|
|
84
96
|
def test_resend_all_failure
|
85
97
|
mock_failed_send
|
86
98
|
request = PostageApp::Request.new(:send_message, {
|
87
|
-
:headers
|
88
|
-
|
99
|
+
:headers => {
|
100
|
+
'from' => 'sender@test.test',
|
101
|
+
'subject' => 'Test Message'
|
102
|
+
},
|
89
103
|
:recipients => 'test@test.test',
|
90
|
-
:content
|
91
|
-
'text/plain'
|
92
|
-
'text/html'
|
104
|
+
:content => {
|
105
|
+
'text/plain' => 'text content',
|
106
|
+
'text/html' => 'html content'
|
93
107
|
}
|
94
108
|
})
|
109
|
+
|
95
110
|
response = request.send
|
96
111
|
assert response.fail?
|
97
112
|
file_path = File.join(PostageApp::FailedRequest.store_path, request.uid)
|
data/test/helper.rb
CHANGED
@@ -3,48 +3,72 @@ require 'rubygems'
|
|
3
3
|
gem 'minitest'
|
4
4
|
require 'minitest/autorun'
|
5
5
|
|
6
|
+
gem 'minitest-reporters'
|
7
|
+
require 'minitest/reporters'
|
8
|
+
|
9
|
+
Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)
|
10
|
+
|
6
11
|
require 'fileutils'
|
7
12
|
|
8
13
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
14
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
10
15
|
|
16
|
+
require 'mail'
|
17
|
+
|
11
18
|
require 'postageapp'
|
12
19
|
require 'postageapp/mailer'
|
13
20
|
|
14
21
|
require 'mocha/setup'
|
22
|
+
require 'with_environment'
|
23
|
+
|
24
|
+
class MiniTest::Test
|
25
|
+
include WithEnvironment
|
26
|
+
|
27
|
+
def self.require_action_mailer(version)
|
28
|
+
if (defined?(ActionMailer))
|
29
|
+
if (ActionMailer::VERSION::MAJOR == version)
|
30
|
+
return yield
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
define_method(:test_skipped) do
|
35
|
+
skip("Not testing against ActionMailer #{version}.x")
|
36
|
+
end
|
37
|
+
end
|
15
38
|
|
16
|
-
class Minitest::Test
|
17
39
|
def setup
|
18
40
|
# Resetting to default configuration
|
19
41
|
|
20
42
|
PostageApp.configure do |config|
|
21
|
-
config.api_key
|
22
|
-
config.secure
|
23
|
-
config.protocol
|
24
|
-
config.host
|
25
|
-
config.port
|
26
|
-
config.proxy_host
|
27
|
-
config.proxy_port
|
28
|
-
config.proxy_user
|
29
|
-
config.proxy_pass
|
30
|
-
config.http_open_timeout
|
43
|
+
config.api_key = '1234567890abcdef'
|
44
|
+
config.secure = true
|
45
|
+
config.protocol = 'https'
|
46
|
+
config.host = 'api.postageapp.com'
|
47
|
+
config.port = 443
|
48
|
+
config.proxy_host = nil
|
49
|
+
config.proxy_port = nil
|
50
|
+
config.proxy_user = nil
|
51
|
+
config.proxy_pass = nil
|
52
|
+
config.http_open_timeout = 5
|
31
53
|
config.http_read_timeout = 10
|
32
54
|
config.recipient_override = nil
|
33
55
|
config.requests_to_resend = %w( send_message )
|
34
|
-
config.project_root
|
35
|
-
config.environment
|
36
|
-
config.logger
|
37
|
-
config.framework
|
56
|
+
config.project_root = File.expand_path('../', __FILE__)
|
57
|
+
config.environment = 'production'
|
58
|
+
config.logger = nil
|
59
|
+
config.framework = 'undefined framework'
|
38
60
|
end
|
39
61
|
|
40
|
-
ActionMailer
|
62
|
+
if (defined?(ActionMailer))
|
63
|
+
ActionMailer::Base.deliveries.clear
|
64
|
+
end
|
41
65
|
end
|
42
66
|
|
43
67
|
def mock_successful_send(status = 'ok')
|
44
68
|
Net::HTTP.any_instance.stubs(:post).returns(Net::HTTPResponse.new(nil, nil, nil))
|
45
69
|
Net::HTTPResponse.any_instance.stubs(:body).returns({
|
46
70
|
:response => {
|
47
|
-
:uid
|
71
|
+
:uid => 'sha1hashuid23456789012345678901234567890',
|
48
72
|
:status => status
|
49
73
|
},
|
50
74
|
:data => {
|
@@ -56,22 +80,17 @@ class Minitest::Test
|
|
56
80
|
def mock_failed_send
|
57
81
|
Net::HTTP.any_instance.stubs(:post).returns(nil)
|
58
82
|
end
|
59
|
-
end
|
60
83
|
|
61
|
-
#
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
def define_constant(name, value)
|
74
|
-
Object.const_set(name, value)
|
75
|
-
@defined_constants << name
|
84
|
+
# Briefly substitutes a new object in place of an existing constant.
|
85
|
+
def const_replace(name, object)
|
86
|
+
original = Object.const_defined?(name) && Object.const_get(name)
|
87
|
+
Object.send(:remove_const, name) if (original)
|
88
|
+
Object.const_set(name, object)
|
89
|
+
|
90
|
+
yield
|
91
|
+
|
92
|
+
ensure
|
93
|
+
Object.send(:remove_const, name)
|
94
|
+
Object.const_set(name, original)
|
76
95
|
end
|
77
96
|
end
|
data/test/live_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require File.expand_path('
|
1
|
+
require File.expand_path('helper', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
class LiveTest <
|
3
|
+
class LiveTest < MiniTest::Test
|
4
4
|
# Note: Need access to a live PostageApp.com account
|
5
5
|
# See helper.rb to set host / api key
|
6
6
|
|
@@ -18,6 +18,7 @@ class LiveTest < Minitest::Test
|
|
18
18
|
def test_request_get_method_list
|
19
19
|
request = PostageApp::Request.new(:get_method_list)
|
20
20
|
response = request.send
|
21
|
+
|
21
22
|
assert_equal 'PostageApp::Response', response.class.name
|
22
23
|
assert_equal 'ok', response.status
|
23
24
|
assert_match /^\w{40}$/, response.uid
|
@@ -29,12 +30,14 @@ class LiveTest < Minitest::Test
|
|
29
30
|
|
30
31
|
def test_request_send_message
|
31
32
|
request = PostageApp::Request.new(:send_message, {
|
32
|
-
:headers
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
33
|
+
:headers => {
|
34
|
+
'from' => 'sender@example.com',
|
35
|
+
'subject' => 'Test Message'
|
36
|
+
},
|
37
|
+
:recipients => 'recipient@example.net',
|
38
|
+
:content => {
|
39
|
+
'text/plain' => 'text content',
|
40
|
+
'text/html' => 'html content'
|
38
41
|
}
|
39
42
|
})
|
40
43
|
response = request.send
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require File.expand_path('helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class MailerDeliveryTest < MiniTest::Test
|
4
|
+
def setup
|
5
|
+
PostageApp::Mail::DeliveryMethod.deliveries.clear
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_text
|
9
|
+
mail = Mail.new do
|
10
|
+
from 'test@example.com'
|
11
|
+
to 'recipient@example.net'
|
12
|
+
subject 'Example message being sent through Mail'
|
13
|
+
body 'Example body text.'
|
14
|
+
|
15
|
+
# add_file :filename => 'somefile.png', :content => File.read('/somefile.png')
|
16
|
+
end
|
17
|
+
|
18
|
+
mail.delivery_method :postageapp, api_key: false
|
19
|
+
|
20
|
+
mail.deliver
|
21
|
+
|
22
|
+
api_call = PostageApp::Mail::DeliveryMethod.deliveries.pop
|
23
|
+
|
24
|
+
expected = [
|
25
|
+
:send_message,
|
26
|
+
{
|
27
|
+
'content' => {
|
28
|
+
'text/plain' => 'Example body text.'
|
29
|
+
},
|
30
|
+
'headers' => {
|
31
|
+
'From' => 'test@example.com',
|
32
|
+
'Subject' => 'Example message being sent through Mail'
|
33
|
+
},
|
34
|
+
'recipients' => [ 'recipient@example.net' ]
|
35
|
+
}
|
36
|
+
]
|
37
|
+
|
38
|
+
assert_equal expected, api_call
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_html
|
42
|
+
mail = Mail.new do
|
43
|
+
from 'test@example.com'
|
44
|
+
to 'recipient@example.net'
|
45
|
+
subject 'Example message being sent through Mail'
|
46
|
+
body '<p>Example body HTML text.</p>'
|
47
|
+
|
48
|
+
content_type 'text/html'
|
49
|
+
end
|
50
|
+
|
51
|
+
mail.delivery_method :postageapp, api_key: false
|
52
|
+
|
53
|
+
mail.deliver
|
54
|
+
|
55
|
+
api_call = PostageApp::Mail::DeliveryMethod.deliveries.pop
|
56
|
+
|
57
|
+
expected = [
|
58
|
+
:send_message,
|
59
|
+
{
|
60
|
+
'content' => {
|
61
|
+
'text/html' => '<p>Example body HTML text.</p>'
|
62
|
+
},
|
63
|
+
'headers' => {
|
64
|
+
'From' => 'test@example.com',
|
65
|
+
'Subject' => 'Example message being sent through Mail'
|
66
|
+
},
|
67
|
+
'recipients' => [ 'recipient@example.net' ]
|
68
|
+
}
|
69
|
+
]
|
70
|
+
|
71
|
+
assert_equal expected, api_call
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_text_body_with_attachment
|
75
|
+
mail = Mail.new do
|
76
|
+
from 'test@example.com'
|
77
|
+
to 'recipient@example.net'
|
78
|
+
subject 'Example message being sent through Mail'
|
79
|
+
|
80
|
+
body "Plain text"
|
81
|
+
|
82
|
+
add_file :filename => 'test.txt', :content => 'Test text file.'
|
83
|
+
end
|
84
|
+
|
85
|
+
mail.delivery_method :postageapp, api_key: false
|
86
|
+
|
87
|
+
mail.deliver
|
88
|
+
|
89
|
+
api_call = PostageApp::Mail::DeliveryMethod.deliveries.pop
|
90
|
+
|
91
|
+
expected = [
|
92
|
+
:send_message,
|
93
|
+
{
|
94
|
+
'content' => {
|
95
|
+
'text/plain' => 'Plain text'
|
96
|
+
},
|
97
|
+
'headers' => {
|
98
|
+
'From' => 'test@example.com',
|
99
|
+
'Subject' => 'Example message being sent through Mail'
|
100
|
+
},
|
101
|
+
'attachments' => {
|
102
|
+
'test.txt' => {
|
103
|
+
'content' => Base64.encode64('Test text file.'),
|
104
|
+
'content_type' => 'text/plain; filename=test.txt'
|
105
|
+
}
|
106
|
+
},
|
107
|
+
'recipients' => [ 'recipient@example.net' ]
|
108
|
+
}
|
109
|
+
]
|
110
|
+
|
111
|
+
assert_equal expected, api_call
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_html_body_with_attachment
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_html_and_text
|
118
|
+
mail = Mail.new do
|
119
|
+
from 'test@example.com'
|
120
|
+
to 'recipient@example.net'
|
121
|
+
subject 'Example message being sent through Mail'
|
122
|
+
|
123
|
+
text_part do
|
124
|
+
body "Plain text"
|
125
|
+
end
|
126
|
+
|
127
|
+
html_part do
|
128
|
+
# Mail 2.2.20 requires a manual declaration of MIME type. Newer
|
129
|
+
# versions handle this correctly.
|
130
|
+
content_type 'text/html'
|
131
|
+
body "<p>HTML text</p>"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
mail.delivery_method :postageapp, api_key: false
|
136
|
+
|
137
|
+
mail.deliver
|
138
|
+
|
139
|
+
api_call = PostageApp::Mail::DeliveryMethod.deliveries.pop
|
140
|
+
|
141
|
+
expected = [
|
142
|
+
:send_message,
|
143
|
+
{
|
144
|
+
'content' => {
|
145
|
+
'text/plain' => 'Plain text',
|
146
|
+
'text/html' => '<p>HTML text</p>'
|
147
|
+
},
|
148
|
+
'headers' => {
|
149
|
+
'From' => 'test@example.com',
|
150
|
+
'Subject' => 'Example message being sent through Mail'
|
151
|
+
},
|
152
|
+
'recipients' => [ 'recipient@example.net' ]
|
153
|
+
}
|
154
|
+
]
|
155
|
+
|
156
|
+
assert_equal expected, api_call
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_html_and_text_with_attachment
|
160
|
+
end
|
161
|
+
end
|