Skip to content

Commit

Permalink
Changed @options to self.settings so deliver! method works.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcg79 committed Sep 21, 2011
1 parent 29b17fe commit 770282b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/letter_opener/delivery_method.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
module LetterOpener
class DeliveryMethod
def initialize(options = {})
@options = {:location => './letter_opener'}.merge!(options)
self.settings = {:location => './letter_opener'}.merge!(options)
end

attr_accessor :settings

def deliver!(mail)
location = File.join(@options[:location], "#{Time.now.to_i}_#{Digest::SHA1.hexdigest(mail.encoded)[0..6]}")
location = File.join(settings[:location], "#{Time.now.to_i}_#{Digest::SHA1.hexdigest(mail.encoded)[0..6]}")
messages = mail.parts.map { |part| Message.new(location, mail, part) }
messages << Message.new(location, mail) if messages.empty?
messages.each { |message| message.render }
Expand Down
19 changes: 19 additions & 0 deletions spec/letter_opener/delivery_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,24 @@
html.should include("View plain text version")
html.should include("<h1>This is HTML</h1>")
end


it "saves text into html document when deliver! is called" do
Launchy.should_receive(:open)
mail = Mail.new do
from 'foo@example.com'
to 'bar@example.com'
subject 'Hello'
body 'World!'
end

mail.deliver!

text = File.read(Dir["#{@location}/*/plain.html"].first)
text.should include("foo@example.com")
text.should include("bar@example.com")
text.should include("Hello")
text.should include("World!")
end
end

0 comments on commit 770282b

Please sign in to comment.