Skip to content

Commit

Permalink
raise exception if location option is not present when setting up del…
Browse files Browse the repository at this point in the history
…ivery
  • Loading branch information
ryanb committed Oct 1, 2012
1 parent 11d5293 commit fccbf2f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.rdoc
Expand Up @@ -22,7 +22,7 @@ If you aren't using Rails, this can be easily set up with the Mail gem. Just set


require "letter_opener" require "letter_opener"
Mail.defaults do Mail.defaults do
delivery_method LetterOpener::DeliveryMethod, :location => "tmp/letter_opener" delivery_method LetterOpener::DeliveryMethod, :location => File.expand_path('../tmp/letter_opener', __FILE__)
end end




Expand Down
9 changes: 6 additions & 3 deletions lib/letter_opener/delivery_method.rb
@@ -1,11 +1,14 @@
module LetterOpener module LetterOpener
class DeliveryMethod class DeliveryMethod
def initialize(options = {}) class InvalidOption < StandardError; end
self.settings = {:location => './letter_opener'}.merge!(options)
end


attr_accessor :settings attr_accessor :settings


def initialize(options = {})
raise InvalidOption, "A location option is required when using the Letter Opener delivery method" if options[:location].nil?
self.settings = options
end

def deliver!(mail) def deliver!(mail)
location = File.join(settings[: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 = Message.rendered_messages(location, mail) messages = Message.rendered_messages(location, mail)
Expand Down
5 changes: 5 additions & 0 deletions spec/letter_opener/delivery_method_spec.rb
Expand Up @@ -13,6 +13,11 @@
end end
end end


it 'raises an exception if no location passed' do
lambda { LetterOpener::DeliveryMethod.new }.should raise_exception(LetterOpener::DeliveryMethod::InvalidOption)
lambda { LetterOpener::DeliveryMethod.new(location: "foo") }.should_not raise_exception
end

context 'content' do context 'content' do
let(:plain_file) { Dir["#{location}/*/plain.html"].first } let(:plain_file) { Dir["#{location}/*/plain.html"].first }
let(:plain) { File.read(plain_file) } let(:plain) { File.read(plain_file) }
Expand Down

0 comments on commit fccbf2f

Please sign in to comment.