catch_all 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +72 -0
- data/README.md +17 -0
- data/catch_all.gemspec +19 -0
- data/lib/catch_all/version.rb +5 -0
- data/lib/catch_all.rb +52 -0
- data/spec/catch_all_spec.rb +96 -0
- metadata +56 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
catch_all (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ZenTest (4.4.2)
|
10
|
+
actionmailer (3.2.11)
|
11
|
+
actionpack (= 3.2.11)
|
12
|
+
mail (~> 2.4.4)
|
13
|
+
actionpack (3.2.11)
|
14
|
+
activemodel (= 3.2.11)
|
15
|
+
activesupport (= 3.2.11)
|
16
|
+
builder (~> 3.0.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
journey (~> 1.0.4)
|
19
|
+
rack (~> 1.4.0)
|
20
|
+
rack-cache (~> 1.2)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
sprockets (~> 2.2.1)
|
23
|
+
activemodel (3.2.11)
|
24
|
+
activesupport (= 3.2.11)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
activesupport (3.2.11)
|
27
|
+
i18n (~> 0.6)
|
28
|
+
multi_json (~> 1.0)
|
29
|
+
builder (3.0.4)
|
30
|
+
diff-lcs (1.1.3)
|
31
|
+
erubis (2.7.0)
|
32
|
+
hike (1.2.1)
|
33
|
+
i18n (0.6.1)
|
34
|
+
journey (1.0.4)
|
35
|
+
mail (2.4.4)
|
36
|
+
i18n (>= 0.4.0)
|
37
|
+
mime-types (~> 1.16)
|
38
|
+
treetop (~> 1.4.8)
|
39
|
+
mime-types (1.19)
|
40
|
+
multi_json (1.5.0)
|
41
|
+
polyglot (0.3.3)
|
42
|
+
rack (1.4.3)
|
43
|
+
rack-cache (1.2)
|
44
|
+
rack (>= 0.4)
|
45
|
+
rack-test (0.6.2)
|
46
|
+
rack (>= 1.0)
|
47
|
+
rspec (2.12.0)
|
48
|
+
rspec-core (~> 2.12.0)
|
49
|
+
rspec-expectations (~> 2.12.0)
|
50
|
+
rspec-mocks (~> 2.12.0)
|
51
|
+
rspec-core (2.12.0)
|
52
|
+
rspec-expectations (2.12.0)
|
53
|
+
diff-lcs (~> 1.1.3)
|
54
|
+
rspec-mocks (2.12.0)
|
55
|
+
sprockets (2.2.2)
|
56
|
+
hike (~> 1.2)
|
57
|
+
multi_json (~> 1.0)
|
58
|
+
rack (~> 1.0)
|
59
|
+
tilt (~> 1.1, != 1.3.0)
|
60
|
+
tilt (1.3.3)
|
61
|
+
treetop (1.4.12)
|
62
|
+
polyglot
|
63
|
+
polyglot (>= 0.3.1)
|
64
|
+
|
65
|
+
PLATFORMS
|
66
|
+
ruby
|
67
|
+
|
68
|
+
DEPENDENCIES
|
69
|
+
ZenTest (~> 4.4.2)
|
70
|
+
actionmailer
|
71
|
+
catch_all!
|
72
|
+
rspec (>= 2.3.0)
|
data/README.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# ActionMailer::CatchAll
|
2
|
+
|
3
|
+
ActionMailer::CatchAll is a simple module to define a white-list of email addresses, used for staging environments.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Gemfile:
|
8
|
+
|
9
|
+
gem 'catch_all'
|
10
|
+
|
11
|
+
config/initializers/email_catch_all.rb:
|
12
|
+
|
13
|
+
if Rails.env.staging?
|
14
|
+
ActionMailer::CatchAll.enable('scott@railsnewbie.com')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
data/catch_all.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'catch_all/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "catch_all"
|
8
|
+
gem.version = ActionMailer::CatchAll::VERSION
|
9
|
+
gem.authors = ["Scott Taylor"]
|
10
|
+
gem.email = ["scott@railsnewbie.com"]
|
11
|
+
gem.description = %q{Define a white-list only set of emails for ActionMailer}
|
12
|
+
gem.summary = %q{Define a white-list only set of emails for ActionMailer. Used in staging environments.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
data/lib/catch_all.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'action_mailer'
|
2
|
+
require File.dirname(__FILE__) + "/catch_all/version"
|
3
|
+
|
4
|
+
module ActionMailer
|
5
|
+
module CatchAll
|
6
|
+
class << self
|
7
|
+
def enabled?
|
8
|
+
ActionMailer::Base.instance_methods.include?(:mail_aliased_from_action_mailer_staging)
|
9
|
+
end
|
10
|
+
|
11
|
+
def enable(*to_addresses)
|
12
|
+
to_addresses = to_addresses.flatten
|
13
|
+
|
14
|
+
ActionMailer::Base.class_eval do
|
15
|
+
if instance_methods.include?(:mail_aliased_from_action_mailer_staging)
|
16
|
+
ActionMailerStaging.disable
|
17
|
+
end
|
18
|
+
|
19
|
+
alias_method :mail_aliased_from_action_mailer_staging, :mail
|
20
|
+
|
21
|
+
define_method :mail do |*args, &block|
|
22
|
+
mailer = mail_aliased_from_action_mailer_staging(*args, &block)
|
23
|
+
|
24
|
+
to_values = Array(mailer[:to]).map do |field|
|
25
|
+
field.value
|
26
|
+
end
|
27
|
+
|
28
|
+
# save the original to header
|
29
|
+
mailer['X-Action-Mailer-Staging-Original-Email-To'] = to_values.inspect
|
30
|
+
selected_to_addresses = to_values.select { |to| to_addresses.include?(to) }
|
31
|
+
if selected_to_addresses.any?
|
32
|
+
mailer[:to] = selected_to_addresses
|
33
|
+
else
|
34
|
+
mailer[:to] = to_addresses
|
35
|
+
end
|
36
|
+
|
37
|
+
mailer
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def disable
|
43
|
+
if enabled?
|
44
|
+
ActionMailer::Base.class_eval do
|
45
|
+
alias_method :mail, :mail_aliased_from_action_mailer_staging
|
46
|
+
remove_method :mail_aliased_from_action_mailer_staging
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/catch_all'
|
2
|
+
|
3
|
+
class Notifier < ActionMailer::Base
|
4
|
+
def notify
|
5
|
+
mail(:to => "scott@learnup.me")
|
6
|
+
end
|
7
|
+
|
8
|
+
def notify_multiple
|
9
|
+
mail(:to => ["scott@learnup.me", "kenny@learnup.me"])
|
10
|
+
end
|
11
|
+
|
12
|
+
def notify_with_name
|
13
|
+
mail(:to => "Scott Taylor <scott@learnup.me>")
|
14
|
+
end
|
15
|
+
|
16
|
+
def notify_no_address
|
17
|
+
mail()
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ActionMailer::CatchAll do
|
22
|
+
before :each do
|
23
|
+
ActionMailer::CatchAll.disable
|
24
|
+
end
|
25
|
+
|
26
|
+
after :all do
|
27
|
+
ActionMailer::CatchAll.disable
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should disable properly" do
|
31
|
+
ActionMailer::CatchAll.disable
|
32
|
+
ActionMailer::CatchAll.disable
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should override the to address when enabled" do
|
36
|
+
ActionMailer::CatchAll.enable("scott@railsnewbie.com")
|
37
|
+
mailer = Notifier.notify
|
38
|
+
mailer.to.should == ["scott@railsnewbie.com"]
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should use the correct email" do
|
42
|
+
ActionMailer::CatchAll.enable("foo@railsnewbie.com")
|
43
|
+
mailer = Notifier.notify
|
44
|
+
mailer.to.should == ["foo@railsnewbie.com"]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should allow a list of emails" do
|
48
|
+
ActionMailer::CatchAll.enable(["foo@railsnewbie.com", "bar@railsnewbie.com"])
|
49
|
+
mailer = Notifier.notify
|
50
|
+
mailer.to.should == ["foo@railsnewbie.com", "bar@railsnewbie.com"]
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should allow a list of emails in splatted format" do
|
54
|
+
ActionMailer::CatchAll.enable("foo@railsnewbie.com", "bar@railsnewbie.com")
|
55
|
+
mailer = Notifier.notify
|
56
|
+
mailer.to.should == ["foo@railsnewbie.com", "bar@railsnewbie.com"]
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should send an email to the intended recipient if on the list (and only to the intended recipient)" do
|
60
|
+
ActionMailer::CatchAll.enable("scott@learnup.me", "bar@railsnewbie.com")
|
61
|
+
mailer = Notifier.notify
|
62
|
+
mailer.to.should == ["scott@learnup.me"]
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should only email the intersection of the lists" do
|
66
|
+
ActionMailer::CatchAll.enable("scott@learnup.me", "scott@railsnewbie.com")
|
67
|
+
mailer = Notifier.notify
|
68
|
+
mailer.to.should == ["scott@learnup.me"]
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should allow for <> in the email format" do
|
72
|
+
ActionMailer::CatchAll.enable("scott@learnup.me")
|
73
|
+
mailer = Notifier.notify
|
74
|
+
mailer.to.should == ["scott@learnup.me"]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should email even if no :to address is specified" do
|
78
|
+
ActionMailer::CatchAll.enable('scott@railsnewbie.com')
|
79
|
+
mailer = Notifier.notify_no_address
|
80
|
+
mailer.to.should == ["scott@railsnewbie.com"]
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should set a header with the original to address" do
|
84
|
+
ActionMailer::CatchAll.enable('scott@railsnewbie.com')
|
85
|
+
mailer = Notifier.notify
|
86
|
+
mailer['X-Action-Mailer-Staging-Original-Email-To'].value.should == "[\"scott@learnup.me\"]"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should report as enabled when enabled" do
|
90
|
+
ActionMailer::CatchAll.enable("scott@railsnewbie.com")
|
91
|
+
ActionMailer::CatchAll.should be_enabled
|
92
|
+
|
93
|
+
ActionMailer::CatchAll.disable
|
94
|
+
ActionMailer::CatchAll.should_not be_enabled
|
95
|
+
end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: catch_all
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Scott Taylor
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Define a white-list only set of emails for ActionMailer
|
15
|
+
email:
|
16
|
+
- scott@railsnewbie.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rspec
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- README.md
|
26
|
+
- catch_all.gemspec
|
27
|
+
- lib/catch_all.rb
|
28
|
+
- lib/catch_all/version.rb
|
29
|
+
- spec/catch_all_spec.rb
|
30
|
+
homepage: ''
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.8.24
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Define a white-list only set of emails for ActionMailer. Used in staging
|
54
|
+
environments.
|
55
|
+
test_files:
|
56
|
+
- spec/catch_all_spec.rb
|