Created
February 23, 2009 05:03
-
-
Save retr0h/68809 to your computer and use it in GitHub Desktop.
ActionMailer Timeouts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### lib/ruby_ext.rb | |
Net::SMTP.class_eval do | |
def initialize_with_timeouts(*args) | |
initialize_without_timeouts(*args) | |
@open_timeout = Emailer::OpenTimeout | |
@read_timeout = Emailer::ReadTimeout | |
end | |
alias_method_chain :initialize, :timeouts | |
end | |
### spec/lib/ruby_ext_spec.rb | |
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
describe Net::SMTP do | |
subject { Net::SMTP.new('remote.mxer', 25) } | |
it "should have redefined timeouts" do | |
subject.open_timeout.should == Emailer::OpenTimeout | |
subject.read_timeout.should == Emailer::ReadTimeout | |
end | |
end | |
### app/models/emailer.rb | |
class Emailer < ActionMailer::Base | |
OpenTimeout = 5 | |
ReadTimeout = 10 | |
... | |
end | |
### spec/models/emailer_spec.rb | |
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
describe :constants do | |
it "should have timeout" do | |
Emailer::OpenTimeout.should == 5 | |
Emailer::ReadTimeout.should == 10 | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment