inaction_mailer 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +11 -0
- data/Rakefile +51 -0
- data/lib/inaction_mailer.rb +38 -0
- data/lib/inaction_mailer/force_load.rb +15 -0
- data/rails/init.rb +1 -0
- data/test/functional_test.rb +31 -0
- data/test/test_helper.rb +63 -0
- metadata +64 -0
data/README.markdown
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
## Usage:
|
2
|
+
|
3
|
+
Add the following lines to the appropriate `config/environments/*.rb` file:
|
4
|
+
|
5
|
+
config.gem "cwninja-inaction_mailer", :lib => 'inaction_mailer/force_load', :source => 'http://gems.github.com'
|
6
|
+
|
7
|
+
As an extra step, for the sake of paranoia, you can check the delivery mechanism with:
|
8
|
+
|
9
|
+
./script/runner 'p ActionMailer::Base.delivery_method'
|
10
|
+
|
11
|
+
Now when you app send e-mails, it will deliver them to `RAILS_ROOT/tmp/sent_mails/mail.*.txt`.
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'rake/gempackagetask'
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
desc 'Default: run unit tests.'
|
9
|
+
task :default => :test
|
10
|
+
|
11
|
+
desc 'Test the inaction_mailer plugin.'
|
12
|
+
Rake::TestTask.new(:test) do |t|
|
13
|
+
t.libs << 'lib'
|
14
|
+
t.pattern = 'test/**/*_test.rb'
|
15
|
+
t.verbose = true
|
16
|
+
end
|
17
|
+
|
18
|
+
spec = Gem::Specification.new do |s|
|
19
|
+
s.name = %q{inaction_mailer}
|
20
|
+
s.version = "0.6"
|
21
|
+
s.summary = %q{An ActionMailer delivery mechanism to save mails as files in a directory.}
|
22
|
+
s.description = %q{An ActionMailer delivery mechanism to save mails as files in a directory.}
|
23
|
+
|
24
|
+
s.files = FileList['[A-Z]*', 'lib/**/*.rb', 'test/**/*.rb', 'rails/*']
|
25
|
+
s.require_path = 'lib'
|
26
|
+
s.test_files = Dir[*['test/**/*_test.rb']]
|
27
|
+
|
28
|
+
s.has_rdoc = true
|
29
|
+
s.extra_rdoc_files = ["README.markdown"]
|
30
|
+
s.rdoc_options = ['--line-numbers', '--inline-source', "--main", "README.markdown"]
|
31
|
+
|
32
|
+
s.authors = ["Tom Lea"]
|
33
|
+
s.email = %q{commits@tomlea.co.uk}
|
34
|
+
|
35
|
+
s.platform = Gem::Platform::RUBY
|
36
|
+
end
|
37
|
+
|
38
|
+
Rake::GemPackageTask.new spec do |pkg|
|
39
|
+
pkg.need_tar = true
|
40
|
+
pkg.need_zip = true
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Clean files generated by rake tasks"
|
44
|
+
task :clobber => [:clobber_rdoc, :clobber_package]
|
45
|
+
|
46
|
+
desc "Generate a gemspec file"
|
47
|
+
task :gemspec do
|
48
|
+
File.open("#{spec.name}.gemspec", 'w') do |f|
|
49
|
+
f.write spec.to_ruby
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module InactionMailer
|
2
|
+
|
3
|
+
def perform_delivery_inaction_file(mail)
|
4
|
+
mail.ready_to_send
|
5
|
+
InactionMailer.new_mail_file do |file|
|
6
|
+
file.write mail.encoded
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def hook!
|
12
|
+
ActionMailer::Base.__send__(:include, self) if defined? ActionMailer::Base
|
13
|
+
end
|
14
|
+
|
15
|
+
def new_mail_file(&block)
|
16
|
+
ensure_output_dir_exists
|
17
|
+
id = 0
|
18
|
+
id += 1 while File.exist? "#{output_dir}/mail.#{id}.txt"
|
19
|
+
File.open("#{output_dir}/mail.#{id}.txt", "w", &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
def output_dir
|
24
|
+
if defined? Rails.root
|
25
|
+
"#{Rails.root}/tmp/sent_mails"
|
26
|
+
else
|
27
|
+
"sent_mails"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def ensure_output_dir_exists
|
32
|
+
Dir.mkdir output_dir unless File.directory? output_dir
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
InactionMailer.hook!
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "inaction_mailer")
|
2
|
+
|
3
|
+
module InactionMailer::ForceLoad
|
4
|
+
# Overide the default mechanism rails uses to determine delivery method,
|
5
|
+
# and force it to always use :inaction_file
|
6
|
+
def self.hook!
|
7
|
+
ActionMailer::Base.instance_eval do
|
8
|
+
def delivery_method
|
9
|
+
:inaction_file
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
InactionMailer::ForceLoad.hook!
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib inaction_mailer])
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "test_helper")
|
2
|
+
|
3
|
+
class InactionMailerTest < Test::Unit::TestCase
|
4
|
+
class Mailer
|
5
|
+
include InactionMailer
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_should_write_mail_to_file
|
9
|
+
with_stubbed_file_store do
|
10
|
+
mailer = Mailer.new
|
11
|
+
mail_content = "Hello world, this is an e-mail!\n"*10
|
12
|
+
mail = stub(:ready_to_send => nil, :encoded => mail_content)
|
13
|
+
mailer.perform_delivery_inaction_file(mail)
|
14
|
+
assert_equal File.read("sent_mails/mail.0.txt"), mail_content
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_write_two_mails_to_files
|
19
|
+
with_stubbed_file_store do
|
20
|
+
mailer = Mailer.new
|
21
|
+
mail_1_content = "Hello world, this is an e-mail!"
|
22
|
+
mail_2_content = "I am a pirate, yarrr!"
|
23
|
+
mail1 = stub(:ready_to_send => nil, :encoded => mail_1_content)
|
24
|
+
mail2 = stub(:ready_to_send => nil, :encoded => mail_2_content)
|
25
|
+
mailer.perform_delivery_inaction_file(mail1)
|
26
|
+
mailer.perform_delivery_inaction_file(mail2)
|
27
|
+
assert_equal File.read("sent_mails/mail.0.txt"), mail_1_content
|
28
|
+
assert_equal File.read("sent_mails/mail.1.txt"), mail_2_content
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
2
|
+
require "inaction_mailer"
|
3
|
+
require "test/unit"
|
4
|
+
gem "mocha"
|
5
|
+
require "mocha"
|
6
|
+
|
7
|
+
class Test::Unit::TestCase
|
8
|
+
class FileSystemStub
|
9
|
+
attr_reader :fake_file_system
|
10
|
+
|
11
|
+
def initialize(fake_file_system = {})
|
12
|
+
@fake_file_system = fake_file_system
|
13
|
+
end
|
14
|
+
|
15
|
+
def open(filename, mode = "r")
|
16
|
+
@fake_file_system[filename] ||= StringIO.new if mode == "w"
|
17
|
+
raise Errno::ENOENT, "No such file or directory - #{filename}" unless @fake_file_system[filename]
|
18
|
+
@fake_file_system[filename].rewind
|
19
|
+
if block_given?
|
20
|
+
yield @fake_file_system[filename]
|
21
|
+
else
|
22
|
+
@fake_file_system[filename]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def read(filename)
|
27
|
+
File.open(filename, "r") do |io|
|
28
|
+
io.read
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def exist?(filename)
|
33
|
+
@fake_file_system.has_key? filename
|
34
|
+
end
|
35
|
+
|
36
|
+
def directory?(d)
|
37
|
+
@fake_file_system.has_key?(d.split("/").join("/") + "/")
|
38
|
+
end
|
39
|
+
|
40
|
+
def mkdir(d)
|
41
|
+
@fake_file_system[d.split("/").join("/") + "/"] = :directory
|
42
|
+
end
|
43
|
+
|
44
|
+
def method_missing(m, *args)
|
45
|
+
raise NotImplementedError, "You are using a stubbed file system, and File.#{m} was called, but the stubbed file system does not understand that menthod. Sorry."
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def with_stubbed_file_store(fake_file_system = {}, &block)
|
50
|
+
file_class = File
|
51
|
+
dir_class = Dir
|
52
|
+
Object.send :remove_const, :File
|
53
|
+
Object.const_set(:File, FileSystemStub.new(fake_file_system))
|
54
|
+
Object.send :remove_const, :Dir
|
55
|
+
Object.const_set(:Dir, File)
|
56
|
+
yield
|
57
|
+
ensure
|
58
|
+
Object.send :remove_const, :File
|
59
|
+
Object.const_set(:File, file_class)
|
60
|
+
Object.send :remove_const, :Dir
|
61
|
+
Object.const_set(:Dir, dir_class)
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inaction_mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.6"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom Lea
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-23 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: An ActionMailer delivery mechanism to save mails as files in a directory.
|
17
|
+
email: commits@tomlea.co.uk
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.markdown
|
24
|
+
files:
|
25
|
+
- Rakefile
|
26
|
+
- README.markdown
|
27
|
+
- lib/inaction_mailer/force_load.rb
|
28
|
+
- lib/inaction_mailer.rb
|
29
|
+
- test/functional_test.rb
|
30
|
+
- test/test_helper.rb
|
31
|
+
- rails/init.rb
|
32
|
+
has_rdoc: true
|
33
|
+
homepage:
|
34
|
+
licenses: []
|
35
|
+
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --line-numbers
|
39
|
+
- --inline-source
|
40
|
+
- --main
|
41
|
+
- README.markdown
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.3.5
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: An ActionMailer delivery mechanism to save mails as files in a directory.
|
63
|
+
test_files:
|
64
|
+
- test/functional_test.rb
|