pony 0.8 → 0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -95,6 +95,9 @@ mailing list: ponyrb@googlegroups.com
95
95
 
96
96
  == Releases
97
97
 
98
+ 0.9
99
+ * merge in kalins fixes to use tmail.destinations instead of trying to parse tmail.to, tmail.cc and tmail.bcc. New specs to test functionality
100
+
98
101
  0.8
99
102
  * Fix bug that was allowing nil :bcc and :cc options to be passed to smtp
100
103
 
@@ -99,7 +99,7 @@ module Pony
99
99
  else
100
100
  smtp.start(o[:domain])
101
101
  end
102
- smtp.send_message tmail.to_s, tmail.from, [ tmail.to, tmail.cc, tmail.bcc ].select { |i| i && i != '' }
102
+ smtp.send_message tmail.to_s, tmail.from, tmail.destinations
103
103
  smtp.finish
104
104
  end
105
105
  end
@@ -0,0 +1,109 @@
1
+ require 'rubygems'
2
+ require 'net/smtp'
3
+ require 'mime/types'
4
+ begin
5
+ require 'smtp_tls'
6
+ rescue LoadError
7
+ end
8
+ require 'base64'
9
+ begin
10
+ require 'tmail'
11
+ rescue LoadError
12
+ require 'actionmailer'
13
+ end
14
+
15
+ module Pony
16
+ def self.mail(options)
17
+ raise(ArgumentError, ":to is required") unless options[:to]
18
+
19
+ via = options.delete(:via)
20
+ if via.nil?
21
+ transport build_tmail(options)
22
+ else
23
+ if via_options.include?(via.to_s)
24
+ send("transport_via_#{via}", build_tmail(options), options)
25
+ else
26
+ raise(ArgumentError, ":via must be either smtp or sendmail")
27
+ end
28
+ end
29
+ end
30
+
31
+ def self.build_tmail(options)
32
+ mail = TMail::Mail.new
33
+ mail.to = options[:to]
34
+ mail.cc = options[:cc]
35
+ mail.bcc = options[:bcc]
36
+ mail.from = options[:from] || 'pony@unknown'
37
+ mail.subject = options[:subject]
38
+ if options[:attachments]
39
+ # If message has attachment, then body must be sent as a message part
40
+ # or it will not be interpreted correctly by client.
41
+ body = TMail::Mail.new
42
+ body.body = options[:body] || ""
43
+ body.content_type = options[:content_type] || "text/plain"
44
+ mail.parts.push body
45
+ (options[:attachments] || []).each do |name, body|
46
+ attachment = TMail::Mail.new
47
+ attachment.transfer_encoding = "base64"
48
+ attachment.body = Base64.encode64(body)
49
+ content_type = MIME::Types.type_for(name).to_s
50
+ attachment.content_type = content_type unless content_type == ""
51
+ attachment.set_content_disposition "attachment", "filename" => name
52
+ mail.parts.push attachment
53
+ end
54
+ else
55
+ mail.content_type = options[:content_type] || "text/plain"
56
+ mail.body = options[:body] || ""
57
+ end
58
+ mail.charset = options[:charset] # charset must be set after setting content_type
59
+ mail
60
+ end
61
+
62
+ def self.sendmail_binary
63
+ sendmail = `which sendmail`.chomp
64
+ sendmail.empty? ? '/usr/sbin/sendmail' : sendmail
65
+ end
66
+
67
+ def self.transport(tmail)
68
+ if File.executable? sendmail_binary
69
+ transport_via_sendmail(tmail)
70
+ else
71
+ transport_via_smtp(tmail)
72
+ end
73
+ end
74
+
75
+ def self.via_options
76
+ %w(sendmail smtp)
77
+ end
78
+
79
+ def self.transport_via_sendmail(tmail, options={})
80
+ IO.popen('-', 'w+') do |pipe|
81
+ if pipe
82
+ pipe.write(tmail.to_s)
83
+ else
84
+ exec(sendmail_binary, "-t")
85
+ end
86
+ end
87
+ end
88
+
89
+ def self.transport_via_smtp(tmail, options={:smtp => {}})
90
+ default_options = {:smtp => { :host => 'localhost', :port => '25', :domain => 'localhost.localdomain' }}
91
+ o = default_options[:smtp].merge(options[:smtp])
92
+ smtp = Net::SMTP.new(o[:host], o[:port])
93
+ if o[:tls]
94
+ raise "You may need: gem install smtp_tls" unless smtp.respond_to?(:enable_starttls)
95
+ smtp.enable_starttls
96
+ end
97
+ if o.include?(:auth)
98
+ smtp.start(o[:domain], o[:user], o[:password], o[:auth])
99
+ else
100
+ smtp.start(o[:domain])
101
+ end
102
+ <<<<<<< HEAD:lib/pony.rb
103
+ smtp.send_message tmail.to_s, tmail.from, tmail.destinations
104
+ =======
105
+ smtp.send_message tmail.to_s, tmail.from, [ tmail.to, tmail.cc, tmail.bcc ].select { |i| i && i != '' }
106
+ >>>>>>> 1cf0f8805e7196bc7237590437191efc6badec7e:lib/pony.rb
107
+ smtp.finish
108
+ end
109
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{pony}
5
- s.version = "0.8"
5
+ s.version = "0.9"
6
6
 
7
7
  s.description = "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
8
8
  s.summary = s.description
@@ -27,10 +27,26 @@ describe Pony do
27
27
  it "to" do
28
28
  Pony.build_tmail(:to => 'joe@example.com').to.should == [ 'joe@example.com' ]
29
29
  end
30
+
31
+ it "to with multiple recipients" do
32
+ Pony.build_tmail(:to => 'joe@example.com, friedrich@example.com').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
33
+ end
34
+
35
+ it "to with multiple recipients and names" do
36
+ Pony.build_tmail(:to => 'joe@example.com, "Friedrich Hayek" <friedrich@example.com>').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
37
+ end
38
+
39
+ it "to with multiple recipients and names in an array" do
40
+ Pony.build_tmail(:to => ['joe@example.com', '"Friedrich Hayek" <friedrich@example.com>']).to.should == [ 'joe@example.com', 'friedrich@example.com' ]
41
+ end
30
42
 
31
43
  it "cc" do
32
44
  Pony.build_tmail(:cc => 'joe@example.com').cc.should == [ 'joe@example.com' ]
33
45
  end
46
+
47
+ it "cc with multiple recipients" do
48
+ Pony.build_tmail(:cc => 'joe@example.com, friedrich@example.com').cc.should == [ 'joe@example.com', 'friedrich@example.com' ]
49
+ end
34
50
 
35
51
  it "from" do
36
52
  Pony.build_tmail(:from => 'joe@example.com').from.should == [ 'joe@example.com' ]
@@ -40,6 +56,10 @@ describe Pony do
40
56
  Pony.build_tmail(:bcc => 'joe@example.com').bcc.should == [ 'joe@example.com' ]
41
57
  end
42
58
 
59
+ it "bcc with multiple recipients" do
60
+ Pony.build_tmail(:bcc => 'joe@example.com, friedrich@example.com').bcc.should == [ 'joe@example.com', 'friedrich@example.com' ]
61
+ end
62
+
43
63
  it "charset" do
44
64
  Pony.build_tmail(:charset => 'UTF-8').charset.should == 'UTF-8'
45
65
  end
@@ -109,7 +129,7 @@ Y29udGVudCBvZiBmb28ucGRm
109
129
  pipe = mock('sendmail pipe')
110
130
  IO.should_receive(:popen).with('-',"w+").and_yield(pipe)
111
131
  pipe.should_receive(:write).with('message')
112
- Pony.transport_via_sendmail(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message'))
132
+ Pony.transport_via_sendmail(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message'))
113
133
  end
114
134
 
115
135
  describe "SMTP transport" do
@@ -121,49 +141,58 @@ Y29udGVudCBvZiBmb28ucGRm
121
141
  Net::SMTP.stub!(:new).and_return(@smtp)
122
142
  end
123
143
 
124
- it "passes cc and bcc as the list of recipients" do
125
- @smtp.should_receive(:send_message).with("message", 'from', ['to', 'cc', 'bcc'])
126
- Pony.transport_via_smtp(mock('tmail', :to => 'to', :cc => 'cc', :from => 'from', :to_s => 'message', :bcc => 'bcc'))
144
+ it "passes cc and bcc as the list of recipients" do
145
+ @smtp.should_receive(:send_message).with("message", ['from'], ['to', 'cc', 'bcc'])
146
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => ['bcc'], :destinations => ['to', 'cc', 'bcc']))
147
+ @smtp.should_receive(:send_message).with("message", 'from', ['to', 'cc'])
148
+ Pony.transport_via_smtp(mock('tmail', :to => 'to', :cc => 'cc', :from => 'from', :to_s => 'message', :bcc => nil, :destinations => ['to', 'cc']))
149
+ end
127
150
 
128
- @smtp.should_receive(:send_message).with("message", 'from', ['to', 'cc'])
129
- Pony.transport_via_smtp(mock('tmail', :to => 'to', :cc => 'cc', :from => 'from', :to_s => 'message', :bcc => nil))
130
- end
151
+ it "only pass cc as the list of recipients" do
152
+ @smtp.should_receive(:send_message).with("message", ['from'], ['to', 'cc' ])
153
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => nil, :destinations => ['to', 'cc']))
154
+ end
131
155
 
132
- it "only pass cc as the list of recipients" do
133
- @smtp.should_receive(:send_message).with("message", 'from', ['to', 'cc' ])
134
- Pony.transport_via_smtp(mock('tmail', :to => 'to', :cc => 'cc', :from => 'from', :to_s => 'message', :bcc => ''))
135
- end
156
+ it "only pass bcc as the list of recipients" do
157
+ @smtp.should_receive(:send_message).with("message", ['from'], ['to', 'bcc' ])
158
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => nil, :from => ['from'], :to_s => 'message', :bcc => ['bcc'], :destinations => ['to', 'bcc']))
159
+ end
160
+
161
+ it "passes cc and bcc as the list of recipients when there are a few of them" do
162
+ @smtp.should_receive(:send_message).with("message", ['from'], ['to', 'to2', 'cc', 'bcc', 'bcc2', 'bcc3'])
163
+ Pony.transport_via_smtp(mock('tmail', :to => ['to', 'to2'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => ['bcc', 'bcc2', 'bcc3'], :destinations => ['to', 'to2', 'cc', 'bcc', 'bcc2', 'bcc3']))
164
+ end
136
165
 
137
166
  it "defaults to localhost as the SMTP server" do
138
167
  Net::SMTP.should_receive(:new).with('localhost', '25').and_return(@smtp)
139
- Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message', :cc => '', :bcc => ''))
168
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
140
169
  end
141
170
 
142
171
  it "uses SMTP authorization when auth key is provided" do
143
172
  o = { :smtp => { :user => 'user', :password => 'password', :auth => 'plain'}}
144
173
  @smtp.should_receive(:start).with('localhost.localdomain', 'user', 'password', 'plain')
145
- Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message', :cc => '', :bcc => ''), o)
174
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']), o)
146
175
  end
147
176
 
148
177
  it "enable starttls when tls option is true" do
149
178
  o = { :smtp => { :user => 'user', :password => 'password', :auth => 'plain', :tls => true}}
150
179
  @smtp.should_receive(:enable_starttls)
151
- Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message', :cc => '', :bcc => ''), o)
180
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']), o)
152
181
  end
153
182
 
154
183
  it "starts the job" do
155
184
  @smtp.should_receive(:start)
156
- Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message', :cc => '', :bcc => ''))
185
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
157
186
  end
158
187
 
159
188
  it "sends a tmail message" do
160
189
  @smtp.should_receive(:send_message)
161
- Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message', :cc => '', :bcc => ''))
190
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
162
191
  end
163
192
 
164
193
  it "finishes the job" do
165
194
  @smtp.should_receive(:finish)
166
- Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message', :cc => '', :bcc => ''))
195
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
167
196
  end
168
197
 
169
198
  end
@@ -0,0 +1,230 @@
1
+ require File.dirname(__FILE__) + '/base'
2
+
3
+ describe Pony do
4
+ it "sends mail" do
5
+ Pony.should_receive(:transport) do |tmail|
6
+ tmail.to.should == [ 'joe@example.com' ]
7
+ tmail.from.should == [ 'sender@example.com' ]
8
+ tmail.subject.should == 'hi'
9
+ tmail.body.should == 'Hello, Joe.'
10
+ end
11
+ Pony.mail(:to => 'joe@example.com', :from => 'sender@example.com', :subject => 'hi', :body => 'Hello, Joe.')
12
+ end
13
+
14
+ it "requires :to param" do
15
+ Pony.stub!(:transport)
16
+ lambda { Pony.mail({}) }.should raise_error(ArgumentError)
17
+ end
18
+
19
+ it "doesn't require any other param" do
20
+ Pony.stub!(:transport)
21
+ lambda { Pony.mail(:to => 'joe@example.com') }.should_not raise_error
22
+ end
23
+
24
+ ####################
25
+
26
+ describe "builds a TMail object with field:" do
27
+ it "to" do
28
+ Pony.build_tmail(:to => 'joe@example.com').to.should == [ 'joe@example.com' ]
29
+ end
30
+
31
+ it "to with multiple recipients" do
32
+ Pony.build_tmail(:to => 'joe@example.com, friedrich@example.com').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
33
+ end
34
+
35
+ it "to with multiple recipients and names" do
36
+ Pony.build_tmail(:to => 'joe@example.com, "Friedrich Hayek" <friedrich@example.com>').to.should == [ 'joe@example.com', 'friedrich@example.com' ]
37
+ end
38
+
39
+ it "to with multiple recipients and names in an array" do
40
+ Pony.build_tmail(:to => ['joe@example.com', '"Friedrich Hayek" <friedrich@example.com>']).to.should == [ 'joe@example.com', 'friedrich@example.com' ]
41
+ end
42
+
43
+ it "cc" do
44
+ Pony.build_tmail(:cc => 'joe@example.com').cc.should == [ 'joe@example.com' ]
45
+ end
46
+
47
+ it "cc with multiple recipients" do
48
+ Pony.build_tmail(:cc => 'joe@example.com, friedrich@example.com').cc.should == [ 'joe@example.com', 'friedrich@example.com' ]
49
+ end
50
+
51
+ it "from" do
52
+ Pony.build_tmail(:from => 'joe@example.com').from.should == [ 'joe@example.com' ]
53
+ end
54
+
55
+ it "bcc" do
56
+ Pony.build_tmail(:bcc => 'joe@example.com').bcc.should == [ 'joe@example.com' ]
57
+ end
58
+
59
+ it "bcc with multiple recipients" do
60
+ Pony.build_tmail(:bcc => 'joe@example.com, friedrich@example.com').bcc.should == [ 'joe@example.com', 'friedrich@example.com' ]
61
+ end
62
+
63
+ it "charset" do
64
+ Pony.build_tmail(:charset => 'UTF-8').charset.should == 'UTF-8'
65
+ end
66
+
67
+ it "default charset" do
68
+ Pony.build_tmail(:body => 'body').charset.should == nil
69
+ Pony.build_tmail(:body => 'body', :content_type => 'text/html').charset.should == nil
70
+ end
71
+
72
+ it "from (default)" do
73
+ Pony.build_tmail({}).from.should == [ 'pony@unknown' ]
74
+ end
75
+
76
+ it "subject" do
77
+ Pony.build_tmail(:subject => 'hello').subject.should == 'hello'
78
+ end
79
+
80
+ it "body" do
81
+ Pony.build_tmail(:body => 'What do you know, Joe?').body.should == 'What do you know, Joe?'
82
+ end
83
+
84
+ it "content_type" do
85
+ Pony.build_tmail(:content_type => 'text/html').content_type.should == 'text/html'
86
+ end
87
+
88
+ it "attachments" do
89
+ tmail = Pony.build_tmail(:attachments => {"foo.txt" => "content of foo.txt"})
90
+ tmail.should have(2).parts
91
+ tmail.parts.first.to_s.should == "Content-Type: text/plain\n\n"
92
+ tmail.parts.last.to_s.should == <<-PART
93
+ Content-Type: text/plain
94
+ Content-Transfer-Encoding: Base64
95
+ Content-Disposition: attachment; filename=foo.txt
96
+
97
+ Y29udGVudCBvZiBmb28udHh0
98
+ PART
99
+ end
100
+
101
+ it "suggests mime-type" do
102
+ tmail = Pony.build_tmail(:attachments => {"foo.pdf" => "content of foo.pdf"})
103
+ tmail.should have(2).parts
104
+ tmail.parts.first.to_s.should == "Content-Type: text/plain\n\n"
105
+ tmail.parts.last.to_s.should == <<-PART
106
+ Content-Type: application/pdf
107
+ Content-Transfer-Encoding: Base64
108
+ Content-Disposition: attachment; filename=foo.pdf
109
+
110
+ Y29udGVudCBvZiBmb28ucGRm
111
+ PART
112
+ end
113
+ end
114
+
115
+ describe "transport" do
116
+ it "transports via the sendmail binary if it exists" do
117
+ File.stub!(:executable?).and_return(true)
118
+ Pony.should_receive(:transport_via_sendmail).with(:tmail)
119
+ Pony.transport(:tmail)
120
+ end
121
+
122
+ it "transports via smtp if no sendmail binary" do
123
+ Pony.stub!(:sendmail_binary).and_return('/does/not/exist')
124
+ Pony.should_receive(:transport_via_smtp).with(:tmail)
125
+ Pony.transport(:tmail)
126
+ end
127
+
128
+ it "transports mail via /usr/sbin/sendmail binary" do
129
+ pipe = mock('sendmail pipe')
130
+ IO.should_receive(:popen).with('-',"w+").and_yield(pipe)
131
+ pipe.should_receive(:write).with('message')
132
+ Pony.transport_via_sendmail(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message'))
133
+ end
134
+
135
+ describe "SMTP transport" do
136
+ before do
137
+ @smtp = mock('net::smtp object')
138
+ @smtp.stub!(:start)
139
+ @smtp.stub!(:send_message)
140
+ @smtp.stub!(:finish)
141
+ Net::SMTP.stub!(:new).and_return(@smtp)
142
+ end
143
+
144
+ it "passes cc and bcc as the list of recipients" do
145
+ <<<<<<< HEAD:spec/pony_spec.rb
146
+ @smtp.should_receive(:send_message).with("message", ['from'], ['to', 'cc', 'bcc'])
147
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => ['bcc'], :destinations => ['to', 'cc', 'bcc']))
148
+ =======
149
+ @smtp.should_receive(:send_message).with("message", 'from', ['to', 'cc', 'bcc'])
150
+ Pony.transport_via_smtp(mock('tmail', :to => 'to', :cc => 'cc', :from => 'from', :to_s => 'message', :bcc => 'bcc'))
151
+
152
+ @smtp.should_receive(:send_message).with("message", 'from', ['to', 'cc'])
153
+ Pony.transport_via_smtp(mock('tmail', :to => 'to', :cc => 'cc', :from => 'from', :to_s => 'message', :bcc => nil))
154
+ >>>>>>> 1cf0f8805e7196bc7237590437191efc6badec7e:spec/pony_spec.rb
155
+ end
156
+
157
+ it "only pass cc as the list of recipients" do
158
+ @smtp.should_receive(:send_message).with("message", ['from'], ['to', 'cc' ])
159
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => nil, :destinations => ['to', 'cc']))
160
+ end
161
+
162
+ it "only pass bcc as the list of recipients" do
163
+ @smtp.should_receive(:send_message).with("message", ['from'], ['to', 'bcc' ])
164
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :cc => nil, :from => ['from'], :to_s => 'message', :bcc => ['bcc'], :destinations => ['to', 'bcc']))
165
+ end
166
+
167
+ it "passes cc and bcc as the list of recipients when there are a few of them" do
168
+ @smtp.should_receive(:send_message).with("message", ['from'], ['to', 'to2', 'cc', 'bcc', 'bcc2', 'bcc3'])
169
+ Pony.transport_via_smtp(mock('tmail', :to => ['to', 'to2'], :cc => ['cc'], :from => ['from'], :to_s => 'message', :bcc => ['bcc', 'bcc2', 'bcc3'], :destinations => ['to', 'to2', 'cc', 'bcc', 'bcc2', 'bcc3']))
170
+ end
171
+
172
+ it "defaults to localhost as the SMTP server" do
173
+ Net::SMTP.should_receive(:new).with('localhost', '25').and_return(@smtp)
174
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
175
+ end
176
+
177
+ it "uses SMTP authorization when auth key is provided" do
178
+ o = { :smtp => { :user => 'user', :password => 'password', :auth => 'plain'}}
179
+ @smtp.should_receive(:start).with('localhost.localdomain', 'user', 'password', 'plain')
180
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']), o)
181
+ end
182
+
183
+ it "enable starttls when tls option is true" do
184
+ o = { :smtp => { :user => 'user', :password => 'password', :auth => 'plain', :tls => true}}
185
+ @smtp.should_receive(:enable_starttls)
186
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']), o)
187
+ end
188
+
189
+ it "starts the job" do
190
+ @smtp.should_receive(:start)
191
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
192
+ end
193
+
194
+ it "sends a tmail message" do
195
+ @smtp.should_receive(:send_message)
196
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
197
+ end
198
+
199
+ it "finishes the job" do
200
+ @smtp.should_receive(:finish)
201
+ Pony.transport_via_smtp(mock('tmail', :to => ['to'], :from => ['from'], :to_s => 'message', :cc => nil, :bcc => nil, :destinations => ['to']))
202
+ end
203
+
204
+ end
205
+ end
206
+
207
+ describe ":via option should over-ride the default transport mechanism" do
208
+ it "should send via sendmail if :via => sendmail" do
209
+ Pony.should_receive(:transport_via_sendmail)
210
+ Pony.mail(:to => 'joe@example.com', :via => :sendmail)
211
+ end
212
+
213
+ it "should send via smtp if :via => smtp" do
214
+ Pony.should_receive(:transport_via_smtp)
215
+ Pony.mail(:to => 'joe@example.com', :via => :smtp)
216
+ end
217
+
218
+ it "should raise an error if via is neither smtp nor sendmail" do
219
+ lambda { Pony.mail(:to => 'joe@plumber.com', :via => :pigeon) }.should raise_error(ArgumentError)
220
+ end
221
+ end
222
+
223
+ describe "sendmail binary location" do
224
+ it "should default to /usr/sbin/sendmail if not in path" do
225
+ Pony.stub!(:'`').and_return('')
226
+ Pony.sendmail_binary.should == '/usr/sbin/sendmail'
227
+ end
228
+ end
229
+
230
+ end
metadata CHANGED
@@ -1,11 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pony
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 8
8
- version: "0.8"
4
+ version: "0.9"
9
5
  platform: ruby
10
6
  authors:
11
7
  - Adam Wiggins
@@ -14,35 +10,29 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-03-12 00:00:00 -07:00
13
+ date: 2010-03-13 00:00:00 -08:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
17
  name: tmail
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
24
21
  requirements:
25
22
  - - ~>
26
23
  - !ruby/object:Gem::Version
27
- segments:
28
- - 1
29
- - 0
30
24
  version: "1.0"
31
- type: :runtime
32
- version_requirements: *id001
25
+ version:
33
26
  - !ruby/object:Gem::Dependency
34
27
  name: mime-types
35
- prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
37
31
  requirements:
38
32
  - - ">="
39
33
  - !ruby/object:Gem::Version
40
- segments:
41
- - 1
42
- - 16
43
34
  version: "1.16"
44
- type: :runtime
45
- version_requirements: *id002
35
+ version:
46
36
  description: "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"
47
37
  email: ben.prew@gmail.com
48
38
  executables: []
@@ -56,8 +46,10 @@ files:
56
46
  - Rakefile
57
47
  - pony.gemspec
58
48
  - lib/pony.rb
59
- - spec/pony_spec.rb
49
+ - lib/pony.rb.orig
60
50
  - spec/base.rb
51
+ - spec/pony_spec.rb.orig
52
+ - spec/pony_spec.rb
61
53
  has_rdoc: true
62
54
  homepage: http://github.com/benprew/pony
63
55
  licenses: []
@@ -72,20 +64,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
64
  requirements:
73
65
  - - ">="
74
66
  - !ruby/object:Gem::Version
75
- segments:
76
- - 0
77
67
  version: "0"
68
+ version:
78
69
  required_rubygems_version: !ruby/object:Gem::Requirement
79
70
  requirements:
80
71
  - - ">="
81
72
  - !ruby/object:Gem::Version
82
- segments:
83
- - 0
84
73
  version: "0"
74
+ version:
85
75
  requirements: []
86
76
 
87
77
  rubyforge_project: pony
88
- rubygems_version: 1.3.6
78
+ rubygems_version: 1.3.5
89
79
  signing_key:
90
80
  specification_version: 3
91
81
  summary: "Send email in one command: Pony.mail(:to => 'someone@example.com', :body => 'hello')"