retr0h (owner)

Revisions

gist: 68809 Download_button fork
public
Description:
ActionMailer Timeouts
Public Clone URL: git://gist.github.com/68809.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
### 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