Skip to content

Commit

Permalink
Add :via option which overrides the default transport mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
arunthampi authored and Adam Wiggins committed Nov 6, 2008
1 parent 9fe8fc1 commit f48635a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/pony.rb
Expand Up @@ -5,7 +5,16 @@
module Pony
def self.mail(options)
raise(ArgumentError, ":to is required") unless options[:to]
transport build_tmail(options)

unless(via = options[:via].to_s).empty?
if via == 'smtp' || via == 'sendmail'
send("transport_via_#{via}", build_tmail(options))
else
raise(ArgumentError, ":via must be either smtp or sendmail")
end
else
transport build_tmail(options)
end
end

def self.build_tmail(options)
Expand Down
17 changes: 17 additions & 0 deletions spec/pony_spec.rb
Expand Up @@ -72,4 +72,21 @@
Pony.transport_via_smtp(mock('tmail', :to => 'to', :from => 'from', :to_s => 'message'))
end
end

describe ":via option should over-ride the default transport mechanism" do
it "should send via sendmail if :via => sendmail" do
Pony.should_receive(:transport_via_sendmail)
Pony.mail(:to => 'joe@example.com', :via => :sendmail)
end

it "should send via smtp if :via => smtp" do
Pony.should_receive(:transport_via_smtp)
Pony.mail(:to => 'joe@example.com', :via => :smtp)
end

it "should raise an error if via is neither smtp nor sendmail" do
lambda { Pony.mail(:to => 'joe@plumber.com', :via => :pigeon) }.should raise_error(ArgumentError)
end
end

end

0 comments on commit f48635a

Please sign in to comment.