resque_mailer 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ ### 2.0.0
2
+
3
+ * Removed support for legacy Rails 2.x applications (please use v1.x)
4
+ * Removed mailer proxy, return Mail::Message object
5
+ * Reorganize and modernize gem structure, add bundler and move to RSpec 2.x
6
+ * Queue target (::Resque) can now be overridden for testing (Joshua
7
+ Clayton)
8
+
9
+ ### 1.0.1 / 2010-12-21
10
+
11
+ * Respect ActionMailer::Base.perform_deliveries
12
+
13
+ ### v1.0.0 / 2010-07-28
14
+
15
+ * 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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010 Nick Plante
1
+ Copyright (c) 2011 Nick Plante
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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 CHANGED
@@ -1,4 +1,16 @@
1
+ # encoding: utf-8
2
+
1
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
+
2
14
  require 'rake'
3
15
 
4
16
  begin
@@ -9,52 +21,25 @@ begin
9
21
  gem.description = %Q{Rails plugin for sending asynchronous email with ActionMailer and Resque}
10
22
  gem.email = "nap@zerosum.org"
11
23
  gem.homepage = "http://github.com/zapnap/resque_mailer"
12
- gem.authors = ["Nick Plante", "Marcin Kulik"]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
24
+ gem.authors = ["Nick Plante"]
25
+ gem.add_development_dependency "rspec", ">= 2.6.0"
14
26
  gem.add_development_dependency "resque", ">= 1.2.3"
15
- gem.add_development_dependency "actionmailer", ">= 2.3.4"
27
+ gem.add_development_dependency "actionmailer", ">= 3.0.0"
16
28
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
29
  end
18
- Jeweler::GemcutterTasks.new
30
+ Jeweler::RubygemsDotOrgTasks.new
19
31
  rescue LoadError
20
32
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
33
  end
22
34
 
23
- begin
24
- require 'spec/rake/spectask'
25
-
26
- puts "Using RSpec 1.x / Rails 2.x"
27
-
28
- desc "Run specs for Rails 2.x"
29
- Spec::Rake::SpecTask.new(:spec) do |spec|
30
- spec.spec_files = FileList['spec/common_spec.rb', 'spec/rails2_spec.rb']
31
- end
32
- rescue LoadError
33
- puts "RSpec 1.x unavailable"
34
- end
35
-
36
- begin
37
- require 'rspec/core'
38
- require 'rspec/core/rake_task'
39
-
40
- puts "Using RSpec 2.x / Rails 3.x"
35
+ require 'rspec/core'
36
+ require 'rspec/core/rake_task'
41
37
 
42
- desc "Run specs for Rails 3.x"
43
- RSpec::Core::RakeTask.new(:spec) do |spec|
44
- spec.pattern = ["spec/common_spec.rb","spec/rails3_spec.rb"]
45
- end
46
- rescue LoadError
47
- puts "RSpec 2.x unavailable"
38
+ RSpec::Core::RakeTask.new(:spec) do |spec|
39
+ spec.pattern = ["spec/resque_mailer_spec.rb"]
48
40
  end
49
41
 
50
42
  task :default => :spec
51
43
 
52
- require 'rake/rdoctask'
53
- Rake::RDocTask.new do |rdoc|
54
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
55
-
56
- rdoc.rdoc_dir = 'rdoc'
57
- rdoc.title = "resque_mailer #{version}"
58
- rdoc.rdoc_files.include('README*')
59
- rdoc.rdoc_files.include('lib/**/*.rb')
60
- end
44
+ require 'yard'
45
+ YARD::Rake::YardocTask.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 2.0.0
data/lib/resque_mailer.rb CHANGED
@@ -1,7 +1,65 @@
1
- require "resque_mailer/common"
1
+ module Resque
2
+ module Mailer
3
+ class << self
4
+ attr_accessor :default_queue_name, :default_queue_target
5
+ attr_reader :excluded_environments
2
6
 
3
- if defined?(Rails.version) && Rails.version.to_i >= 3
4
- require "resque_mailer/rails3"
5
- else
6
- require "resque_mailer/rails2"
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
+ resque = self.resque
30
+ mailer_class = self
31
+ super.tap do |resque_mail|
32
+ resque_mail.class_eval do
33
+ define_method(:deliver) do
34
+ resque.enqueue(mailer_class, method_name, *args)
35
+ self
36
+ end
37
+ end
38
+ end
39
+ else
40
+ super
41
+ end
42
+ end
43
+
44
+ def perform(action, *args)
45
+ self.send(:new, action, *args).message.deliver!
46
+ end
47
+
48
+ def environment_excluded?
49
+ !ActionMailer::Base.perform_deliveries || excluded_environment?(current_env)
50
+ end
51
+
52
+ def queue
53
+ ::Resque::Mailer.default_queue_name
54
+ end
55
+
56
+ def resque
57
+ ::Resque::Mailer.default_queue_target
58
+ end
59
+
60
+ def excluded_environment?(name)
61
+ ::Resque::Mailer.excluded_environments && ::Resque::Mailer.excluded_environments.include?(name.to_sym)
62
+ end
63
+ end
64
+ end
7
65
  end
@@ -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.0"
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-06-24}
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
+
@@ -1,26 +1,45 @@
1
1
  require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
2
 
3
- gem 'actionmailer', '>=3.0.0.beta4'
4
- require 'action_mailer'
5
- require 'resque_mailer/rails3'
6
-
7
- ActionMailer::Base.delivery_method = :test
3
+ class FakeResque
4
+ def self.enqueue(*args); end
5
+ end
8
6
 
9
7
  class Rails3Mailer < ActionMailer::Base
10
8
  include Resque::Mailer
11
9
  default :from => "from@example.org", :subject => "Subject"
12
- MAIL_PARAMS = { :to => "misio@example.org" }
10
+ MAIL_PARAMS = { :to => "crafty@example.org" }
13
11
 
14
12
  def test_mail(*params)
15
13
  mail(*params)
16
14
  end
17
15
  end
18
16
 
19
- describe Rails3Mailer do
17
+ describe Resque::Mailer do
18
+ let(:resque) { FakeResque }
19
+
20
20
  before do
21
+ Resque::Mailer.default_queue_target = resque
21
22
  Rails3Mailer.stub(:current_env => :test)
22
23
  end
23
24
 
25
+ describe "resque" do
26
+ it "allows overriding of the default queue target (for testing)" do
27
+ Resque::Mailer.default_queue_target = FakeResque
28
+ Rails3Mailer.resque.should == FakeResque
29
+ end
30
+ end
31
+
32
+ describe "queue" do
33
+ it "defaults to the 'mailer' queue" do
34
+ Rails3Mailer.queue.should == "mailer"
35
+ end
36
+
37
+ it "allows overriding of the default queue name" do
38
+ Resque::Mailer.default_queue_name = "postal"
39
+ Rails3Mailer.queue.should == "postal"
40
+ end
41
+ end
42
+
24
43
  describe '#deliver' do
25
44
  before(:all) do
26
45
  @delivery = lambda {
@@ -28,16 +47,12 @@ describe Rails3Mailer do
28
47
  }
29
48
  end
30
49
 
31
- before(:each) do
32
- Resque.stub(:enqueue)
33
- end
34
-
35
50
  it 'should not deliver the email synchronously' do
36
51
  lambda { @delivery.call }.should_not change(ActionMailer::Base.deliveries, :size)
37
52
  end
38
53
 
39
54
  it 'should place the deliver action on the Resque "mailer" queue' do
40
- Resque.should_receive(:enqueue).with(Rails3Mailer, :test_mail, Rails3Mailer::MAIL_PARAMS)
55
+ resque.should_receive(:enqueue).with(Rails3Mailer, :test_mail, Rails3Mailer::MAIL_PARAMS)
41
56
  @delivery.call
42
57
  end
43
58
 
@@ -45,7 +60,7 @@ describe Rails3Mailer do
45
60
  it 'should not deliver through Resque for excluded environments' do
46
61
  Resque::Mailer.stub(:excluded_environments => [:custom])
47
62
  Rails3Mailer.should_receive(:current_env).and_return(:custom)
48
- Resque.should_not_receive(:enqueue)
63
+ resque.should_not_receive(:enqueue)
49
64
  @delivery.call
50
65
  end
51
66
  end
@@ -57,11 +72,19 @@ describe Rails3Mailer do
57
72
  end
58
73
  end
59
74
 
60
- describe ".perform" do
75
+ describe "perform" do
61
76
  it 'should perform a queued mailer job' do
62
77
  lambda {
63
78
  Rails3Mailer.perform(:test_mail, Rails3Mailer::MAIL_PARAMS)
64
79
  }.should change(ActionMailer::Base.deliveries, :size).by(1)
65
80
  end
66
81
  end
82
+
83
+ describe "original mail methods" do
84
+ it "should be preserved" do
85
+ Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).subject.should == 'Subject'
86
+ Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).from.should include('from@example.org')
87
+ Rails3Mailer.test_mail(Rails3Mailer::MAIL_PARAMS).to.should include('crafty@example.org')
88
+ end
89
+ end
67
90
  end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,9 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
 
4
- require 'resque_mailer/common'
5
-
6
- begin
7
- require 'rspec/autorun'
8
- rescue LoadError
9
- require 'spec/autorun'
10
- end
4
+ require 'action_mailer'
5
+ require 'resque_mailer'
6
+ require 'rspec/autorun'
11
7
 
12
8
  Resque::Mailer.excluded_environments = []
9
+ ActionMailer::Base.delivery_method = :test
metadata CHANGED
@@ -1,44 +1,137 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_mailer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
- - 1
7
+ - 2
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 0
10
+ version: 2.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Nick Plante
14
- - Marcin Kulik
15
14
  autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-12-21 00:00:00 -05:00
18
+ date: 2011-06-24 00:00:00 -04:00
20
19
  default_executable:
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
- name: rspec
24
- prerelease: false
25
22
  requirement: &id001 !ruby/object:Gem::Requirement
26
23
  none: false
27
24
  requirements:
28
25
  - - ">="
29
26
  - !ruby/object:Gem::Version
30
- hash: 13
27
+ hash: 25
31
28
  segments:
32
29
  - 1
33
30
  - 2
34
- - 9
35
- version: 1.2.9
36
- type: :development
31
+ - 3
32
+ version: 1.2.3
33
+ type: :runtime
34
+ prerelease: false
35
+ name: resque
37
36
  version_requirements: *id001
38
37
  - !ruby/object:Gem::Dependency
39
- name: resque
40
- prerelease: false
41
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
+ type: :runtime
50
+ prerelease: false
51
+ name: actionmailer
52
+ version_requirements: *id002
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
+ type: :development
66
+ prerelease: false
67
+ name: rspec
68
+ version_requirements: *id003
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
+ type: :development
82
+ prerelease: false
83
+ name: yard
84
+ version_requirements: *id004
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
+ type: :development
98
+ prerelease: false
99
+ name: bundler
100
+ version_requirements: *id005
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
+ type: :development
114
+ prerelease: false
115
+ name: jeweler
116
+ version_requirements: *id006
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
+ type: :development
130
+ prerelease: false
131
+ name: rspec
132
+ version_requirements: *id007
133
+ - !ruby/object:Gem::Dependency
134
+ requirement: &id008 !ruby/object:Gem::Requirement
42
135
  none: false
43
136
  requirements:
44
137
  - - ">="
@@ -50,23 +143,25 @@ dependencies:
50
143
  - 3
51
144
  version: 1.2.3
52
145
  type: :development
53
- version_requirements: *id002
54
- - !ruby/object:Gem::Dependency
55
- name: actionmailer
56
146
  prerelease: false
57
- requirement: &id003 !ruby/object:Gem::Requirement
147
+ name: resque
148
+ version_requirements: *id008
149
+ - !ruby/object:Gem::Dependency
150
+ requirement: &id009 !ruby/object:Gem::Requirement
58
151
  none: false
59
152
  requirements:
60
153
  - - ">="
61
154
  - !ruby/object:Gem::Version
62
- hash: 11
155
+ hash: 7
63
156
  segments:
64
- - 2
65
157
  - 3
66
- - 4
67
- version: 2.3.4
158
+ - 0
159
+ - 0
160
+ version: 3.0.0
68
161
  type: :development
69
- version_requirements: *id003
162
+ prerelease: false
163
+ name: actionmailer
164
+ version_requirements: *id009
70
165
  description: Rails plugin for sending asynchronous email with ActionMailer and Resque
71
166
  email: nap@zerosum.org
72
167
  executables: []
@@ -75,21 +170,20 @@ extensions: []
75
170
 
76
171
  extra_rdoc_files:
77
172
  - LICENSE
78
- - README.rdoc
173
+ - README.md
79
174
  files:
80
175
  - .document
176
+ - CHANGELOG.md
177
+ - Gemfile
178
+ - Gemfile.lock
81
179
  - LICENSE
82
- - README.rdoc
180
+ - README.md
83
181
  - Rakefile
84
182
  - VERSION
85
183
  - lib/resque_mailer.rb
86
- - lib/resque_mailer/common.rb
87
- - lib/resque_mailer/rails2.rb
88
- - lib/resque_mailer/rails3.rb
89
184
  - rails/init.rb
90
- - spec/common_spec.rb
91
- - spec/rails2_spec.rb
92
- - spec/rails3_spec.rb
185
+ - resque_mailer.gemspec
186
+ - spec/resque_mailer_spec.rb
93
187
  - spec/spec.opts
94
188
  - spec/spec_helper.rb
95
189
  has_rdoc: true
@@ -126,8 +220,5 @@ rubygems_version: 1.3.7
126
220
  signing_key:
127
221
  specification_version: 3
128
222
  summary: Rails plugin for sending asynchronous email with ActionMailer and Resque
129
- test_files:
130
- - spec/common_spec.rb
131
- - spec/rails2_spec.rb
132
- - spec/rails3_spec.rb
133
- - spec/spec_helper.rb
223
+ test_files: []
224
+
data/README.rdoc DELETED
@@ -1,78 +0,0 @@
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
- Works in both Rails 2.x and Rails 3.x.
8
-
9
- == Usage
10
-
11
- Include Resque::Mailer in your ActionMailer subclass(es) like this:
12
-
13
- class MyMailer < ActionMailer::Base
14
- include Resque::Mailer
15
- end
16
-
17
- Now, when <tt>MyMailer.deliver_subject_email</tt> is called, an entry will be
18
- created in the job queue. Your Resque workers will be able to deliver this
19
- message for you. The queue we're using is imaginatively named +mailer+, so
20
- just make sure your workers know about it and are loading your environment:
21
-
22
- QUEUE=mailer rake environment resque:work
23
-
24
- Note that you can still have mail delivered synchronously by using the bang
25
- method variant:
26
-
27
- MyMailer.deliver_subject_email!
28
-
29
- Oh, by the way. Don't forget that your async mailer jobs will be processed by
30
- a separate worker. This means that you should resist the temptation to pass
31
- database-backed objects as parameters in your mailer and instead pass record
32
- identifiers. Then, in your delivery method, you can look up the record from
33
- the id and use it as needed.
34
-
35
- == Rails 3 Support
36
-
37
- Rails 3 has made some changes to the ActionMailer interface. Instead of
38
- calling <tt>MyMailer.deliver_subject_email(params)</tt>, you'll want to call
39
- <tt>MyMailer.subject_email(params).deliver</tt>.
40
-
41
- You still need to include <tt>Resque::Mailer</tt> in your mailer as described
42
- above. Everything else should work as expected.
43
-
44
- == Installation
45
-
46
- Install it as a plugin or as a gem plugin from Gemcutter:
47
-
48
- gem install resque_mailer
49
- script/plugin install git://github.com/zapnap/resque_mailer.git
50
-
51
- # Rails 2: edit config/environment.rb
52
- config.gem 'resque_mailer'
53
-
54
- # Rails 3: add it to your Gemfile
55
- gem 'resque_mailer'
56
-
57
- == Testing
58
-
59
- You don't want to be sending actual emails in the test environment, so you can
60
- configure the environments that should be excluded like so:
61
-
62
- # config/initializers/resque_mailer.rb
63
- Resque::Mailer.excluded_environments = [:test, :cucumber]
64
-
65
- == Note on Patches / Pull Requests
66
-
67
- * Fork the project.
68
- * Make your feature addition or bug fix.
69
- * Add tests for it. This is important so I don't break it in a future version unintentionally.
70
- * Commit, do not mess with rakefile, version, or history.
71
- (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)
72
- * Send me a pull request. Bonus points for topic branches.
73
-
74
- == Credits
75
-
76
- This work is essentially a forked version of delayed_job_mailer
77
- (http://github.com/andersondias/delayed_job_mailer) by Anderson Dias. Enhanced
78
- and modified to work with Resque by Nick Plante.
@@ -1,34 +0,0 @@
1
- module Resque
2
- module Mailer
3
-
4
- class << self
5
- attr_accessor :default_queue_name
6
- attr_reader :excluded_environments
7
-
8
- def excluded_environments=(envs)
9
- @excluded_environments = [*envs].map { |e| e.to_sym }
10
- end
11
-
12
- def included(base)
13
- base.extend(ClassMethods)
14
- end
15
- end
16
-
17
- self.default_queue_name = "mailer"
18
- self.excluded_environments = [:test]
19
-
20
- module ClassMethods
21
- def environment_excluded?
22
- !ActionMailer::Base.perform_deliveries || excluded_environment?(current_env)
23
- end
24
-
25
- def queue
26
- ::Resque::Mailer.default_queue_name
27
- end
28
-
29
- def excluded_environment?(name)
30
- ::Resque::Mailer.excluded_environments && ::Resque::Mailer.excluded_environments.include?(name.to_sym)
31
- end
32
- end
33
- end
34
- end
@@ -1,25 +0,0 @@
1
- module Resque
2
- module Mailer
3
- module ClassMethods
4
-
5
- def current_env
6
- RAILS_ENV
7
- end
8
-
9
- def method_missing(method_name, *args)
10
- return super if environment_excluded?
11
-
12
- case method_name.id2name
13
- when /^deliver_([_a-z]\w*)\!/ then super(method_name, *args)
14
- when /^deliver_([_a-z]\w*)/ then ::Resque.enqueue(self, "#{method_name}!", *args)
15
- else super(method_name, *args)
16
- end
17
- end
18
-
19
- def perform(cmd, *args)
20
- send(cmd, *args)
21
- end
22
-
23
- end
24
- end
25
- end
@@ -1,42 +0,0 @@
1
- module Resque
2
- module Mailer
3
-
4
- class Rails3MailerProxy
5
- def initialize(mailer_class, action, *args)
6
- @mailer_class = mailer_class
7
- @action = action
8
- @args = args
9
- end
10
-
11
- def deliver
12
- ::Resque.enqueue(@mailer_class, @action, *@args)
13
- end
14
-
15
- def deliver!
16
- @mailer_class.send(:new, @action, *@args).message.deliver
17
- end
18
- end
19
-
20
- module ClassMethods
21
-
22
- def current_env
23
- ::Rails.env
24
- end
25
-
26
- def method_missing(method_name, *args)
27
- return super if environment_excluded?
28
-
29
- if action_methods.include?(method_name.to_s)
30
- Rails3MailerProxy.new(self, method_name, *args)
31
- else
32
- super
33
- end
34
- end
35
-
36
- def perform(action, *args)
37
- Rails3MailerProxy.new(self, action, *args).deliver!
38
- end
39
-
40
- end
41
- end
42
- end
data/spec/common_spec.rb DELETED
@@ -1,26 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
-
3
- class CommonMailer
4
- include Resque::Mailer
5
- end
6
-
7
- describe Resque::Mailer do
8
- describe ".queue" do
9
- context "when not changed" do
10
- it "should return 'mailer'" do
11
- CommonMailer.queue.should == "mailer"
12
- end
13
- end
14
-
15
- context "when changed" do
16
- before do
17
- @my_default_queue = "foobar"
18
- Resque::Mailer.should_receive(:default_queue_name).and_return(@my_default_queue)
19
- end
20
-
21
- it "should return proper queue name" do
22
- CommonMailer.queue.should == @my_default_queue
23
- end
24
- end
25
- end
26
- end
data/spec/rails2_spec.rb DELETED
@@ -1,71 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
2
-
3
- gem 'actionmailer', '~>2.3.4'
4
- require 'action_mailer'
5
- require 'resque_mailer/rails2'
6
-
7
- ActionMailer::Base.delivery_method = :test
8
-
9
- class Rails2Mailer < ActionMailer::Base
10
- include Resque::Mailer
11
- MAIL_PARAMS = { :to => "misio@example.org" }
12
-
13
- def test_mail(opts={})
14
- @subject = 'subject'
15
- @body = 'mail body'
16
- @recipients = opts[:to]
17
- @from = 'from@example.org'
18
- @sent_on = Time.now
19
- @headers = {}
20
- end
21
- end
22
-
23
- describe Rails2Mailer do
24
- before do
25
- Rails2Mailer.stub(:current_env => :test)
26
- end
27
-
28
- describe '#deliver' do
29
- before(:all) do
30
- @delivery = lambda {
31
- Rails2Mailer.deliver_test_mail(Rails2Mailer::MAIL_PARAMS)
32
- }
33
- end
34
-
35
- before(:each) do
36
- Resque.stub(:enqueue)
37
- end
38
-
39
- it 'should not deliver the email synchronously' do
40
- lambda { @delivery.call }.should_not change(ActionMailer::Base.deliveries, :size)
41
- end
42
-
43
- it 'should place the deliver action on the Resque "mailer" queue' do
44
- Resque.should_receive(:enqueue).with(Rails2Mailer, "deliver_test_mail!", Rails2Mailer::MAIL_PARAMS)
45
- @delivery.call
46
- end
47
-
48
- context "when current env is excluded" do
49
- it 'should not deliver through Resque for excluded environments' do
50
- Resque::Mailer.stub(:excluded_environments => [:custom])
51
- Rails2Mailer.should_receive(:current_env).and_return(:custom)
52
- Resque.should_not_receive(:enqueue)
53
- @delivery.call
54
- end
55
- end
56
- end
57
-
58
- describe '#deliver!' do
59
- it 'should deliver the email synchronously' do
60
- lambda { Rails2Mailer.deliver_test_mail!(Rails2Mailer::MAIL_PARAMS) }.should change(ActionMailer::Base.deliveries, :size).by(1)
61
- end
62
- end
63
-
64
- describe ".perform" do
65
- it 'should perform a queued mailer job' do
66
- lambda {
67
- Rails2Mailer.perform("deliver_test_mail!", Rails2Mailer::MAIL_PARAMS)
68
- }.should change(ActionMailer::Base.deliveries, :size).by(1)
69
- end
70
- end
71
- end