Permalink
Browse files

warn and use an empty whitelist if passed nil

  • Loading branch information...
1 parent a4373f1 commit d96992e0b6febe41237e4979a32b495d8b95fd2d @smtlaissezfaire committed Feb 6, 2013
Showing with 30 additions and 1 deletion.
  1. +5 −1 lib/catch_all.rb
  2. +25 −0 spec/catch_all_spec.rb
View
@@ -9,7 +9,11 @@ def enabled?
end
def enable(*to_addresses)
- to_addresses = to_addresses.flatten
+ to_addresses = to_addresses.flatten.compact
+
+ if to_addresses.length == 0
+ Kernel.warn("No email addresses passed to ActionMailer::CatchAll!")
+ end
if enabled?
disable
View
@@ -16,6 +16,10 @@ def notify_with_name
def notify_no_address
mail()
end
+
+ def notify_with_empty_to
+ mail(:to => [])
+ end
end
describe ActionMailer::CatchAll do
@@ -93,4 +97,25 @@ def notify_no_address
ActionMailer::CatchAll.disable
ActionMailer::CatchAll.should_not be_enabled
end
+
+ it "should warn and use [] if passed an empty list" do
+ Kernel.should_receive(:warn).with("No email addresses passed to ActionMailer::CatchAll!")
+ ActionMailer::CatchAll.enable([])
+ mailer = Notifier.notify
+ mailer.to.should == []
+ end
+
+ it "should warn and use [] if passed a nil" do
+ Kernel.should_receive(:warn).with("No email addresses passed to ActionMailer::CatchAll!")
+ ActionMailer::CatchAll.enable(nil)
+ mailer = Notifier.notify
+ mailer.to.should == []
+ end
+
+ it "should warn and use [] if passed nothing" do
+ Kernel.should_receive(:warn).with("No email addresses passed to ActionMailer::CatchAll!")
+ ActionMailer::CatchAll.enable()
+ mailer = Notifier.notify
+ mailer.to.should == []
+ end
end

0 comments on commit d96992e

Please sign in to comment.