delayed_mailer 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,44 @@
1
+ = delayed_mailer
2
+
3
+ This gem hooks in Rails ActionMailer::Base and change the behavior of deliver_* methods to allways delegate the sending taks
4
+ to DelayedJob. With this in mind all your emails will be sent asynchronous instead of sycnhronous.
5
+
6
+ == Download
7
+
8
+ Gem:
9
+ gem install delayed_mailer
10
+
11
+ == Installation
12
+
13
+ Load the gem in the appropriate environments using Rails' 2.1+ gem support. For example, I'm loading this in
14
+ config/environments/production.rb and config/environments/staging.rb:
15
+
16
+ config.gem 'delayed_mailer'
17
+
18
+ == How it works
19
+
20
+ When the gem is loaded it change the ActionMailer::Base method_missing to use send_later method of DelayedJob instead of
21
+ normal deliver_*. If you want synchronous send you just call deliver_*!. The deliver with bang (!) will
22
+ send the message using default ActionMailer method.
23
+
24
+ == Version Compatibility
25
+
26
+ specs.should pass if RUBY_VERSION =~ /^1.(8.6|8.7|9.1)$/ && Rails.version =~ /^(1.2.6|2.\d.\d)$/
27
+
28
+ == Author
29
+
30
+ * Anderson Dias - http://github.com/andersondias
31
+
32
+ == Contributors
33
+
34
+ * Daniel Lopes - http://github.com/danielvlopes
35
+ * Overbryd - http://github.com/Overbryd
36
+ * Grimen - http://github.com/grimen
37
+
38
+ == Copyright
39
+
40
+ Copyright (c) 2009 Anderson Dias, released under the MIT license
41
+
42
+ Email: andersondaraujo[at]gmail.com
43
+ Twitter: extendsmymind
44
+ Blog: http://extendsmymind.wordpress.com
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.2
1
+ 1.0.3
@@ -5,22 +5,22 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{delayed_mailer}
8
- s.version = "1.0.2"
8
+ s.version = "1.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Anderson Ara\303\272jo"]
12
- s.date = %q{2010-03-06}
12
+ s.date = %q{2010-04-12}
13
13
  s.description = %q{Change the behavior of ActionMailer::Base in Rails to allways use delayed_job's send_later method.}
14
14
  s.email = %q{andersondaraujo@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
21
  ".gitignore",
22
22
  "LICENSE",
23
- "README",
23
+ "README.rdoc",
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "delayed_mailer.gemspec",
@@ -4,18 +4,26 @@ module Delayed
4
4
  module Mailer
5
5
 
6
6
  def self.included(base)
7
+
7
8
  class << base
8
9
  alias_method :original_method_missing, :method_missing
9
-
10
- def method_missing(method_symbol, *params)
11
- if (/^deliver_([_a-z!]\w*)(?!\!)$/ =~ method_symbol.to_s)
12
- send_later("#{method_symbol}!", *params)
13
- else
14
- original_method_missing(method_symbol, *params)
10
+
11
+ def method_missing(method_symbol, *params, &block)
12
+ method_name = method_symbol.to_s
13
+
14
+ case method_name
15
+ when /^deliver_([_a-z]\w*)$/
16
+ send_later(method_name, *params, &block)
17
+ when /^deliver_([_a-z]\w*)!$/
18
+ original_method_missing(method_name.gsub(/!$/,""), *params, &block)
19
+ else
20
+ original_method_missing(method_name, *params, &block)
15
21
  end
16
22
  end
17
- end
18
- end
23
+
24
+ end #close eigen class
25
+
26
+ end #close hook
19
27
 
20
28
  end
21
29
  end
@@ -20,31 +20,29 @@ describe AsynchTestMailer do
20
20
  Object.const_set 'RAILS_ENV', 'test' unless defined?(::RAILS_ENV)
21
21
  end
22
22
 
23
- describe 'deliver_test_mail' do
24
- before(:each) do
25
- @emails = ActionMailer::Base.deliveries
26
- @emails.clear
27
- @params = 'noreply@autoki.de', 'joe@doe.com'
28
- AsynchTestMailer.stub(:send_later)
29
- end
23
+ before(:each) do
24
+ @emails = ActionMailer::Base.deliveries
25
+ @emails.clear
26
+ @params = 'noreply@myapp.com', 'jonh@doe.com'
27
+ AsynchTestMailer.stub(:send_later)
28
+ end
30
29
 
30
+ describe 'deliver_test_mail' do
31
31
  it 'should not deliver the email at this moment' do
32
32
  AsynchTestMailer.deliver_test_mail *@params
33
33
  @emails.size.should == 0
34
34
  end
35
35
 
36
36
  it 'should send deliver action to delayed job list' do
37
- AsynchTestMailer.should_receive(:send_later).with('deliver_test_mail!', *@params)
37
+ AsynchTestMailer.should_receive(:send_later).with('deliver_test_mail', *@params)
38
38
  AsynchTestMailer.deliver_test_mail *@params
39
39
  end
40
40
  end
41
41
 
42
42
  describe 'deliver_test_mail!' do
43
- it 'should deliver the mail' do
44
- emails = ActionMailer::Base.deliveries
45
- emails.clear
46
- AsynchTestMailer.deliver_test_mail!('noreply@autoki.de', 'joe@doe.com')
47
- emails.size.should == 1
43
+ it 'should deliver the mail now' do
44
+ AsynchTestMailer.deliver_test_mail! *@params
45
+ @emails.size.should == 1
48
46
  end
49
47
  end
50
48
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 2
9
- version: 1.0.2
8
+ - 3
9
+ version: 1.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Anderson Ara\xC3\xBAjo"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-06 00:00:00 -03:00
17
+ date: 2010-04-12 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -39,12 +39,12 @@ extensions: []
39
39
 
40
40
  extra_rdoc_files:
41
41
  - LICENSE
42
- - README
42
+ - README.rdoc
43
43
  files:
44
44
  - .document
45
45
  - .gitignore
46
46
  - LICENSE
47
- - README
47
+ - README.rdoc
48
48
  - Rakefile
49
49
  - VERSION
50
50
  - delayed_mailer.gemspec
data/README DELETED
@@ -1,56 +0,0 @@
1
- DelayedJobMailer
2
- ==============
3
-
4
- This plugin provides a module which - when included into an ActionMailer subclass - pushes all emails that would
5
- normally be delivered synchronously into a queue for asynchronous processing. For queuing it relies on the delayed_job
6
- plugin ( http://github.com/tobi/delayed_job ).
7
-
8
- How it works
9
- ============
10
-
11
- The plugin provides a module Delayed::Mailer. To make a mailer use a queue simply include it into the class like this:
12
-
13
- class MyMailer < ActionMailer::Base
14
- include Delayed::Mailer
15
- end
16
-
17
- From now on all MyMailer.deliver_whatever_email calls create an entry delayed_job queue.
18
- If you still want to deliver mail sycnhronously add a bang to the method call: MyMailer.deliver_whatever_email!
19
-
20
- To set asynchronous mailing as project default, you need to create an initializer file as follows:
21
-
22
- # config/initializers/delayed_mailer.rb
23
- class ActionMailer::Base
24
- include Delayed::Mailer
25
- end
26
-
27
- Installation
28
- ============
29
-
30
- script/plugin install git://github.com/andersondias/delayed_job_mailer.git
31
-
32
- Configuration
33
- =============
34
-
35
- Delayed e-mails is an awesome thing in production environments, but for e-mail specs/tests in testing environments it can be a mess causing specs/tests to fail because the e-mail haven't been sent directly. Therefore you can configure what environments that should be excluded like so:
36
-
37
- # config/initializers/delayed_mailer.rb
38
-
39
- Delayed::Mailer.excluded_environments = [:test, :cucumber] # etc.
40
-
41
- ...
42
-
43
- Credits
44
- =======
45
-
46
- This plugin is a delayed job plugin based on langalex workling_mailer
47
- plugin that can be found at http://github.com/langalex/workling_mailer
48
-
49
- Contact
50
- =======
51
-
52
- Copyright (c) 2009 Anderson Dias, released under the MIT license
53
-
54
- Email: andersondaraujo[at]gmail.com
55
- Twitter: extendsmymind
56
- Blog: http://extendsmymind.wordpress.com