mandrill-mailer-rails 0.0.1 → 1.0.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: b0ed029c7a9b67be7053e52fafa05e8b22cbd1ff
4
- data.tar.gz: 37577c66c4ae50c876f12406269f9d74fd05f622
3
+ metadata.gz: ccb76410ba8ced75c59ccaaf95161ae650d88547
4
+ data.tar.gz: d60a21170dcad2539c6b1a4b4a2fac9a73153d15
5
5
  SHA512:
6
- metadata.gz: 6b846dd28090d152c6ca277a6482c5bbcc3216f9b7403d0588b206046cce075041226db28df901eed8d9cfd32c6f021e92dc9245c04c2b57268c1ad9d48ec4ff
7
- data.tar.gz: 115f94035526206786e1aecd4916f74b9b71884da3b706a9a14118ac25a034eb220ba6e531e67ad358eca44778c00496591a3444b00d73c762c3230ca2de58f9
6
+ metadata.gz: 5687dd3dad2725d6954c44b34ea868c9df7ea4cc7eca8f97041972bfcd3c3b8290643df7568a133253949ba53cf6d55101d5a63c71c362f71d863822f9409dbb
7
+ data.tar.gz: 6dd8e0991af1cbcfec672aea0fa24649a02ef826d2a3851f991c70d105ee88248d76c9e5ec0367cec99663373c95e9948af1ec4fc9fc69e4a369ab1d905468f3
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1
6
+ gemfile:
7
+ - gemfiles/rails_30.gemfile
8
+ - gemfiles/rails_31.gemfile
9
+ - gemfiles/rails_32.gemfile
10
+ - gemfiles/rails_40.gemfile
11
+ - gemfiles/rails_41.gemfile
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mandrill-mailer-rails (0.0.1)
4
+ mandrill-mailer-rails (1.0.0)
5
5
  mandrill-api
6
6
  rails (> 3.0)
7
7
 
@@ -42,7 +42,7 @@ GEM
42
42
  builder (3.2.2)
43
43
  diff-lcs (1.2.5)
44
44
  erubis (2.7.0)
45
- excon (0.40.0)
45
+ excon (0.42.1)
46
46
  hike (1.2.3)
47
47
  i18n (0.6.11)
48
48
  json (1.8.1)
@@ -51,7 +51,7 @@ GEM
51
51
  mandrill-api (1.0.52)
52
52
  excon (>= 0.16.0, < 1.0)
53
53
  json (>= 1.7.7, < 2.0)
54
- mime-types (2.4.1)
54
+ mime-types (2.4.3)
55
55
  minitest (5.4.2)
56
56
  multi_json (1.10.1)
57
57
  rack (1.5.2)
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # mandrill-mailer-rails
2
- =====================
2
+
3
+ [![Build Status](https://travis-ci.org/bsedat/mandrill-mailer-rails.svg)](https://travis-ci.org/bsedat/mandrill-mailer-rails)
3
4
 
4
5
  Handler for Rails' ActionMailer to send emails through Mandrill.
5
6
 
data/Rakefile CHANGED
@@ -2,3 +2,5 @@ require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -1,14 +1,19 @@
1
1
  module MandrillActionMailer
2
2
  class DeliveryHandler
3
- attr_accessor :settings
3
+ attr_accessor :settings, :result
4
4
 
5
5
  MIME_TYPES = {
6
6
  :html => "text/html",
7
7
  :text => "text/plain"
8
8
  }.freeze
9
9
 
10
+ FULL_EMAIL_REGEX = /\A\s*(.+?)\s*<\s*(?:[^>]+)\s*>\s*\z/
11
+
10
12
  def initialize(options={})
11
- self.settings = { :track_opens => MandrillActionMailer.config.track_opens, :track_clicks => MandrillActionMailer.config.track_clicks }.merge(options)
13
+ self.settings = {
14
+ :track_opens => MandrillActionMailer.config.track_opens,
15
+ :track_clicks => MandrillActionMailer.config.track_clicks
16
+ }.merge(options)
12
17
  end
13
18
 
14
19
  def deliver!(message)
@@ -21,7 +26,11 @@ module MandrillActionMailer
21
26
  }
22
27
 
23
28
  if !(message[:from_name].nil? || message[:from_name].value.blank?)
29
+ # If a from name is set, use it.
24
30
  message_payload[:from_name] = message[:from_name].value
31
+ elsif !(message[:from_email].nil?) && (m = FULL_EMAIL_REGEX.match(message[:from_email].value))
32
+ # If no from name is set, check to see if they set it in the email field.
33
+ message_payload[:from_name] = m[1]
25
34
  end
26
35
 
27
36
  if !message.reply_to.blank?
@@ -38,7 +47,7 @@ module MandrillActionMailer
38
47
  message_payload[format] = content.to_s unless content.blank?
39
48
  end
40
49
 
41
- MandrillActionMailer.client.messages.send(message_payload)
50
+ self.result = MandrillActionMailer.client.messages.send(message_payload)
42
51
  end
43
52
 
44
53
  private
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mandrill-mailer-rails'
3
- s.version = '0.0.1'
3
+ s.version = '1.0.0'
4
4
  s.authors = ['Tinfoil Security, Inc.']
5
5
  s.email = ['engineers@tinfoilsecurity.com']
6
6
  s.homepage = 'https://www.github.com/bsedat/mandrill-mailer-rails'
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'MandrillActionMailer::DeliverHandler' do
3
+ describe 'MandrillActionMailer::DeliveryHandler' do
4
4
  let(:client) { double('Mandrill::API') }
5
5
  let(:sender) { double('Mandrill::Messages') }
6
6
 
@@ -41,6 +41,25 @@ describe 'MandrillActionMailer::DeliverHandler' do
41
41
  Notifier.test.deliver
42
42
  end
43
43
 
44
+ context 'delivery method accessors' do
45
+ before do
46
+ expect(sender).to receive(:send).and_return 'foo' => 'bar'
47
+ @mail = Notifier.test.deliver
48
+ end
49
+
50
+ it 'should have settings for `track_opens`' do
51
+ expect(@mail.delivery_method.settings[:track_opens]).to eq true
52
+ end
53
+
54
+ it 'should have settings for `track_clicks`' do
55
+ expect(@mail.delivery_method.settings[:track_clicks]).to eq false
56
+ end
57
+
58
+ it 'should have response from mandrill api in `result`' do
59
+ expect(@mail.delivery_method.result).to eq 'foo' => 'bar'
60
+ end
61
+ end
62
+
44
63
  it 'should set the subject' do
45
64
  expect(sender).to receive(:send).with(
46
65
  hash_including(
@@ -73,7 +92,7 @@ describe 'MandrillActionMailer::DeliverHandler' do
73
92
  it 'should set the from_name field' do
74
93
  expect(sender).to receive(:send).with(
75
94
  hash_including(
76
- :from_name => Notifier::FROM
95
+ :from_name => Notifier::FROM_NAME
77
96
  )
78
97
  )
79
98
 
@@ -81,6 +100,18 @@ describe 'MandrillActionMailer::DeliverHandler' do
81
100
  end
82
101
  end
83
102
 
103
+ context 'when the from_email contains a name' do
104
+ it 'should set the from_name field' do
105
+ expect(sender).to receive(:send).with(
106
+ hash_including(
107
+ :from_name => Notifier::FROM_NAME
108
+ )
109
+ )
110
+
111
+ Notifier.test_from_email_with_name.deliver
112
+ end
113
+ end
114
+
84
115
  it 'should set the to field' do
85
116
  expect(sender).to receive(:send).with(
86
117
  hash_including(
@@ -2,6 +2,8 @@ class Notifier < ActionMailer::Base
2
2
  TO = 'to@example.org'
3
3
  MANY_TO = [TO, 'to2@example.org']
4
4
  FROM = 'from@example.org'
5
+ FROM_NAME = 'From Name'
6
+ FROM_EMAIL_WITH_NAME = "#{FROM_NAME} <#{FROM}>"
5
7
  SUBJECT = 'Test Subject'
6
8
  REPLY_TO = 'reply@example.org'
7
9
  BCC = 'bcc@example.org'
@@ -21,7 +23,11 @@ class Notifier < ActionMailer::Base
21
23
  end
22
24
 
23
25
  def test_from_name
24
- mail from_name: FROM, template_name: 'test'
26
+ mail from_name: FROM_NAME, template_name: 'test'
27
+ end
28
+
29
+ def test_from_email_with_name
30
+ mail from_email: FROM_EMAIL_WITH_NAME, template_name: 'test'
25
31
  end
26
32
 
27
33
  def to_many
@@ -30,6 +30,8 @@ TestRailsApp::Application.configure do
30
30
  # The :test delivery method accumulates sent emails in the
31
31
  # ActionMailer::Base.deliveries array.
32
32
  config.action_mailer.delivery_method = :mandrill
33
+ config.mandrill_action_mailer.track_opens = true
34
+ config.mandrill_action_mailer.track_clicks = false
33
35
 
34
36
  # Print deprecation notices to the stderr.
35
37
  config.active_support.deprecation = :stderr
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandrill-mailer-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tinfoil Security, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-09 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mandrill-api
@@ -102,6 +102,7 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - .gitignore
105
+ - .travis.yml
105
106
  - Appraisals
106
107
  - Gemfile
107
108
  - Gemfile.lock
@@ -123,7 +124,7 @@ files:
123
124
  - lib/mandrill_action_mailer/delivery_handler.rb
124
125
  - lib/mandrill_action_mailer/railtie.rb
125
126
  - mandrill-mailer-rails.gemspec
126
- - spec/integration/deliver_handler_spec.rb
127
+ - spec/integration/delivery_handler_spec.rb
127
128
  - spec/rails_app/.gitignore
128
129
  - spec/rails_app/Rakefile
129
130
  - spec/rails_app/app/mailers/notifier.rb
@@ -165,12 +166,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
166
  version: '0'
166
167
  requirements: []
167
168
  rubyforge_project:
168
- rubygems_version: 2.4.1
169
+ rubygems_version: 2.4.5
169
170
  signing_key:
170
171
  specification_version: 4
171
172
  summary: Handler for Rails to send emails through Mandrill
172
173
  test_files:
173
- - spec/integration/deliver_handler_spec.rb
174
+ - spec/integration/delivery_handler_spec.rb
174
175
  - spec/rails_app/.gitignore
175
176
  - spec/rails_app/Rakefile
176
177
  - spec/rails_app/app/mailers/notifier.rb