bitlove-resque_mailer 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +3 -0
- data/CHANGELOG.md +25 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +83 -0
- data/LICENSE +20 -0
- data/README.md +97 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/bitlove-resque_mailer.gemspec +77 -0
- data/lib/resque_mailer.rb +90 -0
- data/rails/init.rb +1 -0
- data/resque_mailer.gemspec +77 -0
- data/spec/resque_mailer_spec.rb +102 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +225 -0
data/.document
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
### 2.0.2 / 2011-08-20
|
2
|
+
|
3
|
+
* Fixed deliver vs deliver! issue so mail interceptors will work as
|
4
|
+
expected
|
5
|
+
|
6
|
+
### 2.0.1 / 2011-08-19
|
7
|
+
|
8
|
+
* Restore the mailer proxy object so mailer method bodies never get
|
9
|
+
invoked more than once accidentally (not required to be idempotent)
|
10
|
+
|
11
|
+
### 2.0.0 / 2011-06-24
|
12
|
+
|
13
|
+
* Removed support for legacy Rails 2.x applications (please use v1.x)
|
14
|
+
* Removed mailer proxy, return Mail::Message object
|
15
|
+
* Reorganize and modernize gem structure, add bundler and move to RSpec 2.x
|
16
|
+
* Queue target (::Resque) can now be overridden for testing (Joshua
|
17
|
+
Clayton)
|
18
|
+
|
19
|
+
### 1.0.1 / 2010-12-21
|
20
|
+
|
21
|
+
* Respect ActionMailer::Base.perform_deliveries
|
22
|
+
|
23
|
+
### v1.0.0 / 2010-07-28
|
24
|
+
|
25
|
+
* Added support for Rails 3.x (Marcin Kulik)
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
# Add dependencies required to use your gem here.
|
4
|
+
# Example:
|
5
|
+
# gem 'activesupport', '>= 2.3.5'
|
6
|
+
|
7
|
+
gem 'resque', '>= 1.2.3'
|
8
|
+
gem 'actionmailer', '>= 3.0.0'
|
9
|
+
|
10
|
+
# Add dependencies to develop your gem here.
|
11
|
+
# Include everything needed to run rake, tests, features, etc.
|
12
|
+
group :development do
|
13
|
+
gem 'rspec', '>= 2.6.0'
|
14
|
+
gem 'yard', '>= 0.6.0'
|
15
|
+
gem 'bundler', '~> 1.0.0'
|
16
|
+
gem 'jeweler', '~> 1.6.2'
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.9)
|
6
|
+
actionpack (= 3.0.9)
|
7
|
+
mail (~> 2.2.19)
|
8
|
+
actionpack (3.0.9)
|
9
|
+
activemodel (= 3.0.9)
|
10
|
+
activesupport (= 3.0.9)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.14)
|
16
|
+
rack-test (~> 0.5.7)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.9)
|
19
|
+
activesupport (= 3.0.9)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.5.0)
|
22
|
+
activesupport (3.0.9)
|
23
|
+
builder (2.1.2)
|
24
|
+
diff-lcs (1.1.2)
|
25
|
+
erubis (2.6.6)
|
26
|
+
abstract (>= 1.0.0)
|
27
|
+
git (1.2.5)
|
28
|
+
i18n (0.5.0)
|
29
|
+
jeweler (1.6.2)
|
30
|
+
bundler (~> 1.0)
|
31
|
+
git (>= 1.2.5)
|
32
|
+
rake
|
33
|
+
json (1.5.3)
|
34
|
+
mail (2.2.19)
|
35
|
+
activesupport (>= 2.3.6)
|
36
|
+
i18n (>= 0.4.0)
|
37
|
+
mime-types (~> 1.16)
|
38
|
+
treetop (~> 1.4.8)
|
39
|
+
mime-types (1.16)
|
40
|
+
polyglot (0.3.1)
|
41
|
+
rack (1.2.3)
|
42
|
+
rack-mount (0.6.14)
|
43
|
+
rack (>= 1.0.0)
|
44
|
+
rack-test (0.5.7)
|
45
|
+
rack (>= 1.0)
|
46
|
+
rake (0.9.2)
|
47
|
+
redis (2.2.1)
|
48
|
+
redis-namespace (1.0.3)
|
49
|
+
redis (< 3.0.0)
|
50
|
+
resque (1.17.1)
|
51
|
+
json (>= 1.4.6, < 1.6)
|
52
|
+
redis-namespace (~> 1.0.2)
|
53
|
+
sinatra (>= 0.9.2)
|
54
|
+
vegas (~> 0.1.2)
|
55
|
+
rspec (2.6.0)
|
56
|
+
rspec-core (~> 2.6.0)
|
57
|
+
rspec-expectations (~> 2.6.0)
|
58
|
+
rspec-mocks (~> 2.6.0)
|
59
|
+
rspec-core (2.6.4)
|
60
|
+
rspec-expectations (2.6.0)
|
61
|
+
diff-lcs (~> 1.1.2)
|
62
|
+
rspec-mocks (2.6.0)
|
63
|
+
sinatra (1.2.6)
|
64
|
+
rack (~> 1.1)
|
65
|
+
tilt (>= 1.2.2, < 2.0)
|
66
|
+
tilt (1.3.2)
|
67
|
+
treetop (1.4.9)
|
68
|
+
polyglot (>= 0.3.1)
|
69
|
+
tzinfo (0.3.28)
|
70
|
+
vegas (0.1.8)
|
71
|
+
rack (>= 1.0.0)
|
72
|
+
yard (0.7.2)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
ruby
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
actionmailer (>= 3.0.0)
|
79
|
+
bundler (~> 1.0.0)
|
80
|
+
jeweler (~> 1.6.2)
|
81
|
+
resque (>= 1.2.3)
|
82
|
+
rspec (>= 2.6.0)
|
83
|
+
yard (>= 0.6.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Nick Plante
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# ResqueMailer
|
2
|
+
|
3
|
+
A gem plugin which allows messages prepared by ActionMailer to be delivered
|
4
|
+
asynchronously. Assumes you're using Resque (http://github.com/defunkt/resque)
|
5
|
+
for your background jobs.
|
6
|
+
|
7
|
+
Note that recent (2.0+) versions of Resque::Mailer only work with Rails 3.x.
|
8
|
+
For a version compatible with Rails 2, specify v1.x in your Gemfile.
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
Include Resque::Mailer in your ActionMailer subclass(es) like this:
|
13
|
+
|
14
|
+
class MyMailer < ActionMailer::Base
|
15
|
+
include Resque::Mailer
|
16
|
+
end
|
17
|
+
|
18
|
+
Now, when <tt>MyMailer.subject_email(params).deliver</tt> is called, an entry
|
19
|
+
will be created in the job queue. Your Resque workers will be able to deliver
|
20
|
+
this message for you. The queue we're using is imaginatively named +mailer+,
|
21
|
+
so just make sure your workers know about it and are loading your environment:
|
22
|
+
|
23
|
+
QUEUE=mailer rake environment resque:work
|
24
|
+
|
25
|
+
Note that you can still have mail delivered synchronously by using the bang
|
26
|
+
method variant:
|
27
|
+
|
28
|
+
MyMailer.subject_email(params).deliver!
|
29
|
+
|
30
|
+
Oh, by the way. Don't forget that your async mailer jobs will be processed by
|
31
|
+
a separate worker. This means that you should resist the temptation to pass
|
32
|
+
database-backed objects as parameters in your mailer and instead pass record
|
33
|
+
identifiers. Then, in your delivery method, you can look up the record from
|
34
|
+
the id and use it as needed.
|
35
|
+
|
36
|
+
If you want to set a different default queue name for your mailer, you can
|
37
|
+
change the <tt>default_queue_name</tt> property like so:
|
38
|
+
|
39
|
+
# config/initializers/resque_mailer.rb
|
40
|
+
Resque::Mailer.default_queue_name = 'application_specific_mailer'
|
41
|
+
|
42
|
+
This is useful when you are running more than one application using
|
43
|
+
resque_mailer in a shared environment. You will need to use the new queue
|
44
|
+
name when starting your workers.
|
45
|
+
|
46
|
+
QUEUE=application_specific_mailer rake environment resque:work
|
47
|
+
|
48
|
+
## Resque::Mailer as a Project Default
|
49
|
+
|
50
|
+
If you have a variety of mailers in your application and want all of them to use
|
51
|
+
Resque::Mailer by default, you can subclass ActionMailer::Base and have your
|
52
|
+
other mailers inherit from an AsyncMailer:
|
53
|
+
|
54
|
+
# config/initializers/resque_mailer.rb
|
55
|
+
class AsyncMailer < ActionMailer::Base
|
56
|
+
include Resque::Mailer
|
57
|
+
end
|
58
|
+
|
59
|
+
# app/mailers/example_mailer.rb
|
60
|
+
class ExampleMailer < AsyncMailer
|
61
|
+
def say_hello(user)
|
62
|
+
# ...
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
## Installation
|
67
|
+
|
68
|
+
Install it as a plugin or as a gem plugin from Gemcutter:
|
69
|
+
|
70
|
+
gem install resque_mailer
|
71
|
+
script/plugin install git://github.com/zapnap/resque_mailer.git
|
72
|
+
|
73
|
+
# Rails 3: add it to your Gemfile
|
74
|
+
gem 'resque_mailer'
|
75
|
+
|
76
|
+
## Testing
|
77
|
+
|
78
|
+
You don't want to be sending actual emails in the test environment, so you can
|
79
|
+
configure the environments that should be excluded like so:
|
80
|
+
|
81
|
+
# config/initializers/resque_mailer.rb
|
82
|
+
Resque::Mailer.excluded_environments = [:test, :cucumber]
|
83
|
+
|
84
|
+
## Note on Patches / Pull Requests
|
85
|
+
|
86
|
+
* Fork the project.
|
87
|
+
* Make your feature addition or bug fix.
|
88
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
89
|
+
* Commit, do not mess with rakefile, version, or history.
|
90
|
+
(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)
|
91
|
+
* Send me a pull request. Bonus points for topic branches.
|
92
|
+
|
93
|
+
## Credits
|
94
|
+
|
95
|
+
This work was originally inspired by delayed_job_mailer
|
96
|
+
(http://github.com/andersondias/delayed_job_mailer) by Anderson Dias. Enhanced
|
97
|
+
and modified to work with Resque by Nick Plante.
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
begin
|
7
|
+
Bundler.setup(:default, :development)
|
8
|
+
rescue Bundler::BundlerError => e
|
9
|
+
$stderr.puts e.message
|
10
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
11
|
+
exit e.status_code
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rake'
|
15
|
+
|
16
|
+
begin
|
17
|
+
require 'jeweler'
|
18
|
+
Jeweler::Tasks.new do |gem|
|
19
|
+
gem.name = "bitlove-resque_mailer"
|
20
|
+
gem.summary = %Q{Rails plugin for sending asynchronous email with ActionMailer and Resque}
|
21
|
+
gem.description = %Q{Rails plugin for sending asynchronous email with ActionMailer and Resque}
|
22
|
+
gem.email = "nap@zerosum.org"
|
23
|
+
gem.homepage = "http://github.com/zapnap/resque_mailer"
|
24
|
+
gem.authors = ["Nick Plante"]
|
25
|
+
gem.add_development_dependency "rspec", ">= 2.6.0"
|
26
|
+
gem.add_development_dependency "resque", ">= 1.2.3"
|
27
|
+
gem.add_development_dependency "actionmailer", ">= 3.0.0"
|
28
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
rescue LoadError
|
32
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'rspec/core'
|
36
|
+
require 'rspec/core/rake_task'
|
37
|
+
|
38
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
39
|
+
spec.pattern = ["spec/resque_mailer_spec.rb"]
|
40
|
+
end
|
41
|
+
|
42
|
+
task :default => :spec
|
43
|
+
|
44
|
+
require 'yard'
|
45
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.3
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "bitlove-resque_mailer"
|
8
|
+
s.version = "2.0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nick Plante"]
|
12
|
+
s.date = "2011-10-05"
|
13
|
+
s.description = "Rails plugin for sending asynchronous email with ActionMailer and Resque"
|
14
|
+
s.email = "nap@zerosum.org"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"CHANGELOG.md",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bitlove-resque_mailer.gemspec",
|
29
|
+
"lib/resque_mailer.rb",
|
30
|
+
"rails/init.rb",
|
31
|
+
"resque_mailer.gemspec",
|
32
|
+
"spec/resque_mailer_spec.rb",
|
33
|
+
"spec/spec.opts",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = "http://github.com/zapnap/resque_mailer"
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = "1.3.9.3"
|
39
|
+
s.summary = "Rails plugin for sending asynchronous email with ActionMailer and Resque"
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<resque>, [">= 1.2.3"])
|
46
|
+
s.add_runtime_dependency(%q<actionmailer>, [">= 3.0.0"])
|
47
|
+
s.add_development_dependency(%q<rspec>, [">= 2.6.0"])
|
48
|
+
s.add_development_dependency(%q<yard>, [">= 0.6.0"])
|
49
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 2.6.0"])
|
52
|
+
s.add_development_dependency(%q<resque>, [">= 1.2.3"])
|
53
|
+
s.add_development_dependency(%q<actionmailer>, [">= 3.0.0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<resque>, [">= 1.2.3"])
|
56
|
+
s.add_dependency(%q<actionmailer>, [">= 3.0.0"])
|
57
|
+
s.add_dependency(%q<rspec>, [">= 2.6.0"])
|
58
|
+
s.add_dependency(%q<yard>, [">= 0.6.0"])
|
59
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
61
|
+
s.add_dependency(%q<rspec>, [">= 2.6.0"])
|
62
|
+
s.add_dependency(%q<resque>, [">= 1.2.3"])
|
63
|
+
s.add_dependency(%q<actionmailer>, [">= 3.0.0"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<resque>, [">= 1.2.3"])
|
67
|
+
s.add_dependency(%q<actionmailer>, [">= 3.0.0"])
|
68
|
+
s.add_dependency(%q<rspec>, [">= 2.6.0"])
|
69
|
+
s.add_dependency(%q<yard>, [">= 0.6.0"])
|
70
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
72
|
+
s.add_dependency(%q<rspec>, [">= 2.6.0"])
|
73
|
+
s.add_dependency(%q<resque>, [">= 1.2.3"])
|
74
|
+
s.add_dependency(%q<actionmailer>, [">= 3.0.0"])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Resque
|
2
|
+
module Mailer
|
3
|
+
class << self
|
4
|
+
attr_accessor :default_queue_name, :default_queue_target
|
5
|
+
attr_reader :excluded_environments
|
6
|
+
|
7
|
+
def excluded_environments=(envs)
|
8
|
+
@excluded_environments = [*envs].map { |e| e.to_sym }
|
9
|
+
end
|
10
|
+
|
11
|
+
def included(base)
|
12
|
+
base.extend(ClassMethods)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
self.default_queue_target = ::Resque
|
17
|
+
self.default_queue_name = "mailer"
|
18
|
+
self.excluded_environments = [:test]
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
def current_env
|
22
|
+
::Rails.env
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(method_name, *args)
|
26
|
+
return super if environment_excluded?
|
27
|
+
|
28
|
+
if action_methods.include?(method_name.to_s)
|
29
|
+
MessageDecoy.new(self, method_name, *args)
|
30
|
+
else
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def perform(action, *args)
|
36
|
+
self.send(:new, action, *args).message.deliver
|
37
|
+
end
|
38
|
+
|
39
|
+
def environment_excluded?
|
40
|
+
!ActionMailer::Base.perform_deliveries || excluded_environment?(current_env)
|
41
|
+
end
|
42
|
+
|
43
|
+
def queue
|
44
|
+
::Resque::Mailer.default_queue_name
|
45
|
+
end
|
46
|
+
|
47
|
+
def resque
|
48
|
+
::Resque::Mailer.default_queue_target
|
49
|
+
end
|
50
|
+
|
51
|
+
def excluded_environment?(name)
|
52
|
+
::Resque::Mailer.excluded_environments && ::Resque::Mailer.excluded_environments.include?(name.to_sym)
|
53
|
+
end
|
54
|
+
|
55
|
+
def deliver?
|
56
|
+
true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class MessageDecoy
|
61
|
+
def initialize(mailer_class, method_name, *args)
|
62
|
+
@mailer_class = mailer_class
|
63
|
+
@method_name = method_name
|
64
|
+
*@args = *args
|
65
|
+
end
|
66
|
+
|
67
|
+
def resque
|
68
|
+
::Resque::Mailer.default_queue_target
|
69
|
+
end
|
70
|
+
|
71
|
+
def actual_message
|
72
|
+
@actual_message ||= @mailer_class.send(:new, @method_name, *@args).message
|
73
|
+
end
|
74
|
+
|
75
|
+
def deliver
|
76
|
+
if @mailer_class.deliver?
|
77
|
+
resque.enqueue(@mailer_class, @method_name, *@args)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def deliver!
|
82
|
+
actual_message.deliver!
|
83
|
+
end
|
84
|
+
|
85
|
+
def method_missing(method_name, *args)
|
86
|
+
actual_message.send(method_name, *args)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib', 'resque_mailer'))
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{resque_mailer}
|
8
|
+
s.version = "2.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nick Plante"]
|
12
|
+
s.date = %q{2011-08-20}
|
13
|
+
s.description = %q{Rails plugin for sending asynchronous email with ActionMailer and Resque}
|
14
|
+
s.email = %q{nap@zerosum.org}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"CHANGELOG.md",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE",
|
25
|
+
"README.md",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/resque_mailer.rb",
|
29
|
+
"rails/init.rb",
|
30
|
+
"resque_mailer.gemspec",
|
31
|
+
"spec/resque_mailer_spec.rb",
|
32
|
+
"spec/spec.opts",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/zapnap/resque_mailer}
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.7}
|
38
|
+
s.summary = %q{Rails plugin for sending asynchronous email with ActionMailer and Resque}
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
+
s.specification_version = 3
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_runtime_dependency(%q<resque>, [">= 1.2.3"])
|
46
|
+
s.add_runtime_dependency(%q<actionmailer>, [">= 3.0.0"])
|
47
|
+
s.add_development_dependency(%q<rspec>, [">= 2.6.0"])
|
48
|
+
s.add_development_dependency(%q<yard>, [">= 0.6.0"])
|
49
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 2.6.0"])
|
52
|
+
s.add_development_dependency(%q<resque>, [">= 1.2.3"])
|
53
|
+
s.add_development_dependency(%q<actionmailer>, [">= 3.0.0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<resque>, [">= 1.2.3"])
|
56
|
+
s.add_dependency(%q<actionmailer>, [">= 3.0.0"])
|
57
|
+
s.add_dependency(%q<rspec>, [">= 2.6.0"])
|
58
|
+
s.add_dependency(%q<yard>, [">= 0.6.0"])
|
59
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
61
|
+
s.add_dependency(%q<rspec>, [">= 2.6.0"])
|
62
|
+
s.add_dependency(%q<resque>, [">= 1.2.3"])
|
63
|
+
s.add_dependency(%q<actionmailer>, [">= 3.0.0"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<resque>, [">= 1.2.3"])
|
67
|
+
s.add_dependency(%q<actionmailer>, [">= 3.0.0"])
|
68
|
+
s.add_dependency(%q<rspec>, [">= 2.6.0"])
|
69
|
+
s.add_dependency(%q<yard>, [">= 0.6.0"])
|
70
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
72
|
+
s.add_dependency(%q<rspec>, [">= 2.6.0"])
|
73
|
+
s.add_dependency(%q<resque>, [">= 1.2.3"])
|
74
|
+
s.add_dependency(%q<actionmailer>, [">= 3.0.0"])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
|
2
|
+
|
3
|
+
class FakeResque
|
4
|
+
def self.enqueue(*args); end
|
5
|
+
end
|
6
|
+
|
7
|
+
class Rails3Mailer < ActionMailer::Base
|
8
|
+
include Resque::Mailer
|
9
|
+
default :from => "from@example.org", :subject => "Subject"
|
10
|
+
MAIL_PARAMS = { :to => "crafty@example.org" }
|
11
|
+
|
12
|
+
def test_mail(*params)
|
13
|
+
Resque::Mailer.success!
|
14
|
+
mail(*params)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe Resque::Mailer do
|
19
|
+
let(:resque) { FakeResque }
|
20
|
+
|
21
|
+
before do
|
22
|
+
Resque::Mailer.default_queue_target = resque
|
23
|
+
Resque::Mailer.stub(:success!)
|
24
|
+
Rails3Mailer.stub(:current_env => :test)
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "resque" do
|
28
|
+
it "allows overriding of the default queue target (for testing)" do
|
29
|
+
Resque::Mailer.default_queue_target = FakeResque
|
30
|
+
Rails3Mailer.resque.should == FakeResque
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "queue" do
|
35
|
+
it "defaults to the 'mailer' queue" do
|
36
|
+
Rails3Mailer.queue.should == "mailer"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "allows overriding of the default queue name" do
|
40
|
+
Resque::Mailer.default_queue_name = "postal"
|
41
|
+
Rails3Mailer.queue.should == "postal"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#deliver' do
|
46
|
+
before(:all) do
|
47
|
+
@delivery = lambda {
|
48
|
+
Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).deliver
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should not deliver the email synchronously' do
|
53
|
+
lambda { @delivery.call }.should_not change(ActionMailer::Base.deliveries, :size)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should place the deliver action on the Resque "mailer" queue' do
|
57
|
+
resque.should_receive(:enqueue).with(Rails3Mailer, :test_mail, Rails3Mailer::MAIL_PARAMS)
|
58
|
+
@delivery.call
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when current env is excluded" do
|
62
|
+
it 'should not deliver through Resque for excluded environments' do
|
63
|
+
Resque::Mailer.stub(:excluded_environments => [:custom])
|
64
|
+
Rails3Mailer.should_receive(:current_env).and_return(:custom)
|
65
|
+
resque.should_not_receive(:enqueue)
|
66
|
+
@delivery.call
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should not invoke the method body more than once' do
|
71
|
+
Resque::Mailer.should_not_receive(:success!)
|
72
|
+
Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).deliver
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#deliver!' do
|
77
|
+
it 'should deliver the email synchronously' do
|
78
|
+
lambda { Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).deliver! }.should change(ActionMailer::Base.deliveries, :size).by(1)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'perform' do
|
83
|
+
it 'should perform a queued mailer job' do
|
84
|
+
lambda {
|
85
|
+
Rails3Mailer.perform(:test_mail, Rails3Mailer::MAIL_PARAMS)
|
86
|
+
}.should change(ActionMailer::Base.deliveries, :size).by(1)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'original mail methods' do
|
91
|
+
it 'should be preserved' do
|
92
|
+
Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).subject.should == 'Subject'
|
93
|
+
Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).from.should include('from@example.org')
|
94
|
+
Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).to.should include('crafty@example.org')
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should require execution of the method body prior to queueing' do
|
98
|
+
Resque::Mailer.should_receive(:success!).once
|
99
|
+
Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).subject
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'action_mailer'
|
5
|
+
require 'resque_mailer'
|
6
|
+
require 'rspec/autorun'
|
7
|
+
|
8
|
+
Resque::Mailer.excluded_environments = []
|
9
|
+
ActionMailer::Base.delivery_method = :test
|
metadata
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bitlove-resque_mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 2.0.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nick Plante
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-05 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 25
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 2
|
31
|
+
- 3
|
32
|
+
version: 1.2.3
|
33
|
+
prerelease: false
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
name: resque
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 7
|
44
|
+
segments:
|
45
|
+
- 3
|
46
|
+
- 0
|
47
|
+
- 0
|
48
|
+
version: 3.0.0
|
49
|
+
prerelease: false
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
name: actionmailer
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 23
|
60
|
+
segments:
|
61
|
+
- 2
|
62
|
+
- 6
|
63
|
+
- 0
|
64
|
+
version: 2.6.0
|
65
|
+
prerelease: false
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id003
|
68
|
+
name: rspec
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 7
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
- 6
|
79
|
+
- 0
|
80
|
+
version: 0.6.0
|
81
|
+
prerelease: false
|
82
|
+
type: :development
|
83
|
+
version_requirements: *id004
|
84
|
+
name: yard
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ~>
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 23
|
92
|
+
segments:
|
93
|
+
- 1
|
94
|
+
- 0
|
95
|
+
- 0
|
96
|
+
version: 1.0.0
|
97
|
+
prerelease: false
|
98
|
+
type: :development
|
99
|
+
version_requirements: *id005
|
100
|
+
name: bundler
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ~>
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 11
|
108
|
+
segments:
|
109
|
+
- 1
|
110
|
+
- 6
|
111
|
+
- 2
|
112
|
+
version: 1.6.2
|
113
|
+
prerelease: false
|
114
|
+
type: :development
|
115
|
+
version_requirements: *id006
|
116
|
+
name: jeweler
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 23
|
124
|
+
segments:
|
125
|
+
- 2
|
126
|
+
- 6
|
127
|
+
- 0
|
128
|
+
version: 2.6.0
|
129
|
+
prerelease: false
|
130
|
+
type: :development
|
131
|
+
version_requirements: *id007
|
132
|
+
name: rspec
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
hash: 25
|
140
|
+
segments:
|
141
|
+
- 1
|
142
|
+
- 2
|
143
|
+
- 3
|
144
|
+
version: 1.2.3
|
145
|
+
prerelease: false
|
146
|
+
type: :development
|
147
|
+
version_requirements: *id008
|
148
|
+
name: resque
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
hash: 7
|
156
|
+
segments:
|
157
|
+
- 3
|
158
|
+
- 0
|
159
|
+
- 0
|
160
|
+
version: 3.0.0
|
161
|
+
prerelease: false
|
162
|
+
type: :development
|
163
|
+
version_requirements: *id009
|
164
|
+
name: actionmailer
|
165
|
+
description: Rails plugin for sending asynchronous email with ActionMailer and Resque
|
166
|
+
email: nap@zerosum.org
|
167
|
+
executables: []
|
168
|
+
|
169
|
+
extensions: []
|
170
|
+
|
171
|
+
extra_rdoc_files:
|
172
|
+
- LICENSE
|
173
|
+
- README.md
|
174
|
+
files:
|
175
|
+
- .document
|
176
|
+
- CHANGELOG.md
|
177
|
+
- Gemfile
|
178
|
+
- Gemfile.lock
|
179
|
+
- LICENSE
|
180
|
+
- README.md
|
181
|
+
- Rakefile
|
182
|
+
- VERSION
|
183
|
+
- bitlove-resque_mailer.gemspec
|
184
|
+
- lib/resque_mailer.rb
|
185
|
+
- rails/init.rb
|
186
|
+
- resque_mailer.gemspec
|
187
|
+
- spec/resque_mailer_spec.rb
|
188
|
+
- spec/spec.opts
|
189
|
+
- spec/spec_helper.rb
|
190
|
+
has_rdoc: true
|
191
|
+
homepage: http://github.com/zapnap/resque_mailer
|
192
|
+
licenses: []
|
193
|
+
|
194
|
+
post_install_message:
|
195
|
+
rdoc_options: []
|
196
|
+
|
197
|
+
require_paths:
|
198
|
+
- lib
|
199
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
200
|
+
none: false
|
201
|
+
requirements:
|
202
|
+
- - ">="
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
hash: 3
|
205
|
+
segments:
|
206
|
+
- 0
|
207
|
+
version: "0"
|
208
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
|
+
none: false
|
210
|
+
requirements:
|
211
|
+
- - ">="
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
hash: 3
|
214
|
+
segments:
|
215
|
+
- 0
|
216
|
+
version: "0"
|
217
|
+
requirements: []
|
218
|
+
|
219
|
+
rubyforge_project:
|
220
|
+
rubygems_version: 1.3.9.3
|
221
|
+
signing_key:
|
222
|
+
specification_version: 3
|
223
|
+
summary: Rails plugin for sending asynchronous email with ActionMailer and Resque
|
224
|
+
test_files: []
|
225
|
+
|