Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.