action_mailer_test_mailing 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,23 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Andi Bade
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,65 @@
1
+ = action_mailer_test_mailing
2
+
3
+ If you want to test your e-mails not just in your log, this library is for you. It allows you to configure a
4
+ test-recipient which gets all mails send via SMTP. Best for testing or staging environments.
5
+
6
+ At the moment, this library is only tested with Rails 2.3.8
7
+
8
+ == Usage
9
+
10
+ Load the gem
11
+
12
+ config.gem "action_mailer_test_mailing"
13
+
14
+ and in you staging.rb (environment file) you can configure this mode
15
+
16
+ require "action_mailer_test_mailing"
17
+ config.action_mailer.delivery_method = :test_via_smtp
18
+ config.action_mailer.test_recipient = "andi@galaxycats.com"
19
+
20
+ now every single mail will be sent to the test_recipient, prefixed with the original recipient.
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.
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 < ActionMailerTestMailing::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
+
53
+ == Note on Patches/Pull Requests
54
+
55
+ * Fork the project.
56
+ * Make your feature addition or bug fix.
57
+ * Add tests for it. This is important so I don't break it in a
58
+ future version unintentionally.
59
+ * Commit, do not mess with rakefile, version, or history.
60
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
61
+ * Send me a pull request. Bonus points for topic branches.
62
+
63
+ == Copyright
64
+
65
+ Copyright (c) 2010 Galaxy Cats IT Consulting GmbH. See LICENSE for details.
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "action_mailer_test_mailing"
8
+ gem.summary = %Q{test mails via smtp with actionmailer}
9
+ gem.description = %Q{Set one test-reciepient which gets all mails from th app in for example a test/staging environment }
10
+ gem.email = "andi@galaxycats.com"
11
+ gem.homepage = "http://github.com/galaxycats/action_mailer_test_mailing"
12
+ gem.authors = ["Andi Bade"]
13
+ # gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/*_test.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/*_test.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "action_mailer_test_mailing #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{action_mailer_test_mailing}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andi Bade"]
12
+ s.date = %q{2010-08-12}
13
+ s.description = %q{Set one test-reciepient which gets all mails from th app in for example a test/staging environment }
14
+ s.email = %q{andi@galaxycats.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "Gemfile",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "action_mailer_test_mailing.gemspec",
28
+ "action_mailer_test_via_smtp.gemspec",
29
+ "lib/action_mailer_test_mailing.rb",
30
+ "lib/action_mailer_test_mailing/header_renderer/base.rb",
31
+ "lib/action_mailer_test_mailing/header_renderer/standard.rb",
32
+ "test/action_mailer_test_mailing_test.rb",
33
+ "test/templates/notifier/multipart_email.text.html.erb",
34
+ "test/templates/notifier/multipart_email.text.plain.erb",
35
+ "test/templates/notifier/plain_text_email.erb",
36
+ "test/test_helper.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/galaxycats/action_mailer_test_mailing}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.6}
42
+ s.summary = %q{test mails via smtp with actionmailer}
43
+ s.test_files = [
44
+ "test/action_mailer_test_mailing_test.rb",
45
+ "test/test_helper.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
53
+ else
54
+ end
55
+ else
56
+ end
57
+ end
58
+
@@ -0,0 +1,57 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{action_mailer_test_mailing}
8
+ s.version = "0.2.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andi Bade"]
12
+ s.date = %q{2010-08-12}
13
+ s.description = %q{Set one test-reciepient which gets all mails from th app in for example a test/staging environment }
14
+ s.email = %q{andi@galaxycats.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "Gemfile",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "action_mailer_test_mailing.gemspec",
28
+ "lib/action_mailer_test_mailing.rb",
29
+ "lib/action_mailer_test_mailing/header_renderer/base.rb",
30
+ "lib/action_mailer_test_mailing/header_renderer/standard.rb",
31
+ "test/action_mailer_test_mailing_test.rb",
32
+ "test/templates/notifier/multipart_email.text.html.erb",
33
+ "test/templates/notifier/multipart_email.text.plain.erb",
34
+ "test/templates/notifier/plain_text_email.erb",
35
+ "test/test_helper.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/galaxycats/action_mailer_test_mailing}
38
+ s.rdoc_options = ["--charset=UTF-8"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.6}
41
+ s.summary = %q{test mails via smtp with actionmailer}
42
+ s.test_files = [
43
+ "test/action_mailer_test_mailing_test.rb",
44
+ "test/test_helper.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ else
53
+ end
54
+ else
55
+ end
56
+ end
57
+
@@ -0,0 +1,46 @@
1
+ require "action_mailer_test_mailing/header_renderer/standard"
2
+
3
+ module ActionMailer
4
+ class Base
5
+ @@test_recipient = false
6
+ cattr_accessor :test_recipient
7
+
8
+ @@test_mail_header_renderer = ActionMailerTestMailing::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
+
15
+ def generate_test_mail_header(mail)
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
21
+ end
22
+
23
+ [:sendmail, :smtp, :test].each do |meth|
24
+ define_method "perform_delivery_test_via_#{meth}" do |mail|
25
+ if mail.multipart?
26
+ mail.each_part do |part|
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
32
+ end
33
+ else
34
+ mail.body = generate_test_mail_header(mail) + mail.body
35
+ end
36
+ mail.to = self.class.test_recipient
37
+ mail.cc = nil
38
+ mail.bcc = nil
39
+ send("perform_delivery_#{meth}", mail)
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ module ActionMailerTestMailing
46
+ end
@@ -0,0 +1,13 @@
1
+ module ActionMailerTestMailing
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_mailing/header_renderer/base"
2
+
3
+ module ActionMailerTestMailing
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
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+
3
+ class ActionMailerTestMailingTest < 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).at_least_once.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
+ 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
26
+ end
27
+ end
28
+
29
+ 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_mailing"
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 ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: action_mailer_test_mailing
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
+ platform: ruby
11
+ authors:
12
+ - Andi Bade
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-12 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: "Set one test-reciepient which gets all mails from th app in for example a test/staging environment "
22
+ email: andi@galaxycats.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README.rdoc
30
+ files:
31
+ - .document
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - VERSION
38
+ - action_mailer_test_mailing.gemspec
39
+ - action_mailer_test_via_smtp.gemspec
40
+ - lib/action_mailer_test_mailing.rb
41
+ - lib/action_mailer_test_mailing/header_renderer/base.rb
42
+ - lib/action_mailer_test_mailing/header_renderer/standard.rb
43
+ - test/action_mailer_test_mailing_test.rb
44
+ - test/templates/notifier/multipart_email.text.html.erb
45
+ - test/templates/notifier/multipart_email.text.plain.erb
46
+ - test/templates/notifier/plain_text_email.erb
47
+ - test/test_helper.rb
48
+ has_rdoc: true
49
+ homepage: http://github.com/galaxycats/action_mailer_test_mailing
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options:
54
+ - --charset=UTF-8
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.3.6
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: test mails via smtp with actionmailer
78
+ test_files:
79
+ - test/action_mailer_test_mailing_test.rb
80
+ - test/test_helper.rb