catch_all 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/catch_all/version.rb +1 -1
- data/lib/catch_all.rb +9 -5
- data/spec/catch_all_spec.rb +25 -0
- metadata +1 -1
data/lib/catch_all/version.rb
CHANGED
data/lib/catch_all.rb
CHANGED
@@ -9,13 +9,17 @@ module ActionMailer
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def enable(*to_addresses)
|
12
|
-
to_addresses = to_addresses.flatten
|
12
|
+
to_addresses = to_addresses.flatten.compact
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
14
|
+
if to_addresses.length == 0
|
15
|
+
Kernel.warn("No email addresses passed to ActionMailer::CatchAll!")
|
16
|
+
end
|
18
17
|
|
18
|
+
if enabled?
|
19
|
+
disable
|
20
|
+
end
|
21
|
+
|
22
|
+
ActionMailer::Base.class_eval do
|
19
23
|
alias_method :mail_aliased_from_action_mailer_staging, :mail
|
20
24
|
|
21
25
|
define_method :mail do |*args, &block|
|
data/spec/catch_all_spec.rb
CHANGED
@@ -16,6 +16,10 @@ class Notifier < ActionMailer::Base
|
|
16
16
|
def notify_no_address
|
17
17
|
mail()
|
18
18
|
end
|
19
|
+
|
20
|
+
def notify_with_empty_to
|
21
|
+
mail(:to => [])
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
25
|
describe ActionMailer::CatchAll do
|
@@ -93,4 +97,25 @@ describe ActionMailer::CatchAll do
|
|
93
97
|
ActionMailer::CatchAll.disable
|
94
98
|
ActionMailer::CatchAll.should_not be_enabled
|
95
99
|
end
|
100
|
+
|
101
|
+
it "should warn and use [] if passed an empty list" do
|
102
|
+
Kernel.should_receive(:warn).with("No email addresses passed to ActionMailer::CatchAll!")
|
103
|
+
ActionMailer::CatchAll.enable([])
|
104
|
+
mailer = Notifier.notify
|
105
|
+
mailer.to.should == []
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should warn and use [] if passed a nil" do
|
109
|
+
Kernel.should_receive(:warn).with("No email addresses passed to ActionMailer::CatchAll!")
|
110
|
+
ActionMailer::CatchAll.enable(nil)
|
111
|
+
mailer = Notifier.notify
|
112
|
+
mailer.to.should == []
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should warn and use [] if passed nothing" do
|
116
|
+
Kernel.should_receive(:warn).with("No email addresses passed to ActionMailer::CatchAll!")
|
117
|
+
ActionMailer::CatchAll.enable()
|
118
|
+
mailer = Notifier.notify
|
119
|
+
mailer.to.should == []
|
120
|
+
end
|
96
121
|
end
|