action_mailer_test_via_smtp 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,6 +29,27 @@ or
29
29
 
30
30
  I know, the gem name is not valid anymore.
31
31
 
32
+ == Custom Mail-Header
33
+
34
+ You can change the standard test mail header by writing your own renderer. Just set
35
+
36
+ config.test_mail_header_renderer = CustomMailHeaderRenderer
37
+
38
+ Your class should look something like this
39
+
40
+ class CustomMailHeaderRenderer < ActionMailerTestViaSmtp::HeaderRenderer::Base
41
+ def test_mail_header
42
+ # you can access 'mail' which is a TMail::Mail
43
+ "return a prepared string"
44
+ end
45
+
46
+ def test_mail_header_html
47
+ # you can access 'mail' which is a TMail::Mail
48
+ "return a prepared string"
49
+ end
50
+ end
51
+
52
+
32
53
  == Note on Patches/Pull Requests
33
54
 
34
55
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{action_mailer_test_via_smtp}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andi Bade"]
@@ -26,6 +26,8 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "action_mailer_test_via_smtp.gemspec",
28
28
  "lib/action_mailer_test_via_smtp.rb",
29
+ "lib/action_mailer_test_via_smtp/header_renderer/base.rb",
30
+ "lib/action_mailer_test_via_smtp/header_renderer/standard.rb",
29
31
  "test/action_mailer_test_via_smtp_test.rb",
30
32
  "test/templates/notifier/multipart_email.text.html.erb",
31
33
  "test/templates/notifier/multipart_email.text.plain.erb",
@@ -1,23 +1,34 @@
1
+ require "action_mailer_test_via_smtp/header_renderer/standard"
2
+
1
3
  module ActionMailer
2
4
  class Base
3
5
  @@test_recipient = false
4
6
  cattr_accessor :test_recipient
5
7
 
8
+ @@test_mail_header_renderer = ActionMailerTestViaSmtp::HeaderRenderer::Standard
9
+ cattr_accessor :test_mail_header_renderer
10
+
11
+ def test_mail_header_renderer(mail)
12
+ @test_mail_header_renderer ||= self.class.test_mail_header_renderer.new(mail)
13
+ end
14
+
6
15
  def generate_test_mail_header(mail)
7
- %Q{------------------------------- Test-Mail (#{Rails.env}) -------------------------------
8
- Original-Recipient: #{mail.to.join(", ")}
9
- CC: #{mail.cc ? mail.cc.join(", ") : "no CC"}
10
- BCC: #{mail.bcc ? mail.bcc.join(", ") : "no BCC"}
11
- ----------------------------------------------------------------------------------
12
- }
16
+ test_mail_header_renderer(mail).test_mail_header
17
+ end
18
+
19
+ def generate_test_mail_header_html(mail)
20
+ test_mail_header_renderer(mail).test_mail_header_html
13
21
  end
14
22
 
15
23
  [:sendmail, :smtp, :test].each do |meth|
16
24
  define_method "perform_delivery_test_via_#{meth}" do |mail|
17
25
  if mail.multipart?
18
- test_mail_header = generate_test_mail_header(mail)
19
26
  mail.each_part do |part|
20
- part.body = test_mail_header + part.body
27
+ if part.content_type == "text/html"
28
+ part.body = generate_test_mail_header_html(mail) + part.body
29
+ else
30
+ part.body = generate_test_mail_header(mail) + part.body
31
+ end
21
32
  end
22
33
  else
23
34
  mail.body = generate_test_mail_header(mail) + mail.body
@@ -30,3 +41,6 @@ BCC: #{mail.bcc ? mail.bcc.join(", ") : "no BCC"}
30
41
  end
31
42
  end
32
43
  end
44
+
45
+ module ActionMailerTestViaSmtp
46
+ end
@@ -0,0 +1,13 @@
1
+ module ActionMailerTestViaSmtp
2
+ module HeaderRenderer
3
+ class Base
4
+
5
+ attr_reader :mail
6
+
7
+ def initialize(mail)
8
+ @mail = mail
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ require "action_mailer_test_via_smtp/header_renderer/base"
2
+
3
+ module ActionMailerTestViaSmtp
4
+ module HeaderRenderer
5
+ class Standard < Base
6
+
7
+ def test_mail_header
8
+ %Q{------------------------------- Test-Mail (#{Rails.env}) -------------------------------
9
+ Original-Recipient: #{mail.to.join(", ")}
10
+ CC: #{mail.cc ? mail.cc.join(", ") : "no CC"}
11
+ BCC: #{mail.bcc ? mail.bcc.join(", ") : "no BCC"}
12
+ ----------------------------------------------------------------------------------
13
+ }
14
+ end
15
+
16
+ def test_mail_header_html
17
+ test_mail_header.gsub("\n", "<br>")
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -12,13 +12,17 @@ class ActionMailerTestViaSmtpTest < ActiveSupport::TestCase
12
12
 
13
13
  test "should add content to every body of multipart email" do
14
14
  Notifier.deliveries = []
15
- Rails.expects(:env).returns(:test)
15
+ Rails.expects(:env).at_least_once.returns(:test)
16
16
  assert Notifier.deliver_multipart_email
17
17
  assert_equal 1, Notifier.deliveries.size
18
18
  mail = Notifier.deliveries.first
19
19
  assert Notifier.deliveries.first.parts.size > 0
20
20
  Notifier.deliveries.first.each_part do |part|
21
- assert_match /Original-Recipient: test@galaxycats.com/, part.body
21
+ if part.content_type == "text/html"
22
+ assert_match /Original-Recipient: test@galaxycats.com<br>/, part.body
23
+ else
24
+ assert_match /Original-Recipient: test@galaxycats.com/, part.body
25
+ end
22
26
  end
23
27
  end
24
28
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andi Bade
@@ -37,6 +37,8 @@ files:
37
37
  - VERSION
38
38
  - action_mailer_test_via_smtp.gemspec
39
39
  - lib/action_mailer_test_via_smtp.rb
40
+ - lib/action_mailer_test_via_smtp/header_renderer/base.rb
41
+ - lib/action_mailer_test_via_smtp/header_renderer/standard.rb
40
42
  - test/action_mailer_test_via_smtp_test.rb
41
43
  - test/templates/notifier/multipart_email.text.html.erb
42
44
  - test/templates/notifier/multipart_email.text.plain.erb