Permalink
Browse files

automatically include the new deliver when require the gem

  • Loading branch information...
1 parent c87838a commit 91c030d80db80a5078773291a69179586fa7ec48 @danielvlopes danielvlopes committed Mar 5, 2010
@@ -1,19 +0,0 @@
-# coding: utf-8
-
-module Delayed
- module Mailer
- def self.included(base)
- base.extend self
- end
-
- def method_missing(method_symbol, *params)
- case method_symbol.id2name
- when /^deliver_([_a-z]\w*)\!/ then super(method_symbol, *params)
- when /^deliver_([_a-z]\w*)/ then self.send_later(method_symbol.to_s + '!', *params)
- else
- super(method_symbol, *params)
- end
- end
-
- end
-end
@@ -5,7 +5,5 @@
require 'delayed_mailer/deliver'
if ActionMailer::VERSION::MAJOR < 3
- require 'delayed_mailer/rails2_hook'
-else
- require 'delayed_mailer/rails3_hook'
+ ActionMailer::Base.send(:include, DelayedMailer::Deliver)
end
@@ -1,17 +1,22 @@
# coding: utf-8
-
module DelayedMailer
module Deliver
def self.included(base)
- base.extend self
- end
+ base.class_eval do
+ class << self
+
+ alias_method :orig_method_missing, :method_missing
- def method_missing(method_symbol, *params)
- case method_symbol.id2name
- when /^deliver_([_a-z]\w*)\!/ then super(method_symbol, *params)
- when /^deliver_([_a-z]\w*)/ then self.send_later(method_symbol.to_s + '!', *params)
- else
- super(method_symbol, *params)
+ def method_missing(method_symbol, *params)
+ case method_symbol.id2name
+ when /^deliver_([_a-z]\w*)\!/ then orig_method_missing(method_symbol, *params)
+ when /^deliver_([_a-z]\w*)/ then self.send_later("#{method_symbol}!", *params)
+ else
+ orig_method_missing(method_symbol, *params)
+ end
+ end
+
+ end
end
end
@@ -1,3 +0,0 @@
-unless ActionMailer::Base.ancestors.include?(DelayedMailer::Deliver)
- ActionMailer::Base.send(:include, DelayedMailer::Deliver)
-end
@@ -1,8 +0,0 @@
-# require 'mail'
-#
-# module DelayedMailer
-# class MailInterceptor
-# include DelayedMailer
-# ::Mail.register_interceptor(self)
-# end
-# end
@@ -1,15 +1,10 @@
# coding: utf-8
require File.dirname(__FILE__) + '/spec_helper'
-require 'rubygems'
-gem 'actionmailer', '>= 1.0.0'
-require 'action_mailer'
-
ActionMailer::Base.delivery_method = :test
-class AsynchTestMailer < ActionMailer::Base
- include Delayed::Mailer
-
+class AsynchTestMailer < ActionMailer::Base
+
def test_mail(from, to)
@subject = 'subject'
@body = 'mail body'
@@ -25,39 +20,26 @@ def test_mail(from, to)
# We need a default environment...
Object.const_set 'RAILS_ENV', 'test' unless defined?(::RAILS_ENV)
end
-
+
describe 'deliver_test_mail' do
before(:each) do
@emails = ActionMailer::Base.deliveries
@emails.clear
@params = 'noreply@autoki.de', 'joe@doe.com'
AsynchTestMailer.stub(:send_later)
end
-
+
it 'should not deliver the email at this moment' do
AsynchTestMailer.deliver_test_mail *@params
@emails.size.should == 0
end
-
+
it 'should send deliver action to delayed job list' do
AsynchTestMailer.should_receive(:send_later).with('deliver_test_mail!', *@params)
AsynchTestMailer.deliver_test_mail *@params
end
-
- it 'should not send deliver action to delayed job list for environments where delayed job mailer is disabled' do
- excluded_environments = [:cucumber, :foo, 'bar']
- ::Delayed::Mailer.excluded_environments = excluded_environments
-
- excluded_environments.each do |env|
- Object.send :remove_const, 'RAILS_ENV'
- Object.const_set 'RAILS_ENV', env.to_s
-
- AsynchTestMailer.should_not_receive(:send_later).with('deliver_test_mail!', *@params)
- AsynchTestMailer.deliver_test_mail *@params
- end
- end
end
-
+
describe 'deliver_test_mail!' do
it 'should deliver the mail' do
emails = ActionMailer::Base.deliveries
@@ -1,66 +0,0 @@
-# coding: utf-8
-require File.dirname(__FILE__) + '/spec_helper'
-
-require 'rubygems'
-gem 'actionmailer', '>= 1.0.0'
-require 'action_mailer'
-
-ActionMailer::Base.delivery_method = :test
-
-class AsynchTestMailer < ActionMailer::Base
- def test_mail(from, to)
- @subject = 'subject'
- @body = 'mail body'
- @recipients = to
- @from = from
- @sent_on = Time.now
- @headers = {}
- end
-end
-
-describe AsynchTestMailer do
- before do
- Object.const_set 'RAILS_ENV', 'test' unless defined?(::RAILS_ENV)
- end
-
- describe 'deliver_test_mail' do
- before(:each) do
- @emails = ActionMailer::Base.deliveries
- @emails.clear
- @params = 'noreply@autoki.de', 'joe@doe.com'
- AsynchTestMailer.stub(:send_later)
- end
-
- it 'should not deliver the email at this moment' do
- AsynchTestMailer.deliver_test_mail *@params
- @emails.size.should == 0
- end
-
- it 'should send deliver action to delayed job list' do
- AsynchTestMailer.should_receive(:send_later).with('deliver_test_mail!', *@params)
- AsynchTestMailer.deliver_test_mail *@params
- end
-
- # it 'should not send deliver action to delayed job list for environments where delayed job mailer is disabled' do
- # excluded_environments = [:cucumber, :foo, 'bar']
- # ::Delayed::Mailer.excluded_environments = excluded_environments
- #
- # excluded_environments.each do |env|
- # Object.send :remove_const, 'RAILS_ENV'
- # Object.const_set 'RAILS_ENV', env.to_s
- #
- # AsynchTestMailer.should_not_receive(:send_later).with('deliver_test_mail!', *@params)
- # AsynchTestMailer.deliver_test_mail *@params
- # end
- # end
- end
-
- describe 'deliver_test_mail!' do
- it 'should deliver the mail' do
- emails = ActionMailer::Base.deliveries
- emails.clear
- AsynchTestMailer.deliver_test_mail! 'noreply@autoki.de', 'joe@doe.com'
- emails.size.should == 1
- end
- end
-end

0 comments on commit 91c030d

Please sign in to comment.