email_prefixer 1.0.2 → 1.1.0

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: 7702d0b953f2c520988dc25b8cff260d405fd0ad
4
- data.tar.gz: 19c241633096b2754c8cb081f12e4ec027d3de3a
3
+ metadata.gz: b61b05c800103a57cec9350aaa65927affc4d587
4
+ data.tar.gz: ce1f60d57950924b048d6f17d3919dcf5f461b95
5
5
  SHA512:
6
- metadata.gz: 6c88e03eeec1aa766f24692d4735aa2595b9b277d33435e358c5826550bf6c1f785e5f12adc18a666c14d25b0e5f33c1204be6c4e509d8d4aafb81aefacce6dd
7
- data.tar.gz: 01fc43833f98b12d051fa7a0ea3e1db4fa1f14ed2295226dc661a3aa88c73dc30185d233bd29697960f7ac058083cbe4fb384c7002d00ddf708ec8ab098aa643
6
+ metadata.gz: 4145cf9ded7b88ade8a6467f7616c88116c74af43055aa9ff732008def8aa1339a8dd74d59da279526c906f8b7fbd84d0a02ec0b9ae89023c3a705a4ae708234
7
+ data.tar.gz: c6a2266d03a164ecbac1f405c553a6043efbd2f62fae69da4430162a7931a4b5b29f0ca02aa8809224516c3aeb740a3aeeaa741ff4bf3ee8767a4274861aa32f
data/README.md CHANGED
@@ -25,17 +25,41 @@ gem 'email_prefixer'
25
25
  ```
26
26
 
27
27
  ## Configuration
28
+ All EmailPrefixer configuration can be customized using
29
+ a standard Rails config initializer.
28
30
 
29
- #### Custom Application Name
30
- EmailPrefixer automatically infers the application name
31
- from the Rails application class name, but this can be
32
- changed using a standard config/initializer.
31
+ ```ruby
32
+ # config/initializers/email_prefixer.rb
33
+ EmailPrefixer.configure do |config|
34
+ # custom configuration goes here
35
+ end
36
+ ```
37
+
38
+ Some of the more common configuration options are listed here.
39
+ See the source code and test suite for a full list of options.
40
+
41
+ #### application_name - Customize Application Name
42
+ The application name is automatically inferred from the Rails application class name
43
+ and can be overridden via the `application_name` setting.
44
+
45
+ Example:
46
+ ```ruby
47
+ # config/initializers/email_prefixer.rb
48
+ EmailPrefixer.configure do |config|
49
+ config.application_name = 'MyApp'
50
+ end
51
+ ```
52
+
53
+ #### stage_name - Customize Environment Stage Name
54
+ The application environment/stage name is automatically
55
+ inferred from the running Rails.env and it can be overridden
56
+ via the `stage_name` setting.
33
57
 
34
58
  Example:
35
59
  ```ruby
36
60
  # config/initializers/email_prefixer.rb
37
61
  EmailPrefixer.configure do |config|
38
- config.application_name = 'MyCompany'
62
+ config.stage_name = 'demo'
39
63
  end
40
64
  ```
41
65
 
@@ -1,5 +1,5 @@
1
1
  module EmailPrefixer
2
2
  class Configuration
3
- attr_accessor :application_name
3
+ attr_accessor :application_name, :stage_name
4
4
  end
5
5
  end
@@ -1,5 +1,12 @@
1
1
  module EmailPrefixer
2
2
  class Interceptor
3
+ extend Forwardable
4
+ def_delegators :@configuration, :application_name, :stage_name
5
+
6
+ def initialize
7
+ @configuration = EmailPrefixer.configuration
8
+ end
9
+
3
10
  def delivering_email(mail)
4
11
  mail.subject.prepend(subject_prefix)
5
12
  end
@@ -9,8 +16,8 @@ module EmailPrefixer
9
16
 
10
17
  def subject_prefix
11
18
  prefixes = []
12
- prefixes << EmailPrefixer.configuration.application_name
13
- prefixes << Rails.env.upcase unless Rails.env.production?
19
+ prefixes << application_name
20
+ prefixes << stage_name.upcase unless stage_name == 'production'
14
21
  "[#{prefixes.join(' ')}] "
15
22
  end
16
23
  end
@@ -6,6 +6,7 @@ module EmailPrefixer
6
6
  ActionMailer::Base.register_interceptor(interceptor)
7
7
  EmailPrefixer.configure do |config|
8
8
  config.application_name ||= app.class.parent_name
9
+ config.stage_name ||= Rails.env
9
10
  end
10
11
  end
11
12
  end
@@ -1,3 +1,3 @@
1
1
  module EmailPrefixer
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -2,12 +2,42 @@ require 'rails_helper'
2
2
 
3
3
  RSpec.describe EmailPrefixer::Interceptor do
4
4
  describe '#delivering_email' do
5
- before do
6
- ExampleMailer.simple_mail.deliver
5
+ subject(:email) { ExampleMailer.simple_mail }
6
+ context 'when application_name is configured' do
7
+ before do
8
+ email.deliver_now
9
+ end
10
+ it 'adds prefix to delivered mail subject' do
11
+ expect(email.subject).to eq '[CustomApp TEST] Here is the Subject'
12
+ end
7
13
  end
8
- it 'adds prefix to delivered mail subject' do
9
- mail = ActionMailer::Base.deliveries.last
10
- expect(mail.subject).to eq '[CustomApp TEST] Here is the Subject'
14
+
15
+ context 'when stage_name is configured' do
16
+ before do
17
+ @original_stage_name = EmailPrefixer.configuration.stage_name
18
+ EmailPrefixer.configuration.stage_name = 'staging'
19
+ email.deliver_now
20
+ end
21
+ after do
22
+ EmailPrefixer.configuration.stage_name = @original_stage_name
23
+ end
24
+ it 'adds custom stage name to subject' do
25
+ expect(email.subject).to eq '[CustomApp STAGING] Here is the Subject'
26
+ end
27
+ end
28
+
29
+ context 'when stage_name == production' do
30
+ before do
31
+ @original_stage_name = EmailPrefixer.configuration.stage_name
32
+ EmailPrefixer.configuration.stage_name = 'production'
33
+ email.deliver_now
34
+ end
35
+ after do
36
+ EmailPrefixer.configuration.stage_name = @original_stage_name
37
+ end
38
+ it 'does not add the stage_name to the subject' do
39
+ expect(email.subject).to eq '[CustomApp] Here is the Subject'
40
+ end
11
41
  end
12
42
  end
13
43
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'coveralls'
2
2
  Coveralls.wear!
3
3
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+ Dir[File.join('support/**/*.rb')].each { |f| require f }
4
5
 
5
6
  RSpec.configure do |config|
6
7
  config.expect_with :rspec do |expectations|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_prefixer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Sonnek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-09 00:00:00.000000000 Z
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails