bjornblomqvist-emailer 0.1.9 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +11 -0
- data/VERSION +1 -1
- data/emailer.gemspec +1 -1
- data/lib/emailer/mock_smtp_facade.rb +15 -3
- data/spec/emailer/logger_smtp_facade_spec.rb +23 -1
- data/spec/emailer/mock_smtp_facade_spec.rb +2 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -38,6 +38,17 @@ code. Here's a taste:
|
|
38
38
|
) { |success, mail| puts "Sent mail to #{mail[:to]}..." }
|
39
39
|
queue.process
|
40
40
|
|
41
|
+
== Testing using webrat
|
42
|
+
|
43
|
+
Add middleware to render emails for webrat
|
44
|
+
|
45
|
+
Emailer::SmtpFacade.default = Emailer:MockSmtpFacade.new
|
46
|
+
config.middleware.use "Emailer::MockSmtpFacade"
|
47
|
+
|
48
|
+
Then you can get the url to the last email sent using
|
49
|
+
|
50
|
+
Emailer::SmtpFacade.default.last_email_sent_url
|
51
|
+
|
41
52
|
== Note on Patches/Pull Requests
|
42
53
|
|
43
54
|
* Fork the project.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.11
|
data/emailer.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'uuid'
|
2
|
+
|
1
3
|
module Emailer
|
2
4
|
|
3
5
|
class MockNetSmtp
|
@@ -24,17 +26,27 @@ module Emailer
|
|
24
26
|
# And save, don't send, mail...
|
25
27
|
def send_mail(options)
|
26
28
|
raise ConnectionNotOpenError unless @open
|
27
|
-
@sent[UUID.new.
|
29
|
+
@sent[UUID.new.generate] = options
|
28
30
|
true
|
29
31
|
rescue ConnectionNotOpenError => e
|
30
32
|
raise e
|
31
33
|
rescue StandardError => e
|
32
34
|
@error = e
|
33
|
-
@offending_mail =
|
35
|
+
@offending_mail = options
|
34
36
|
false
|
35
37
|
end
|
36
38
|
|
39
|
+
def last_email_sent
|
40
|
+
@sent[@sent.keys.last.to_s]
|
41
|
+
end
|
37
42
|
|
43
|
+
def last_email_sent_key
|
44
|
+
@sent.keys.last
|
45
|
+
end
|
46
|
+
|
47
|
+
def last_email_sent_url
|
48
|
+
get_url_for last_email_sent_key
|
49
|
+
end
|
38
50
|
|
39
51
|
def get_url_for uuidString
|
40
52
|
return "/getemail/"+uuidString
|
@@ -46,7 +58,7 @@ module Emailer
|
|
46
58
|
uuid = env["PATH_INFO"].sub("/getemail/".length)
|
47
59
|
|
48
60
|
return [200, {"Content-Type" => "text/plain"},['Emailer::SmtpFacade.default is not a MockSmtpFacade']] unless
|
49
|
-
Emailer::SmtpFacade.default
|
61
|
+
Emailer::SmtpFacade.default.instance_of? Emailer::MockSmtpFacade
|
50
62
|
|
51
63
|
return [200, {"Content-Type" => "text/plain"},['No email sent']] if Emailer::SmtpFacade.default.sent.count == 0
|
52
64
|
|
@@ -66,10 +66,32 @@ module Emailer
|
|
66
66
|
smtp.send_mail email
|
67
67
|
end
|
68
68
|
|
69
|
-
mock.
|
69
|
+
mock.last_email_sent.should == email
|
70
70
|
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
|
75
|
+
describe :last_email_sent_url do
|
76
|
+
it 'Should return url to last email sent' do
|
77
|
+
smtp = LoggerSmtpFacade.new :log_file => TEST_LOG_FILE
|
78
|
+
|
79
|
+
email = {
|
80
|
+
:to => "test@bits2life.com",
|
81
|
+
:from => "test2@bits2life.com",
|
82
|
+
:subject => "This is a test 4",
|
83
|
+
:body => "Test body"
|
84
|
+
}
|
85
|
+
|
86
|
+
smtp.open do
|
87
|
+
smtp.send_mail email
|
88
|
+
end
|
89
|
+
|
90
|
+
smtp.last_email_sent_url.should == "/getemail/"+smtp.sent.keys.last
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
73
95
|
|
74
96
|
# Should be able to wrap another smtp facade
|
75
97
|
# Should have temp directory configurable
|