Skip to content

Commit

Permalink
added config option and spec
Browse files Browse the repository at this point in the history
  • Loading branch information
amaierhofer committed May 12, 2012
1 parent fca069b commit 41dc4ef
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/models/notification.rb
Expand Up @@ -68,7 +68,7 @@ def deliver(should_clean = true)
if Mailboxer.uses_emails if Mailboxer.uses_emails
email_to = r.send(Mailboxer.email_method,self) email_to = r.send(Mailboxer.email_method,self)
unless email_to.blank? unless email_to.blank?
NotificationMailer.send_email(self,r).deliver get_mailer.send_email(self,r).deliver
end end
end end
end end
Expand All @@ -77,6 +77,9 @@ def deliver(should_clean = true)
return temp_receipts if temp_receipts.size > 1 return temp_receipts if temp_receipts.size > 1
return temp_receipts.first return temp_receipts.first
end end
def get_mailer
Mailboxer.notification_mailer || NotificationMailer
end


#Returns the recipients of the Notification #Returns the recipients of the Notification
def recipients def recipients
Expand Down
3 changes: 2 additions & 1 deletion lib/mailboxer.rb
Expand Up @@ -15,7 +15,8 @@ module Models
@@email_method = :mailboxer_email @@email_method = :mailboxer_email
mattr_accessor :name_method mattr_accessor :name_method
@@name_method = :name @@name_method = :name

mattr_accessor :notification_mailer

class << self class << self
def setup def setup
yield self yield self
Expand Down
13 changes: 12 additions & 1 deletion spec/mailboxer_spec.rb
Expand Up @@ -4,4 +4,15 @@
it "should be valid" do it "should be valid" do
Mailboxer.should be_a(Module) Mailboxer.should be_a(Module)
end end
end
describe "configuring notification mailer" do
before { Mailboxer.notification_mailer.should eq nil }

it "can override notification mailer" do
Mailboxer.notification_mailer = "foo"
Mailboxer.notification_mailer.should eq "foo"
end

after { Mailboxer.notification_mailer.should eq nil }
end
end
15 changes: 14 additions & 1 deletion spec/models/notification_spec.rb
Expand Up @@ -60,5 +60,18 @@
notification.body.should=="Body" notification.body.should=="Body"


end end


describe "#get_mailer obtains mailer from config" do
before { Mailboxer.notification_mailer.should be_nil }

it "defaults to NotificationMailer" do
subject.get_mailer.should eq NotificationMailer
end
it "can be overriden on Mailboxer" do
Mailboxer.notification_mailer = 'foo'
subject.get_mailer.should eq 'foo'
end

after { Mailboxer.notification_mailer = nil }
end
end end

0 comments on commit 41dc4ef

Please sign in to comment.