mail_interceptor 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 691b985934a4d8d914973c060939febba013f974
4
- data.tar.gz: ce02faa6ca1925dba811e607ceb5b015e7ce10da
3
+ metadata.gz: 00ca7563318bdfe6a5a029d688a30a11389c6241
4
+ data.tar.gz: 822c440a035866a071146d0c18ea8ae4cf0ca2f6
5
5
  SHA512:
6
- metadata.gz: 1d47f4ab350a5a78dbc0628edb983ad02a867aefd72893284012efe6e62284596120c1e7dcf7ead1022bd64bff723de6fcbb93830dd1217cbe2180566e22da70
7
- data.tar.gz: fe81f686a1df5e724f94380cf7ed94375e573df5a310f5c7900f0485d8331fdeb4f73043532e4e2b9263eb070628a202c38e6d8ccefe99439e2b7c8d6589f25b
6
+ metadata.gz: f9996e2846789d53d5e7bff41c2a1141b9655ad935450fab2e05fb88967633f6569632b7f3236a7f22b3f98d9391b449f2eb0dbd9236f9186591bdcc1e9a51c2
7
+ data.tar.gz: d5a63b1210264f18dbae927675dbf0cf7a8e7b66033f0f7a326c68ae55ef2e072de486c6b5feccc4646c3dff0e9a950bf84c905c30ff85efeef606ae28e9048d
data/README.md CHANGED
@@ -3,19 +3,17 @@
3
3
  [![Circle CI](https://circleci.com/gh/bigbinary/mail_interceptor.svg?style=svg)](https://circleci.com/gh/bigbinary/mail_interceptor)
4
4
 
5
5
  This gem intercepts and forwards email to a forwarding address in
6
- non-production environment. However it also provides ability to not
6
+ a non-production environment. It also allows to not
7
7
  intercept certain emails so that testing of emails is easier in
8
8
  development/staging environment.
9
9
 
10
- If `subject_prefix` is supplied then that is added to every single email
11
- in both production and non-production environment.
12
-
13
10
  ## Installation
14
11
 
15
12
  Add this line to your application's Gemfile:
16
13
 
17
14
  ```ruby
18
- gem 'mail_interceptor'
15
+ # There is no need to include this gem for production or for test environment
16
+ gem 'mail_interceptor', group: [:development, :staging]
19
17
  ```
20
18
 
21
19
  ## Usage
@@ -24,11 +22,11 @@ gem 'mail_interceptor'
24
22
  # config/initializer/mail_interceptor.rb
25
23
 
26
24
  options = { forward_emails_to: 'intercepted_emails@domain.com',
27
- deliver_emails_to: ["@wheel.com"],
28
- subject_prefix: 'WHEEL' }
25
+ deliver_emails_to: ["@wheel.com"] }
29
26
 
30
27
  interceptor = MailInterceptor::Interceptor.new(options)
31
- unless Rails.env.test?
28
+
29
+ unless (Rails.env.test? || Rails.env.production?)
32
30
  ActionMailer::Base.register_interceptor(interceptor)
33
31
  end
34
32
  ```
@@ -64,22 +62,11 @@ will be intercepted and forwarded.
64
62
  The regular expression is matched without case sensitive. So you can mix lowercase
65
63
  and uppercase and it won't matter.
66
64
 
67
- ### subject_prefix
68
-
69
- __subject_prefix__ is optional. If it is supplied then it is added to
70
- the front of the subject. In non-production environment the environment
71
- name is also added.
72
-
73
- ```
74
- [WHEEL] Forgot password
75
- [WHEEL STAGING] Forgot password
76
- ```
77
-
78
65
  ### forward_emails_to
79
66
 
80
67
  This is a required field.
81
68
 
82
- It takes a single email as string.
69
+ It can take a single email or an array of emails.
83
70
 
84
71
  ```ruby
85
72
  MailInterceptor::Interceptor.new({ forward_emails_to: 'intercepted_emails@bigbinary.com' })
@@ -94,15 +81,24 @@ MailInterceptor::Interceptor.new({ forward_emails_to: ['intercepted_emails@bigbi
94
81
 
95
82
  ### Custom environment
96
83
 
97
- If your staging environment is using the same Rails environment as
98
- production, you can pass in an object with the name of the environment
99
- and whether to intercept mail as an option. The default is to use
100
- `Rails.env` and intercept mail in all environments except production.
84
+ By default all emails sent in non production environment are
85
+ intercepted. However you can control this behavior by passing `env` as
86
+ the key. It accepts any ruby objects which responds to `intercept?`
87
+ method. If the result of that method is `true` then emails are
88
+ intercepted otherwise emails are not intercepted.
89
+
90
+ Below is an example of how to pass a custom ruby object as value for
91
+ `env` key.
92
+
93
+ Besides method `intercept?` method `name` is needed if you have provided
94
+ `subject_prefix`. This name will be appended to the `subject_prefix` to
95
+ produce something like `[WHEEL STAGING] Forgot password`. In this case
96
+ `STAGING` came form `name`.
101
97
 
102
98
  ```ruby
103
99
  class MyEnv
104
100
  def name
105
- ENV["INSTANCE_NAME"]
101
+ ENV["ENVIRONMENT_NAME"]
106
102
  end
107
103
 
108
104
  def intercept?
@@ -4,20 +4,17 @@ require "mail_interceptor/version"
4
4
 
5
5
  module MailInterceptor
6
6
  class Interceptor
7
- attr_accessor :deliver_emails_to, :forward_emails_to, :subject_prefix, :env
7
+ attr_accessor :deliver_emails_to, :forward_emails_to, :env
8
8
 
9
9
  def initialize options = {}
10
10
  @deliver_emails_to = Array.wrap options[:deliver_emails_to]
11
- @subject_prefix = options[:subject_prefix] || ''
12
11
  @forward_emails_to = options.fetch :forward_emails_to
13
12
  @env = options.fetch :env, InterceptorEnv.new
14
13
 
15
- add_env_info_to_subject_prefix
16
14
  sanitize_forward_emails_to
17
15
  end
18
16
 
19
17
  def delivering_email message
20
- add_subject_prefix message
21
18
  message.to = normalize_recipients(message.to).flatten.uniq
22
19
  end
23
20
 
@@ -37,12 +34,6 @@ module MailInterceptor
37
34
  end
38
35
  end
39
36
 
40
- def add_subject_prefix message
41
- return if subject_prefix.blank?
42
-
43
- message.subject = "#{subject_prefix} #{message.subject}"
44
- end
45
-
46
37
  def sanitize_forward_emails_to
47
38
  self.forward_emails_to = Array.wrap forward_emails_to
48
39
 
@@ -51,13 +42,6 @@ module MailInterceptor
51
42
  end
52
43
  end
53
44
 
54
- def add_env_info_to_subject_prefix
55
- return if subject_prefix.blank?
56
-
57
- _prefix = env.intercept? ? "#{subject_prefix} #{env.name}" : subject_prefix
58
- self.subject_prefix = "[#{_prefix}]"
59
- end
60
-
61
45
  def forward_emails_to_empty?
62
46
  Array.wrap(forward_emails_to).reject(&:blank?).empty?
63
47
  end
@@ -1,3 +1,3 @@
1
1
  module MailInterceptor
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -36,63 +36,26 @@ class MailInterceptorTest < Minitest::Test
36
36
  assert_equal ["a@wheel.com", "b@wheel.com", "c@pump.com", "test@example.com", "john@gmail.com"], @message.to
37
37
  end
38
38
 
39
- def test_no_subject_prefix_in_test
40
- interceptor = ::MailInterceptor::Interceptor.new env: env,
41
- forward_emails_to: 'test@example.com',
42
- subject_prefix: nil
43
- @message.subject = 'Forgot password'
44
-
45
- interceptor.delivering_email @message
46
- assert_equal "Forgot password", @message.subject
47
- end
48
-
49
- def test_subject_prefix_in_test
50
- interceptor = ::MailInterceptor::Interceptor.new env: env,
51
- forward_emails_to: 'test@example.com',
52
- subject_prefix: 'wheel'
53
- @message.subject = 'Forgot password'
54
-
55
- interceptor.delivering_email @message
56
- assert_equal "[wheel TEST] Forgot password", @message.subject
57
-
58
- @message.subject = 'Another Forgot password'
59
- interceptor.delivering_email @message
60
- assert_equal "[wheel TEST] Another Forgot password", @message.subject
61
- end
62
-
63
- def test_subject_prefix_in_production
64
- interceptor = ::MailInterceptor::Interceptor.new env: env('production'),
65
- forward_emails_to: 'test@example.com',
66
- subject_prefix: 'wheel'
67
- @message.subject = 'Forgot password'
68
-
69
- interceptor.delivering_email @message
70
- assert_equal "[wheel] Forgot password", @message.subject
71
- end
72
-
73
39
  def test_error_if_forward_emails_to_is_empty
74
40
  message = "forward_emails_to should not be empty"
75
41
 
76
42
  exception = assert_raises(RuntimeError) do
77
43
  ::MailInterceptor::Interceptor.new env: env,
78
- forward_emails_to: '',
79
- subject_prefix: 'wheel'
44
+ forward_emails_to: ''
80
45
  end
81
46
 
82
47
  assert_equal message, exception.message
83
48
 
84
49
  exception = assert_raises(RuntimeError) do
85
50
  ::MailInterceptor::Interceptor.new env: env,
86
- forward_emails_to: [],
87
- subject_prefix: 'wheel'
51
+ forward_emails_to: []
88
52
  end
89
53
 
90
54
  assert_equal message, exception.message
91
55
 
92
56
  exception = assert_raises(RuntimeError) do
93
57
  ::MailInterceptor::Interceptor.new env: env,
94
- forward_emails_to: [''],
95
- subject_prefix: 'wheel'
58
+ forward_emails_to: ['']
96
59
  end
97
60
 
98
61
  assert_equal message, exception.message
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail_interceptor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neeraj Singh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-22 00:00:00.000000000 Z
11
+ date: 2015-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  requirements: []
118
118
  rubyforge_project:
119
- rubygems_version: 2.2.2
119
+ rubygems_version: 2.4.5
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: Intercepts and forwards emails in non production environment