action_mailer_test_via_smtp 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,4 +19,5 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
- .rake_tasks
22
+ .rake_tasks
23
+ .bundle/config
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source :gemcutter
2
+
3
+ gem "rake"
4
+
5
+ group :test do
6
+ gem "activesupport", "2.3.8"
7
+ gem "actionpack", "2.3.8"
8
+ gem "actionmailer", "2.3.8"
9
+ gem "mocha"
10
+ end
data/README.rdoc CHANGED
@@ -19,6 +19,15 @@ and in you staging.rb (environment file) you can configure this mode
19
19
 
20
20
  now every single mail will be sent to the test_recipient, prefixed with the original recipient.
21
21
 
22
+ Since 0.2.0 you can also test 'sendmail' and even 'test':
23
+
24
+ config.action_mailer.delivery_method = :test_via_sendmail
25
+
26
+ or
27
+
28
+ config.action_mailer.delivery_method = :test_via_test
29
+
30
+ I know, the gem name is not valid anymore.
22
31
 
23
32
  == Note on Patches/Pull Requests
24
33
 
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  gem.email = "andi@galaxycats.com"
11
11
  gem.homepage = "http://github.com/galaxycats/action_mailer_test_via_smtp"
12
12
  gem.authors = ["Andi Bade"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
13
+ # gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
15
  end
16
16
  Jeweler::GemcutterTasks.new
@@ -21,7 +21,7 @@ end
21
21
  require 'rake/testtask'
22
22
  Rake::TestTask.new(:test) do |test|
23
23
  test.libs << 'lib' << 'test'
24
- test.pattern = 'test/**/test_*.rb'
24
+ test.pattern = 'test/**/*_test.rb'
25
25
  test.verbose = true
26
26
  end
27
27
 
@@ -29,7 +29,7 @@ begin
29
29
  require 'rcov/rcovtask'
30
30
  Rcov::RcovTask.new do |test|
31
31
  test.libs << 'test'
32
- test.pattern = 'test/**/test_*.rb'
32
+ test.pattern = 'test/**/*_test.rb'
33
33
  test.verbose = true
34
34
  end
35
35
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{action_mailer_test_via_smtp}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
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"]
12
- s.date = %q{2010-08-09}
12
+ s.date = %q{2010-08-12}
13
13
  s.description = %q{Set one test-reciepient which gets all mails from th app in for example a test/staging environment }
14
14
  s.email = %q{andi@galaxycats.com}
15
15
  s.extra_rdoc_files = [
@@ -19,14 +19,18 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
+ "Gemfile",
22
23
  "LICENSE",
23
24
  "README.rdoc",
24
25
  "Rakefile",
25
26
  "VERSION",
26
27
  "action_mailer_test_via_smtp.gemspec",
27
28
  "lib/action_mailer_test_via_smtp.rb",
28
- "test/helper.rb",
29
- "test/test_action_mailer_test_via_smtp.rb"
29
+ "test/action_mailer_test_via_smtp_test.rb",
30
+ "test/templates/notifier/multipart_email.text.html.erb",
31
+ "test/templates/notifier/multipart_email.text.plain.erb",
32
+ "test/templates/notifier/plain_text_email.erb",
33
+ "test/test_helper.rb"
30
34
  ]
31
35
  s.homepage = %q{http://github.com/galaxycats/action_mailer_test_via_smtp}
32
36
  s.rdoc_options = ["--charset=UTF-8"]
@@ -34,8 +38,8 @@ Gem::Specification.new do |s|
34
38
  s.rubygems_version = %q{1.3.6}
35
39
  s.summary = %q{test mails via smtp with actionmailer}
36
40
  s.test_files = [
37
- "test/helper.rb",
38
- "test/test_action_mailer_test_via_smtp.rb"
41
+ "test/action_mailer_test_via_smtp_test.rb",
42
+ "test/test_helper.rb"
39
43
  ]
40
44
 
41
45
  if s.respond_to? :specification_version then
@@ -43,12 +47,9 @@ Gem::Specification.new do |s|
43
47
  s.specification_version = 3
44
48
 
45
49
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
47
50
  else
48
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
49
51
  end
50
52
  else
51
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
52
53
  end
53
54
  end
54
55
 
@@ -3,20 +3,30 @@ module ActionMailer
3
3
  @@test_recipient = false
4
4
  cattr_accessor :test_recipient
5
5
 
6
- def perform_delivery_test_via_smtp(mail)
7
- mail.body = %Q{
8
- ------------------------------- Test-Mail (#{Rails.env}) -------------------------------
6
+ def generate_test_mail_header(mail)
7
+ %Q{------------------------------- Test-Mail (#{Rails.env}) -------------------------------
9
8
  Original-Recipient: #{mail.to.join(", ")}
10
9
  CC: #{mail.cc ? mail.cc.join(", ") : "no CC"}
11
10
  BCC: #{mail.bcc ? mail.bcc.join(", ") : "no BCC"}
12
11
  ----------------------------------------------------------------------------------
13
- #{mail.body}
14
- }
15
- mail.to = self.class.test_recipient
16
- mail.cc = nil
17
- mail.bcc = nil
18
- perform_delivery_smtp(mail)
12
+ }
19
13
  end
20
14
 
15
+ [:sendmail, :smtp, :test].each do |meth|
16
+ define_method "perform_delivery_test_via_#{meth}" do |mail|
17
+ if mail.multipart?
18
+ test_mail_header = generate_test_mail_header(mail)
19
+ mail.each_part do |part|
20
+ part.body = test_mail_header + part.body
21
+ end
22
+ else
23
+ mail.body = generate_test_mail_header(mail) + mail.body
24
+ end
25
+ mail.to = self.class.test_recipient
26
+ mail.cc = nil
27
+ mail.bcc = nil
28
+ send("perform_delivery_#{meth}", mail)
29
+ end
30
+ end
21
31
  end
22
32
  end
@@ -0,0 +1,25 @@
1
+ require "test_helper"
2
+
3
+ class ActionMailerTestViaSmtpTest < ActiveSupport::TestCase
4
+
5
+ test "should add content to body" do
6
+ Notifier.deliveries = []
7
+ Rails.expects(:env).returns(:test)
8
+ assert Notifier.deliver_plain_text_email
9
+ assert_equal 1, Notifier.deliveries.size
10
+ assert_match /Original-Recipient: test@galaxycats.com/, Notifier.deliveries.first.body
11
+ end
12
+
13
+ test "should add content to every body of multipart email" do
14
+ Notifier.deliveries = []
15
+ Rails.expects(:env).returns(:test)
16
+ assert Notifier.deliver_multipart_email
17
+ assert_equal 1, Notifier.deliveries.size
18
+ mail = Notifier.deliveries.first
19
+ assert Notifier.deliveries.first.parts.size > 0
20
+ Notifier.deliveries.first.each_part do |part|
21
+ assert_match /Original-Recipient: test@galaxycats.com/, part.body
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ This is the HTML part of the multipart mail
2
+
3
+ HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code HTML Code
@@ -0,0 +1,3 @@
1
+ This is the PLAIN part of the multipart mail
2
+
3
+ Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text Plain Text
@@ -0,0 +1,3 @@
1
+ This is the plain-text E-Mail
2
+
3
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
@@ -0,0 +1,33 @@
1
+ $:.reject! { |e| e.include? 'TextMate' }
2
+
3
+ ENV["RAILS_ENV"] = "test"
4
+
5
+ require "rubygems"
6
+ require "bundler"
7
+ Bundler.setup
8
+
9
+ require 'test/unit'
10
+ require "active_support"
11
+ require "active_support/test_case"
12
+ require "active_support/core_ext"
13
+ require "action_mailer"
14
+ require "action_mailer_test_via_smtp"
15
+ require "mocha"
16
+
17
+ ActionMailer::Base.delivery_method = :test_via_test
18
+ ActionMailer::Base.test_recipient = "tester@galaxycats.com"
19
+ ActionMailer::Base.template_root = "test/templates"
20
+
21
+ class Rails; end
22
+
23
+ class Notifier < ActionMailer::Base
24
+
25
+ def plain_text_email
26
+ recipients ["test@galaxycats.com"]
27
+ end
28
+
29
+ def multipart_email
30
+ recipients ["test@galaxycats.com"]
31
+ end
32
+
33
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andi Bade
@@ -14,21 +14,10 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-09 00:00:00 +02:00
17
+ date: 2010-08-12 00:00:00 +02:00
18
18
  default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: thoughtbot-shoulda
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
30
- type: :development
31
- version_requirements: *id001
19
+ dependencies: []
20
+
32
21
  description: "Set one test-reciepient which gets all mails from th app in for example a test/staging environment "
33
22
  email: andi@galaxycats.com
34
23
  executables: []
@@ -41,14 +30,18 @@ extra_rdoc_files:
41
30
  files:
42
31
  - .document
43
32
  - .gitignore
33
+ - Gemfile
44
34
  - LICENSE
45
35
  - README.rdoc
46
36
  - Rakefile
47
37
  - VERSION
48
38
  - action_mailer_test_via_smtp.gemspec
49
39
  - lib/action_mailer_test_via_smtp.rb
50
- - test/helper.rb
51
- - test/test_action_mailer_test_via_smtp.rb
40
+ - test/action_mailer_test_via_smtp_test.rb
41
+ - test/templates/notifier/multipart_email.text.html.erb
42
+ - test/templates/notifier/multipart_email.text.plain.erb
43
+ - test/templates/notifier/plain_text_email.erb
44
+ - test/test_helper.rb
52
45
  has_rdoc: true
53
46
  homepage: http://github.com/galaxycats/action_mailer_test_via_smtp
54
47
  licenses: []
@@ -80,5 +73,5 @@ signing_key:
80
73
  specification_version: 3
81
74
  summary: test mails via smtp with actionmailer
82
75
  test_files:
83
- - test/helper.rb
84
- - test/test_action_mailer_test_via_smtp.rb
76
+ - test/action_mailer_test_via_smtp_test.rb
77
+ - test/test_helper.rb
data/test/helper.rb DELETED
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'action_mailer_test_via_smtp'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestActionMailerTestViaSmtp < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end