Skip to content

Commit

Permalink
Merge pull request #17 from DEIGirls/Prepare
Browse files Browse the repository at this point in the history
Prepare (#8)
  • Loading branch information
Trung Lê committed Aug 26, 2015
2 parents 598e65b + 476a94e commit 92877ba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/lotus/mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def self.configure(&blk)
def self.included(base)
conf = self.configuration
conf.add_mailer(base)
base.extend(ClassMethods)
base.include(InstanceMethods)

base.class_eval do
extend Dsl.dup
extend Rendering.dup
extend ClassMethods
include InstanceMethods

include Utils::ClassAttribute
class_attribute :configuration
Expand Down Expand Up @@ -160,6 +160,10 @@ def deliver
end
end

if self.respond_to? ('prepare')
self.prepare
end

mail.deliver
end
end
Expand Down
11 changes: 8 additions & 3 deletions test/delivery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@

Mail::TestMailer.deliveries.clear
WelcomeMailer.deliver
SubscriptionMailer.deliver
end

it 'delivers the mail' do
Mail::TestMailer.deliveries.length.must_equal 1
Mail::TestMailer.deliveries.length.must_equal 2
end

it 'sends the correct information' do
Mail::TestMailer.deliveries.first.from.must_equal ["noreply@sender.com"]
Mail::TestMailer.deliveries.first.to.must_equal ["noreply@recipient.com"]
Mail::TestMailer.deliveries.first.from.must_equal ['noreply@sender.com']
Mail::TestMailer.deliveries.first.to.must_equal ['noreply@recipient.com']
Mail::TestMailer.deliveries.first.subject.must_equal "Welcome"
end

Expand All @@ -27,6 +28,10 @@
Mail::TestMailer.deliveries.first.attachments[1].to_s.must_include %(welcome_mailer)
end

it 'interprets the prepare statement' do
Mail::TestMailer.deliveries[1].attachments[0].to_s.must_include %(pdf)
end

after do
Lotus::Mailer.configure do
delivery_method :smtp
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,15 @@ def initialize(name)

attr_reader :name
end

class SubscriptionMailer
include Lotus::Mailer

from "noreply@sender.com"
to "noreply@recipient.com"
subject "Prepare test"

def prepare
mail.attachments['invoice.pdf'] = '/path/to/invoice.pdf'
end
end

0 comments on commit 92877ba

Please sign in to comment.