Skip to content

Instantly share code, notes, and snippets.

@retr0h
Created February 23, 2009 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save retr0h/68809 to your computer and use it in GitHub Desktop.
Save retr0h/68809 to your computer and use it in GitHub Desktop.
ActionMailer Timeouts
### 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