aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/outgoing_mailer_spec.rb
blob: de59b09b2fb875783cc06d377e681204b5e6b7a8 (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
require File.dirname(__FILE__) + '/../spec_helper'

describe OutgoingMailer, " when working out follow up addresses" do
    # This is done with fixtures as the code is a bit tangled with the way it
    # calls TMail.  XXX untangle it and make these tests spread out and using
    # mocks. Put parts of the tests in spec/lib/tmail_extensions.rb
    fixtures :info_requests, :incoming_messages, :raw_emails, :public_bodies

    it "should parse them right" do
        ir = info_requests(:fancy_dog_request) 
        im = ir.incoming_messages[0]

        # check the basic entry in the fixture is fine
        OutgoingMailer.name_and_email_for_followup(ir, im).should == "FOI Person <foiperson@localhost>"
        OutgoingMailer.name_for_followup(ir, im).should == "FOI Person"
        OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
    end

    it "should work when there is only an email address" do
        ir = info_requests(:fancy_dog_request) 
        im = ir.incoming_messages[0]

        im.raw_email.data = im.raw_email.data.sub("\"FOI Person\" <foiperson@localhost>", "foiperson@localhost")

        # check the basic entry in the fixture is fine
        OutgoingMailer.name_and_email_for_followup(ir, im).should == "foiperson@localhost"
        OutgoingMailer.name_for_followup(ir, im).should == "The Geraldine Quango"
        OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
    end

    it "should quote funny characters" do
        ir = info_requests(:fancy_dog_request) 
        im = ir.incoming_messages[0]

        im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI [ Person")

        # check the basic entry in the fixture is fine
        OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI [ Person\" <foiperson@localhost>"
        OutgoingMailer.name_for_followup(ir, im).should == "FOI [ Person"
        OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
    end

    it "should quote quotes" do
        ir = info_requests(:fancy_dog_request) 
        im = ir.incoming_messages[0]

        im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI \\\" Person")

        # check the basic entry in the fixture is fine
        OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI \\\" Person\" <foiperson@localhost>"
        OutgoingMailer.name_for_followup(ir, im).should == "FOI \" Person"
        OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
    end

    it "should quote @ signs" do
        ir = info_requests(:fancy_dog_request) 
        im = ir.incoming_messages[0]

        im.raw_email.data = im.raw_email.data.sub("FOI Person", "FOI @ Person")

        # check the basic entry in the fixture is fine
        OutgoingMailer.name_and_email_for_followup(ir, im).should == "\"FOI @ Person\" <foiperson@localhost>"
        OutgoingMailer.name_for_followup(ir, im).should == "FOI @ Person"
        OutgoingMailer.email_for_followup(ir, im).should == "foiperson@localhost"
    end

end