Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added config option and spec

  • Loading branch information...
commit 41dc4efc607949d83dc6c0b3bd3f1f7c02d364c3 1 parent fca069b
@amaierhofer authored
View
5 app/models/notification.rb
@@ -68,7 +68,7 @@ def deliver(should_clean = true)
if Mailboxer.uses_emails
email_to = r.send(Mailboxer.email_method,self)
unless email_to.blank?
- NotificationMailer.send_email(self,r).deliver
+ get_mailer.send_email(self,r).deliver
end
end
end
@@ -77,6 +77,9 @@ def deliver(should_clean = true)
return temp_receipts if temp_receipts.size > 1
return temp_receipts.first
end
+ def get_mailer
+ Mailboxer.notification_mailer || NotificationMailer
+ end
#Returns the recipients of the Notification
def recipients
View
3  lib/mailboxer.rb
@@ -15,7 +15,8 @@ module Models
@@email_method = :mailboxer_email
mattr_accessor :name_method
@@name_method = :name
-
+ mattr_accessor :notification_mailer
+
class << self
def setup
yield self
View
13 spec/mailboxer_spec.rb
@@ -4,4 +4,15 @@
it "should be valid" do
Mailboxer.should be_a(Module)
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
View
15 spec/models/notification_spec.rb
@@ -60,5 +60,18 @@
notification.body.should=="Body"
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
Please sign in to comment.
Something went wrong with that request. Please try again.