mailthis 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/Gemfile +1 -2
- data/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +27 -2
- data/lib/mailthis/mailer.rb +90 -26
- data/lib/mailthis/outgoing_email.rb +14 -7
- data/lib/mailthis/version.rb +1 -1
- data/mailthis.gemspec +4 -4
- data/test/helper.rb +10 -0
- data/test/support/factory.rb +10 -8
- data/test/unit/mailer_tests.rb +157 -94
- data/test/unit/mailthis_tests.rb +1 -1
- data/test/unit/outgoing_email_tests.rb +21 -7
- metadata +54 -67
- data/Rakefile +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA512:
|
3
|
+
metadata.gz: 9b932ae539ca3de085ebf72c38e4af7a037008948bad9e269f4f0c2c1b86200a18af05545cca05088a6a2289ad03a4ab9865ac30f52e94876abacafad84f6cee
|
4
|
+
data.tar.gz: eb4f6509650be2b72a1df2e7964c5034b5c1c7c9bee5213d3a60fddb6ed7b77190a968b8bed441ca0409b6367042b5e0abf76c3d01c9b6181b1d384c56591421
|
5
|
+
SHA1:
|
6
|
+
metadata.gz: a6d88da05b6daf2c42ee315da216b80e5a3dd998
|
7
|
+
data.tar.gz: 3fbd933f825c70c735a8eacfad600d5b5d829507
|
data/Gemfile
CHANGED
data/{LICENSE.txt → LICENSE}
RENAMED
File without changes
|
data/README.md
CHANGED
@@ -39,7 +39,7 @@ GMAIL = Mailthis.mailer do
|
|
39
39
|
smtp_pw 'secret'
|
40
40
|
|
41
41
|
smtp_auth "plain" # (optional) default: "login"
|
42
|
-
from "me@example.com" # (optional) default:
|
42
|
+
from "me@example.com" # (optional) default: `smtp_user` (if valid)
|
43
43
|
logger Logger.new("log/email.log") # (optional) default: no logger, no logging
|
44
44
|
end
|
45
45
|
|
@@ -66,7 +66,32 @@ if !production?
|
|
66
66
|
end
|
67
67
|
```
|
68
68
|
|
69
|
-
|
69
|
+
Set the env var to *any not-nil* value and mailthis will not send any mail. It will do everything else, however, including logging the mail it would have sent and "delivering" the message in test mode (see below).
|
70
|
+
|
71
|
+
### Test Mode
|
72
|
+
|
73
|
+
When testing it is often nice to be able to check and see if your code delivered email or not. Mailthis has a test mode where the mailer tracks
|
74
|
+
the messages it delivers. Enable this with the env var `MAILTHIS_TEST_MODE`
|
75
|
+
in your tests.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
# in your test helper or whatever
|
79
|
+
ENV['MAILTHIS_TEST_MODE'] = 'y'
|
80
|
+
|
81
|
+
# in your tests or whatever
|
82
|
+
should "email a notification" do
|
83
|
+
assert_not_empty my_mailer.delivered_messages
|
84
|
+
|
85
|
+
msg = my_mailer.delivered_messages.last
|
86
|
+
exp_notification = Notification.new
|
87
|
+
assert_equal [exp_notification.to], msg.to
|
88
|
+
assert_equal exp_notification.subject, msg.subject
|
89
|
+
assert_equal exp_notification.body, msg.body.to_s
|
90
|
+
# or whatever your test logic may be, this is just an example
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
Set the env var to *any not-nil* value to enable this mode.
|
70
95
|
|
71
96
|
## Installation
|
72
97
|
|
data/lib/mailthis/mailer.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'much-plugin'
|
2
2
|
require 'mailthis/exceptions'
|
3
3
|
require 'mailthis/message'
|
4
4
|
require 'mailthis/outgoing_email'
|
@@ -6,6 +6,24 @@ require 'mailthis/outgoing_email'
|
|
6
6
|
module Mailthis
|
7
7
|
|
8
8
|
module Mailer
|
9
|
+
include MuchPlugin
|
10
|
+
|
11
|
+
plugin_included do
|
12
|
+
include InstanceMethods
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
REQUIRED_SETTINGS = [
|
17
|
+
:smtp_helo,
|
18
|
+
:smtp_server,
|
19
|
+
:smtp_port,
|
20
|
+
:smtp_user,
|
21
|
+
:smtp_pw,
|
22
|
+
:smtp_auth,
|
23
|
+
:from,
|
24
|
+
:logger
|
25
|
+
].freeze
|
26
|
+
DEFAULT_AUTH = 'login'.freeze
|
9
27
|
|
10
28
|
def self.new(*args, &block)
|
11
29
|
if !ENV['MAILTHIS_TEST_MODE']
|
@@ -15,43 +33,85 @@ module Mailthis
|
|
15
33
|
end
|
16
34
|
end
|
17
35
|
|
18
|
-
|
19
|
-
klass.class_eval do
|
20
|
-
include NsOptions::Proxy
|
21
|
-
include InstanceMethods
|
36
|
+
module InstanceMethods
|
22
37
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
option :smtp_pw, String, :required => true
|
28
|
-
option :smtp_auth, String, :required => true, :default => proc{ "login" }
|
38
|
+
def initialize(&block)
|
39
|
+
@nil_settings = nil
|
40
|
+
@smtp_auth = DEFAULT_AUTH
|
41
|
+
@logger = NullLogger.new
|
29
42
|
|
30
|
-
|
31
|
-
|
43
|
+
self.instance_eval(&block) if block
|
44
|
+
end
|
32
45
|
|
46
|
+
def smtp_helo(value = nil)
|
47
|
+
@smtp_helo = value if !value.nil?
|
48
|
+
@smtp_helo
|
33
49
|
end
|
34
|
-
end
|
35
50
|
|
36
|
-
|
51
|
+
def smtp_server(value = nil)
|
52
|
+
@smtp_server = value if !value.nil?
|
53
|
+
@smtp_server
|
54
|
+
end
|
55
|
+
|
56
|
+
def smtp_port(value = nil)
|
57
|
+
@smtp_port = value if !value.nil?
|
58
|
+
@smtp_port
|
59
|
+
end
|
60
|
+
|
61
|
+
def smtp_user(value = nil)
|
62
|
+
@smtp_user = value if !value.nil?
|
63
|
+
@smtp_user
|
64
|
+
end
|
65
|
+
|
66
|
+
def smtp_pw(value = nil)
|
67
|
+
@smtp_pw = value if !value.nil?
|
68
|
+
@smtp_pw
|
69
|
+
end
|
37
70
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
71
|
+
def smtp_auth(value = nil)
|
72
|
+
@smtp_auth = value.to_s if !value.nil?
|
73
|
+
@smtp_auth
|
74
|
+
end
|
75
|
+
|
76
|
+
def from(value = nil)
|
77
|
+
@from = value if !value.nil?
|
78
|
+
@from
|
79
|
+
end
|
80
|
+
|
81
|
+
def logger(value = nil)
|
82
|
+
@logger = value if !value.nil?
|
83
|
+
@logger
|
84
|
+
end
|
85
|
+
|
86
|
+
def valid?
|
87
|
+
!@nil_settings.nil? && @nil_settings.empty?
|
44
88
|
end
|
45
89
|
|
46
90
|
def validate!
|
47
|
-
|
91
|
+
@from = self.smtp_user if @from.nil?
|
92
|
+
|
93
|
+
@nil_settings = []
|
94
|
+
REQUIRED_SETTINGS.each{ |s| @nil_settings << s if self.send(s).nil? }
|
95
|
+
if !self.valid?
|
96
|
+
raise(MailerError, "missing required settings: #{@nil_settings.join(', ')}")
|
97
|
+
end
|
98
|
+
|
48
99
|
self # for chaining
|
49
100
|
end
|
50
101
|
|
51
102
|
def deliver(message = nil, &block)
|
103
|
+
raise NotImplementedError
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def outgoing_email(message, &block)
|
109
|
+
OutgoingEmail.new(self, build_message(message, &block))
|
110
|
+
end
|
111
|
+
|
112
|
+
def build_message(message, &block)
|
52
113
|
(message || ::Mailthis::Message.new).tap do |msg|
|
53
114
|
msg.instance_eval(&block) if block
|
54
|
-
OutgoingEmail.new(self, msg).deliver
|
55
115
|
end
|
56
116
|
end
|
57
117
|
|
@@ -69,6 +129,10 @@ module Mailthis
|
|
69
129
|
class MailthisMailer
|
70
130
|
include Mailer
|
71
131
|
|
132
|
+
def deliver(message = nil, &block)
|
133
|
+
outgoing_email(message, &block).deliver
|
134
|
+
end
|
135
|
+
|
72
136
|
end
|
73
137
|
|
74
138
|
class TestMailer
|
@@ -81,9 +145,9 @@ module Mailthis
|
|
81
145
|
@delivered_messages = []
|
82
146
|
end
|
83
147
|
|
84
|
-
def deliver(
|
85
|
-
|
86
|
-
|
148
|
+
def deliver(message = nil, &block)
|
149
|
+
outgoing_email(message, &block).deliver_dry_run do |msg|
|
150
|
+
self.delivered_messages << msg
|
87
151
|
end
|
88
152
|
end
|
89
153
|
|
@@ -35,13 +35,20 @@ module Mailthis
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
38
|
+
def deliver_dry_run
|
39
39
|
self.validate!
|
40
40
|
@mailer.validate!
|
41
|
-
deliver_smtp if ENV['MAILTHIS_DISABLE_SEND'].nil?
|
42
41
|
|
43
|
-
|
44
|
-
|
42
|
+
yield(self.message) if block_given?
|
43
|
+
|
44
|
+
log_message(self.message)
|
45
|
+
self.message
|
46
|
+
end
|
47
|
+
|
48
|
+
def deliver
|
49
|
+
self.deliver_dry_run do |msg|
|
50
|
+
deliver_smtp(msg) if ENV['MAILTHIS_DISABLE_SEND'].nil?
|
51
|
+
end
|
45
52
|
end
|
46
53
|
|
47
54
|
private
|
@@ -58,7 +65,7 @@ module Mailthis
|
|
58
65
|
!message.send(field).nil? && !message.send(field).empty?
|
59
66
|
end
|
60
67
|
|
61
|
-
def deliver_smtp
|
68
|
+
def deliver_smtp(msg)
|
62
69
|
smtp_start_args = [
|
63
70
|
@mailer.smtp_server,
|
64
71
|
@mailer.smtp_port,
|
@@ -70,8 +77,8 @@ module Mailthis
|
|
70
77
|
|
71
78
|
Net::SMTP.start(*smtp_start_args) do |smtp|
|
72
79
|
ADDRESS_FIELDS.each do |field|
|
73
|
-
if (recipients =
|
74
|
-
recipients.each{ |r| smtp.send_message(
|
80
|
+
if (recipients = msg.send(field))
|
81
|
+
recipients.each{ |r| smtp.send_message(msg.to_s, msg.from, r) }
|
75
82
|
end
|
76
83
|
end
|
77
84
|
end
|
data/lib/mailthis/version.rb
CHANGED
data/mailthis.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Mailthis::VERSION
|
9
9
|
gem.authors = ["Kelly Redding", "Collin Redding"]
|
10
10
|
gem.email = ["kelly@kellyredding.com", "collin.redding@me.com"]
|
11
|
-
gem.description = %q{mailer for ruby}
|
12
11
|
gem.summary = %q{mailer for ruby}
|
12
|
+
gem.description = %q{mailer for ruby}
|
13
13
|
gem.homepage = "http://github.com/redding/mailthis"
|
14
14
|
gem.license = 'MIT'
|
15
15
|
|
@@ -18,9 +18,9 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.add_development_dependency("assert", ["~> 2.
|
21
|
+
gem.add_development_dependency("assert", ["~> 2.16.1"])
|
22
22
|
|
23
|
-
gem.add_dependency("
|
24
|
-
gem.add_dependency("mail",
|
23
|
+
gem.add_dependency("much-plugin", ["~> 0.2.0"])
|
24
|
+
gem.add_dependency("mail", ["~> 2.5"])
|
25
25
|
|
26
26
|
end
|
data/test/helper.rb
CHANGED
@@ -6,7 +6,17 @@ $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
|
|
6
6
|
|
7
7
|
# require pry for debugging (`binding.pry`)
|
8
8
|
require 'pry'
|
9
|
+
|
9
10
|
require 'test/support/factory'
|
10
11
|
|
12
|
+
# 1.8.7 backfills
|
13
|
+
|
14
|
+
# Array#sample
|
15
|
+
if !(a = Array.new).respond_to?(:sample) && a.respond_to?(:choice)
|
16
|
+
class Array
|
17
|
+
alias_method :sample, :choice
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
11
21
|
# disable actually delivering emails for testing purposes
|
12
22
|
ENV['MAILTHIS_DISABLE_SEND'] = 'y'
|
data/test/support/factory.rb
CHANGED
@@ -3,16 +3,18 @@ require 'assert/factory'
|
|
3
3
|
module Factory
|
4
4
|
extend Assert::Factory
|
5
5
|
|
6
|
-
def self.mailer
|
6
|
+
def self.mailer(s = {})
|
7
|
+
s ||= {}
|
7
8
|
require 'mailthis/mailer'
|
8
9
|
Mailthis::Mailer.new do
|
9
|
-
smtp_helo "example.com"
|
10
|
-
smtp_server "smtp.example.com"
|
11
|
-
smtp_port 25
|
12
|
-
smtp_user "test@example.com"
|
13
|
-
smtp_pw "secret"
|
14
|
-
smtp_auth :plain
|
15
|
-
from "me@example.com"
|
10
|
+
smtp_helo (s.key?(:smtp_helo) ? s[:smtp_helo] : "example.com")
|
11
|
+
smtp_server (s.key?(:smtp_server) ? s[:smtp_server] : "smtp.example.com")
|
12
|
+
smtp_port (s.key?(:smtp_port) ? s[:smtp_port] : 25)
|
13
|
+
smtp_user (s.key?(:smtp_user) ? s[:smtp_user] : "test@example.com")
|
14
|
+
smtp_pw (s.key?(:smtp_pw) ? s[:smtp_pw] : "secret")
|
15
|
+
smtp_auth (s.key?(:smtp_auth) ? s[:smtp_auth] : :plain)
|
16
|
+
from (s.key?(:from) ? s[:from] : "me@example.com")
|
17
|
+
logger (s.key?(:logger) ? s[:logger] : nil)
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
data/test/unit/mailer_tests.rb
CHANGED
@@ -19,6 +19,24 @@ module Mailthis::Mailer
|
|
19
19
|
|
20
20
|
should have_imeths :new
|
21
21
|
|
22
|
+
should "know its required settings" do
|
23
|
+
exp = [
|
24
|
+
:smtp_helo,
|
25
|
+
:smtp_server,
|
26
|
+
:smtp_port,
|
27
|
+
:smtp_user,
|
28
|
+
:smtp_pw,
|
29
|
+
:smtp_auth,
|
30
|
+
:from,
|
31
|
+
:logger
|
32
|
+
]
|
33
|
+
assert_equal exp, subject::REQUIRED_SETTINGS
|
34
|
+
end
|
35
|
+
|
36
|
+
should "know its default auth value" do
|
37
|
+
assert_equal 'login', subject::DEFAULT_AUTH
|
38
|
+
end
|
39
|
+
|
22
40
|
should "return a mailthis mailer using `new`" do
|
23
41
|
ENV.delete('MAILTHIS_TEST_MODE')
|
24
42
|
mailer = subject.new
|
@@ -45,9 +63,9 @@ module Mailthis::Mailer
|
|
45
63
|
should have_imeths :smtp_helo, :smtp_server, :smtp_port
|
46
64
|
should have_imeths :smtp_user, :smtp_pw, :smtp_auth
|
47
65
|
should have_imeths :from, :logger
|
48
|
-
should have_imeths :validate!, :deliver
|
66
|
+
should have_imeths :valid?, :validate!, :deliver
|
49
67
|
|
50
|
-
should "know its smtp settings" do
|
68
|
+
should "know its smtp helo, server, port and user settings" do
|
51
69
|
{ :smtp_helo => Factory.string,
|
52
70
|
:smtp_server => Factory.string,
|
53
71
|
:smtp_port => Factory.integer,
|
@@ -61,27 +79,124 @@ module Mailthis::Mailer
|
|
61
79
|
end
|
62
80
|
end
|
63
81
|
|
64
|
-
should "
|
65
|
-
assert_equal
|
82
|
+
should "know its smtp auth setting" do
|
83
|
+
assert_equal DEFAULT_AUTH, subject.smtp_auth
|
66
84
|
|
67
|
-
|
68
|
-
|
85
|
+
exp = Factory.string
|
86
|
+
subject.smtp_auth exp
|
87
|
+
assert_equal exp, subject.smtp_auth
|
69
88
|
end
|
70
89
|
|
71
|
-
should "
|
90
|
+
should "know its from setting" do
|
72
91
|
assert_nil subject.from
|
73
92
|
|
74
|
-
|
75
|
-
|
93
|
+
exp = Factory.email
|
94
|
+
subject.from exp
|
95
|
+
assert_equal exp, subject.from
|
76
96
|
end
|
77
97
|
|
78
|
-
should "
|
79
|
-
subject.
|
80
|
-
|
98
|
+
should "know its logger setting" do
|
99
|
+
assert_instance_of NullLogger, subject.logger
|
100
|
+
|
101
|
+
exp = Factory.string
|
102
|
+
subject.logger exp
|
103
|
+
assert_equal exp, subject.logger
|
81
104
|
end
|
82
105
|
|
83
|
-
|
84
|
-
|
106
|
+
end
|
107
|
+
|
108
|
+
class ValidationTests < UnitTests
|
109
|
+
desc "when validating"
|
110
|
+
setup do
|
111
|
+
@valid_settings = {
|
112
|
+
:smtp_helo => Factory.string,
|
113
|
+
:smtp_server => Factory.string,
|
114
|
+
:smtp_port => Factory.integer,
|
115
|
+
:smtp_user => Factory.email,
|
116
|
+
:smtp_pw => Factory.string,
|
117
|
+
:smtp_auth => :plain,
|
118
|
+
:from => nil
|
119
|
+
}
|
120
|
+
@valid_mailer = Factory.mailer(@valid_settings)
|
121
|
+
end
|
122
|
+
subject{ @valid_mailer }
|
123
|
+
|
124
|
+
should "not be valid until validated" do
|
125
|
+
assert_false subject.valid?
|
126
|
+
subject.validate!
|
127
|
+
assert_true subject.valid?
|
128
|
+
end
|
129
|
+
|
130
|
+
should "not complain if all settings are in place" do
|
131
|
+
assert_valid(subject)
|
132
|
+
end
|
133
|
+
|
134
|
+
should "return itself when validating" do
|
135
|
+
assert_same subject, subject.validate!
|
136
|
+
end
|
137
|
+
|
138
|
+
should "set the from to the smtp user if it isn't set already" do
|
139
|
+
assert_nil subject.from
|
140
|
+
|
141
|
+
subject.validate!
|
142
|
+
assert_equal subject.smtp_user, subject.from
|
143
|
+
end
|
144
|
+
|
145
|
+
should "be invalid if no helo domain is set" do
|
146
|
+
@valid_settings[:smtp_helo] = nil
|
147
|
+
assert_invalid(Factory.mailer(@valid_settings))
|
148
|
+
end
|
149
|
+
|
150
|
+
should "be invalid if no server is set" do
|
151
|
+
@valid_settings[:smtp_server] = nil
|
152
|
+
assert_invalid(Factory.mailer(@valid_settings))
|
153
|
+
end
|
154
|
+
|
155
|
+
should "be invalid if no port is set" do
|
156
|
+
@valid_settings[:smtp_port] = nil
|
157
|
+
assert_invalid(Factory.mailer(@valid_settings))
|
158
|
+
end
|
159
|
+
|
160
|
+
should "be invalid if no user is set" do
|
161
|
+
@valid_settings[:smtp_user] = nil
|
162
|
+
assert_invalid(Factory.mailer(@valid_settings))
|
163
|
+
end
|
164
|
+
|
165
|
+
should "be invalid if no pw is set" do
|
166
|
+
@valid_settings[:smtp_pw] = nil
|
167
|
+
assert_invalid(Factory.mailer(@valid_settings))
|
168
|
+
end
|
169
|
+
|
170
|
+
should "not be invalid if no auth is set" do
|
171
|
+
# b/c it has a default value
|
172
|
+
@valid_settings[:smtp_auth] = nil
|
173
|
+
assert_valid(Factory.mailer(@valid_settings))
|
174
|
+
end
|
175
|
+
|
176
|
+
should "not be invalid if no from is set" do
|
177
|
+
# b/c it is defaulted from the smtp user
|
178
|
+
@valid_settings[:from] = nil
|
179
|
+
assert_valid(Factory.mailer(@valid_settings))
|
180
|
+
end
|
181
|
+
|
182
|
+
should "not be invalid if no logger is set" do
|
183
|
+
# b/c it is defaulted to a NullLogger
|
184
|
+
@valid_settings[:logger] = nil
|
185
|
+
assert_valid(Factory.mailer(@valid_settings))
|
186
|
+
end
|
187
|
+
|
188
|
+
private
|
189
|
+
|
190
|
+
def assert_valid(mailer)
|
191
|
+
with_backtrace(caller) do
|
192
|
+
assert_nothing_raised{ mailer.validate! }
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def assert_invalid(mailer)
|
197
|
+
with_backtrace(caller) do
|
198
|
+
assert_raises(Mailthis::MailerError){ mailer.validate! }
|
199
|
+
end
|
85
200
|
end
|
86
201
|
|
87
202
|
end
|
@@ -91,7 +206,7 @@ module Mailthis::Mailer
|
|
91
206
|
setup do
|
92
207
|
@message = Factory.message(:from => "me@example.com")
|
93
208
|
@mailer = Factory.mailer
|
94
|
-
@mailer.logger
|
209
|
+
@mailer.logger(Factory.logger(@out = ""))
|
95
210
|
|
96
211
|
@sent_msg = @mailer.deliver(@message)
|
97
212
|
end
|
@@ -117,7 +232,7 @@ module Mailthis::Mailer
|
|
117
232
|
assert_equal 'a message', built_msg.subject
|
118
233
|
end
|
119
234
|
|
120
|
-
should "
|
235
|
+
should "take a message and apply the given block" do
|
121
236
|
built_msg = @mailer.deliver(Factory.message) do
|
122
237
|
from 'me@example.com'
|
123
238
|
end
|
@@ -130,98 +245,36 @@ module Mailthis::Mailer
|
|
130
245
|
|
131
246
|
end
|
132
247
|
|
133
|
-
class
|
134
|
-
desc "
|
248
|
+
class MailthisMailerTests < Assert::Context
|
249
|
+
desc "MailthisMailer"
|
135
250
|
setup do
|
136
|
-
@
|
137
|
-
smtp_helo Factory.string
|
138
|
-
smtp_server Factory.string
|
139
|
-
smtp_port Factory.integer
|
140
|
-
smtp_user Factory.email
|
141
|
-
smtp_pw Factory.string
|
142
|
-
smtp_auth :plain
|
143
|
-
end
|
144
|
-
end
|
145
|
-
subject{ @invalid }
|
146
|
-
|
147
|
-
should "not complain if all settings are in place" do
|
148
|
-
assert_valid
|
149
|
-
end
|
150
|
-
|
151
|
-
should "return itself when validating" do
|
152
|
-
assert_same subject, subject.validate!
|
153
|
-
end
|
154
|
-
|
155
|
-
should "be invalid if missing the helo domain" do
|
156
|
-
subject.smtp_helo = nil
|
157
|
-
assert_invalid
|
158
|
-
end
|
159
|
-
|
160
|
-
should "be invalid if missing the server" do
|
161
|
-
subject.smtp_server = nil
|
162
|
-
assert_invalid
|
163
|
-
end
|
164
|
-
|
165
|
-
should "be invalid if missing the port" do
|
166
|
-
subject.smtp_port = nil
|
167
|
-
assert_invalid
|
168
|
-
end
|
169
|
-
|
170
|
-
should "be invalid if missing the user" do
|
171
|
-
subject.smtp_user = nil
|
172
|
-
assert_invalid
|
173
|
-
end
|
174
|
-
|
175
|
-
should "be invalid if missing the pw" do
|
176
|
-
subject.smtp_pw = nil
|
177
|
-
assert_invalid
|
178
|
-
end
|
179
|
-
|
180
|
-
should "be invalid if missing the auth" do
|
181
|
-
subject.smtp_auth = nil
|
182
|
-
assert_invalid
|
183
|
-
end
|
184
|
-
|
185
|
-
should "be invalid if missing the from" do
|
186
|
-
subject.from = nil
|
187
|
-
assert_invalid
|
188
|
-
end
|
189
|
-
|
190
|
-
should "be invalid if missing the logger" do
|
191
|
-
subject.logger = nil
|
192
|
-
assert_invalid
|
193
|
-
end
|
194
|
-
|
195
|
-
private
|
196
|
-
|
197
|
-
def assert_valid
|
198
|
-
assert_nothing_raised do
|
199
|
-
subject.validate!
|
200
|
-
end
|
251
|
+
@mailer_class = Mailthis::MailthisMailer
|
201
252
|
end
|
253
|
+
subject{ @mailer_class }
|
202
254
|
|
203
|
-
|
204
|
-
|
205
|
-
subject.validate!
|
206
|
-
end
|
255
|
+
should "include the Mailer mixin" do
|
256
|
+
assert_includes Mailthis::Mailer, subject
|
207
257
|
end
|
208
258
|
|
209
259
|
end
|
210
260
|
|
211
|
-
class
|
212
|
-
desc "
|
261
|
+
class MailthisMailerInitTests < MailthisMailerTests
|
262
|
+
desc "when init"
|
213
263
|
setup do
|
214
|
-
@
|
264
|
+
@message = Factory.message
|
265
|
+
|
266
|
+
ENV.delete('MAILTHIS_TEST_MODE')
|
267
|
+
@mailer = Factory.mailer # b/c not in test mode, this is a mailthis mailer
|
215
268
|
end
|
216
|
-
subject{ @
|
269
|
+
subject{ @mailer }
|
217
270
|
|
218
|
-
should "
|
219
|
-
|
271
|
+
should "return the message when delivering" do
|
272
|
+
assert_same @message, subject.deliver(@message)
|
220
273
|
end
|
221
274
|
|
222
275
|
end
|
223
276
|
|
224
|
-
class TestMailerTests <
|
277
|
+
class TestMailerTests < Assert::Context
|
225
278
|
desc "TestMailer"
|
226
279
|
setup do
|
227
280
|
@mailer_class = Mailthis::TestMailer
|
@@ -237,14 +290,24 @@ module Mailthis::Mailer
|
|
237
290
|
class TestMailerInitTests < TestMailerTests
|
238
291
|
desc "when init"
|
239
292
|
setup do
|
293
|
+
@current_test_mode = ENV['MAILTHIS_TEST_MODE']
|
294
|
+
ENV['MAILTHIS_TEST_MODE'] = 'yes'
|
295
|
+
|
240
296
|
@message = Factory.message
|
241
297
|
@mailer = Factory.mailer # b/c in test mode, this is a test mailer
|
242
298
|
end
|
299
|
+
teardown do
|
300
|
+
ENV['MAILTHIS_TEST_MODE'] = @current_test_mode
|
301
|
+
end
|
243
302
|
subject{ @mailer }
|
244
303
|
|
245
304
|
should have_readers :delivered_messages
|
246
305
|
should have_imeths :reset
|
247
306
|
|
307
|
+
should "return the message when delivering" do
|
308
|
+
assert_same @message, subject.deliver(@message)
|
309
|
+
end
|
310
|
+
|
248
311
|
should "not have any delivered messages by default" do
|
249
312
|
assert_empty subject.delivered_messages
|
250
313
|
end
|
data/test/unit/mailthis_tests.rb
CHANGED
@@ -15,7 +15,7 @@ class Mailthis::OutgoingEmail
|
|
15
15
|
subject{ @email }
|
16
16
|
|
17
17
|
should have_readers :mailer, :message
|
18
|
-
should have_imeths :validate!, :deliver
|
18
|
+
should have_imeths :validate!, :deliver_dry_run, :deliver
|
19
19
|
|
20
20
|
should "know its mailer and message" do
|
21
21
|
assert_same @mailer, subject.mailer
|
@@ -40,18 +40,26 @@ class Mailthis::OutgoingEmail
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
should "yield the message on deliver dry runs" do
|
44
|
+
subject.deliver_dry_run do |msg|
|
45
|
+
assert_equal subject.message, msg
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
43
49
|
should "complain if delivering with an invalid mailer" do
|
44
|
-
|
45
|
-
|
50
|
+
mailer = Factory.mailer(:smtp_server => nil)
|
51
|
+
assert_false mailer.valid?
|
46
52
|
|
47
|
-
|
53
|
+
email = Mailthis::OutgoingEmail.new(mailer, @message)
|
54
|
+
assert_raises(Mailthis::MailerError){ email.send(deliver_method) }
|
48
55
|
end
|
49
56
|
|
50
57
|
should "log when delivering a message" do
|
51
|
-
|
58
|
+
mailer = Factory.mailer(:logger => Factory.logger(out = ""))
|
52
59
|
assert_empty out
|
53
60
|
|
54
|
-
|
61
|
+
email = Mailthis::OutgoingEmail.new(mailer, @message)
|
62
|
+
email.send(deliver_method)
|
55
63
|
|
56
64
|
assert_not_empty out
|
57
65
|
assert_includes "Sent '#{@message.subject}'", out
|
@@ -59,7 +67,13 @@ class Mailthis::OutgoingEmail
|
|
59
67
|
end
|
60
68
|
|
61
69
|
should "return the delivered message" do
|
62
|
-
assert_same
|
70
|
+
assert_same subject.message, subject.send(deliver_method)
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def deliver_method
|
76
|
+
[:deliver, :deliver_dry_run].sample
|
63
77
|
end
|
64
78
|
|
65
79
|
end
|
metadata
CHANGED
@@ -1,77 +1,62 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailthis
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Kelly Redding
|
8
8
|
- Collin Redding
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
|
13
|
+
date: 2016-06-16 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
15
16
|
name: assert
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.16.1
|
21
23
|
type: :development
|
24
|
+
version_requirements: *id001
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: much-plugin
|
22
27
|
prerelease: false
|
23
|
-
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version:
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: ns-options
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - "~>"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '1.1'
|
35
|
-
- - ">="
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 1.1.4
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.2.0
|
38
33
|
type: :runtime
|
39
|
-
|
40
|
-
|
41
|
-
requirements:
|
42
|
-
- - "~>"
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version: '1.1'
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 1.1.4
|
48
|
-
- !ruby/object:Gem::Dependency
|
34
|
+
version_requirements: *id002
|
35
|
+
- !ruby/object:Gem::Dependency
|
49
36
|
name: mail
|
50
|
-
requirement: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '2.5'
|
55
|
-
type: :runtime
|
56
37
|
prerelease: false
|
57
|
-
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version:
|
38
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "2.5"
|
43
|
+
type: :runtime
|
44
|
+
version_requirements: *id003
|
62
45
|
description: mailer for ruby
|
63
|
-
email:
|
46
|
+
email:
|
64
47
|
- kelly@kellyredding.com
|
65
48
|
- collin.redding@me.com
|
66
49
|
executables: []
|
50
|
+
|
67
51
|
extensions: []
|
52
|
+
|
68
53
|
extra_rdoc_files: []
|
69
|
-
|
70
|
-
|
54
|
+
|
55
|
+
files:
|
56
|
+
- .gitignore
|
71
57
|
- Gemfile
|
72
|
-
- LICENSE
|
58
|
+
- LICENSE
|
73
59
|
- README.md
|
74
|
-
- Rakefile
|
75
60
|
- lib/mailthis.rb
|
76
61
|
- lib/mailthis/exceptions.rb
|
77
62
|
- lib/mailthis/mailer.rb
|
@@ -89,30 +74,32 @@ files:
|
|
89
74
|
- test/unit/outgoing_email_tests.rb
|
90
75
|
- tmp/.gitkeep
|
91
76
|
homepage: http://github.com/redding/mailthis
|
92
|
-
licenses:
|
77
|
+
licenses:
|
93
78
|
- MIT
|
94
79
|
metadata: {}
|
80
|
+
|
95
81
|
post_install_message:
|
96
82
|
rdoc_options: []
|
97
|
-
|
83
|
+
|
84
|
+
require_paths:
|
98
85
|
- lib
|
99
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
-
|
102
|
-
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
version: '0'
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- &id004
|
89
|
+
- ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- *id004
|
109
95
|
requirements: []
|
96
|
+
|
110
97
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.4
|
98
|
+
rubygems_version: 2.6.4
|
112
99
|
signing_key:
|
113
100
|
specification_version: 4
|
114
101
|
summary: mailer for ruby
|
115
|
-
test_files:
|
102
|
+
test_files:
|
116
103
|
- test/helper.rb
|
117
104
|
- test/support/factory.rb
|
118
105
|
- test/unit/mailer_tests.rb
|
data/Rakefile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "bundler/gem_tasks"
|