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.
@@ -1,5 +1,5 @@
1
1
  module ActionMailer
2
2
  module CatchAll
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
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
- ActionMailer::Base.class_eval do
15
- if instance_methods.include?(:mail_aliased_from_action_mailer_staging)
16
- ActionMailerStaging.disable
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|
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catch_all
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: