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 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.9
1
+ 0.1.11
data/emailer.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{emailer}
8
- s.version = "0.1.9"
8
+ s.version = "0.1.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Erik Hansson", "Bjorn Blomqvist"]
@@ -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.to_s] << options
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 = 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 && Emailer::SmtpFacade.default.instance_of? Emailer::MockSmtpFacade
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.sent.first.should == email
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
@@ -19,7 +19,8 @@ module Emailer
19
19
  )
20
20
  end
21
21
 
22
- smtp.sent.first.should == message
22
+ smtp.last_email_sent.should == message
23
+
23
24
  end
24
25
  end
25
26
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bjornblomqvist-emailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Hansson