aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/jabber/hashtable.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2006-06-21 18:34:33 +0200
committerWilmer van der Gaast <wilmer@gaast.net>2006-06-21 18:34:33 +0200
commitb72caac09b5944ee9954eb18262fe45228665570 (patch)
treeb44353f8ab3d23702f49e129d53b787952fe6546 /protocols/jabber/hashtable.c
parent3af70b06b2f0fb0fb41a041f6d86e3711b9eea3f (diff)
parentdf417ca6657bc824e1dbd4a6026284656a42ce40 (diff)
Merging libevent branch: Events can now be handles by both glib and libevent.
Diffstat (limited to 'protocols/jabber/hashtable.c')
0 files changed, 0 insertions, 0 deletions
ion value='hotfix/0.20.0.4'>hotfix/0.20.0.4 Unnamed repository; edit this file 'description' to name the repository.MimesBrønn
aboutsummaryrefslogtreecommitdiffstats
path: root/spec/lib/sendmail_return_path_spec.rb
blob: f1a91240be33334542f2ae20d34bdd0e1e46ba13 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# This is a test of the monkey patches in sendmail_return_path.rb

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe "when sending email with an altered return path" do

    it "should default to delivery method test" do
        ActionMailer::Base.delivery_method.should == :test
    end

    it "should let the helper change the method" do
        with_delivery_method :smtp do
            ActionMailer::Base.delivery_method.should == :smtp
        end
        ActionMailer::Base.delivery_method.should == :test
    end

    # Documentation for fancy mock functions: http://rspec.info/documentation/mocks/message_expectations.html
    it "should set the return path when sending email using SMTP" do
        mock_smtp = mock("smtp")
        mock_smtp_session = mock("smtp_session")

        mock_smtp.should_receive(:start).once.and_yield(mock_smtp_session)
        # the second parameter to the SMTP session is the sender (return path)
        mock_smtp_session.should_receive(:sendmail).once.with(anything(), "test@localhost", anything())

        Net::SMTP.stub!(:new).and_return(mock_smtp)

        with_delivery_method :smtp do
            ContactMailer.deliver_message(
                "Mr. Test", "test@localhost", "Test script spec/lib/sendmail_return_path_spec.rb",
                "This is just a test for a test script", nil, nil, nil
            )
        end

        deliveries = ActionMailer::Base.deliveries
        deliveries.size.should == 0
    end

    it "should set the return path when sending email using sendmail" do
        with_stub_popen do
            IO.should_receive(:popen).once.with('/usr/sbin/sendmail -i -t -f "test@localhost"', "w+")
            with_delivery_method :sendmail do
                ContactMailer.deliver_message(
                    "Mr. Test", "test@localhost", "Test script spec/lib/sendmail_return_path_spec.rb",
                    "This is just a test for a test script", nil, nil, nil
                )
            end
        end

        deliveries = ActionMailer::Base.deliveries
        deliveries.size.should == 0
    end


 protected
    # Change the way Rails delivers memory, just for current scope
    def with_delivery_method(new_delivery_method)
        old_delivery_method, ActionMailer::Base.delivery_method = ActionMailer::Base.delivery_method, new_delivery_method
        yield
    ensure
        ActionMailer::Base.delivery_method = old_delivery_method
    end

    # By default, we can't stub popen, presumably because it is a builtin written in C.
    # Replace it entirely with a normal method that just calls the C one, so we can stub it -
    # this leaves IO working afterwards (for other tests that run in the same instance).
    def with_stub_popen()
        IO.class_eval "@orig_popen = self.method(:popen); def self.popen(a, b, &c); @orig_popen.call(a, b, &c); end"
        begin
            yield
        ensure
            # in theory would undo the popen alterations and return IO to a pristine state, but
            # don't know how to (much fiddling with alias bind and the like didn't help). It
            # doesn't matter - the new popen should behave just the same.
        end
    end


end