mandriller 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 774c2fa8ff2956266ac2b7a42411dddeb979ad16
4
+ data.tar.gz: 583f26ca46dd4c2dc6fe8c0f705b32b71ecdc488
5
+ SHA512:
6
+ metadata.gz: 2c4073662c7f0c1d5bd98540603de84fd8340dd4af860ed79be72cd510fe7f96fa1fc4a3c7bd9d070c34b90a4854a1bc1fd9bcfcb79d4923248a697960c562f1
7
+ data.tar.gz: 4b140218ed3d09dd4758f91654076459cb96fd274658948304bb1a750db9a79a3fac9386813849dd6657ecbfe4d9a3675ee3cf8ac483336791fe818e5099e840
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,88 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mandriller (0.0.1)
5
+ actionmailer (>= 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ abstract (1.0.0)
11
+ actionmailer (3.0.1)
12
+ actionpack (= 3.0.1)
13
+ mail (~> 2.2.5)
14
+ actionpack (3.0.1)
15
+ activemodel (= 3.0.1)
16
+ activesupport (= 3.0.1)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.4.1)
20
+ rack (~> 1.2.1)
21
+ rack-mount (~> 0.6.12)
22
+ rack-test (~> 0.5.4)
23
+ tzinfo (~> 0.3.23)
24
+ activemodel (3.0.1)
25
+ activesupport (= 3.0.1)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.4.1)
28
+ activesupport (3.0.1)
29
+ builder (2.1.2)
30
+ coveralls (0.7.0)
31
+ multi_json (~> 1.3)
32
+ rest-client
33
+ simplecov (>= 0.7)
34
+ term-ansicolor
35
+ thor
36
+ diff-lcs (1.2.5)
37
+ docile (1.1.5)
38
+ erubis (2.6.6)
39
+ abstract (>= 1.0.0)
40
+ i18n (0.4.2)
41
+ mail (2.2.7)
42
+ activesupport (>= 2.3.6)
43
+ mime-types
44
+ treetop (>= 1.4.5)
45
+ mime-types (2.3)
46
+ multi_json (1.10.1)
47
+ polyglot (0.3.5)
48
+ rack (1.2.8)
49
+ rack-mount (0.6.14)
50
+ rack (>= 1.0.0)
51
+ rack-test (0.5.7)
52
+ rack (>= 1.0)
53
+ rake (10.3.2)
54
+ rest-client (1.6.7)
55
+ mime-types (>= 1.16)
56
+ rspec (3.0.0)
57
+ rspec-core (~> 3.0.0)
58
+ rspec-expectations (~> 3.0.0)
59
+ rspec-mocks (~> 3.0.0)
60
+ rspec-core (3.0.2)
61
+ rspec-support (~> 3.0.0)
62
+ rspec-expectations (3.0.2)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.0.0)
65
+ rspec-mocks (3.0.2)
66
+ rspec-support (~> 3.0.0)
67
+ rspec-support (3.0.2)
68
+ simplecov (0.8.2)
69
+ docile (~> 1.1.0)
70
+ multi_json
71
+ simplecov-html (~> 0.8.0)
72
+ simplecov-html (0.8.0)
73
+ term-ansicolor (1.3.0)
74
+ tins (~> 1.0)
75
+ thor (0.19.1)
76
+ tins (1.3.0)
77
+ treetop (1.5.3)
78
+ polyglot (~> 0.3)
79
+ tzinfo (0.3.39)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ coveralls
86
+ mandriller!
87
+ rake
88
+ rspec (>= 3.0)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Daisuke Taniwaki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # mandriller
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/mandriller.svg)](http://badge.fury.io/rb/mandriller) [![Build Status](https://secure.travis-ci.org/dtaniwaki/mandriller.png)](http://travis-ci.org/dtaniwaki/mandriller) [![Coverage Status](https://coveralls.io/repos/dtaniwaki/mandriller/badge.png)](https://coveralls.io/r/dtaniwaki/mandriller)
4
+
5
+ Mandriller SMTP API integration for ActionMailer.
6
+
7
+ ## Installation
8
+
9
+ Add the mandriller gem to your Gemfile.
10
+
11
+ ```ruby
12
+ gem "mandriller"
13
+ ```
14
+
15
+ And run `bundle install`.
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ class UserMailer < Mandriller::Base
21
+ set_google_analytics_campaign
22
+ set_open_track
23
+
24
+ def test_mail
25
+ set_click_track
26
+ mail from: 'from@example.com', to: 'to@example.com'
27
+ end
28
+ end
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new [Pull Request](../../pull/new/master)
38
+
39
+ ## Copyright
40
+
41
+ Copyright (c) 2014 Daisuke Taniwaki. See [LICENSE](LICENSE) for details.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = FileList['spec/**/*_spec.rb']
7
+ end
8
+ task :default => :spec
data/aaa ADDED
File without changes
@@ -0,0 +1,5 @@
1
+ {
2
+ "result": {
3
+ "covered_percent": 100.0
4
+ }
5
+ }
@@ -0,0 +1,277 @@
1
+ {
2
+ "RSpec": {
3
+ "coverage": {
4
+ "/Users/dtaniwaki/github/mandriller/lib/mandriller.rb": [
5
+ 1,
6
+ 1,
7
+ 1,
8
+ null,
9
+ 1,
10
+ null
11
+ ],
12
+ "/Users/dtaniwaki/github/mandriller/lib/mandriller/errors.rb": [
13
+ 1,
14
+ 1,
15
+ 1,
16
+ null
17
+ ],
18
+ "/Users/dtaniwaki/github/mandriller/lib/mandriller/base.rb": [
19
+ 1,
20
+ 1,
21
+ null,
22
+ 1,
23
+ 1,
24
+ null,
25
+ 1,
26
+ null,
27
+ null,
28
+ null,
29
+ null,
30
+ null,
31
+ null,
32
+ null,
33
+ null,
34
+ null,
35
+ 1,
36
+ null,
37
+ null,
38
+ null,
39
+ null,
40
+ null,
41
+ null,
42
+ null,
43
+ 1,
44
+ null,
45
+ null,
46
+ null,
47
+ 1,
48
+ 1,
49
+ 1,
50
+ 1,
51
+ 1,
52
+ 1,
53
+ null,
54
+ 1,
55
+ null,
56
+ 1,
57
+ 1,
58
+ 3,
59
+ null,
60
+ null,
61
+ 1,
62
+ 3,
63
+ null,
64
+ null,
65
+ null,
66
+ 1,
67
+ 3,
68
+ null,
69
+ null,
70
+ 1,
71
+ 3,
72
+ null,
73
+ null,
74
+ 1,
75
+ 134,
76
+ null,
77
+ 134,
78
+ 134,
79
+ 134,
80
+ 134,
81
+ 134,
82
+ 6,
83
+ 7,
84
+ null,
85
+ null,
86
+ 133,
87
+ null,
88
+ 133,
89
+ 133,
90
+ 4,
91
+ null,
92
+ null,
93
+ 133,
94
+ 133,
95
+ 4,
96
+ null,
97
+ null,
98
+ 133,
99
+ 133,
100
+ 3,
101
+ null,
102
+ null,
103
+ 133,
104
+ 1064,
105
+ 1064,
106
+ 56,
107
+ null,
108
+ null,
109
+ null,
110
+ 133,
111
+ 798,
112
+ 798,
113
+ 18,
114
+ null,
115
+ null,
116
+ null,
117
+ 133,
118
+ 266,
119
+ 266,
120
+ 6,
121
+ null,
122
+ null,
123
+ null,
124
+ 133,
125
+ null,
126
+ null,
127
+ 1,
128
+ null,
129
+ 1,
130
+ 7,
131
+ null,
132
+ null
133
+ ],
134
+ "/Users/dtaniwaki/github/mandriller/lib/mandriller/settings_methods.rb": [
135
+ 1,
136
+ 1,
137
+ 1,
138
+ 9,
139
+ null,
140
+ null,
141
+ 1,
142
+ 1,
143
+ 14,
144
+ 14,
145
+ 5,
146
+ null,
147
+ 9,
148
+ null,
149
+ null,
150
+ 14,
151
+ 27,
152
+ null,
153
+ null,
154
+ null,
155
+ null,
156
+ null,
157
+ null,
158
+ null,
159
+ null,
160
+ null,
161
+ null,
162
+ null,
163
+ null,
164
+ null,
165
+ null,
166
+ 1,
167
+ 2397,
168
+ null,
169
+ 1,
170
+ null,
171
+ null
172
+ ],
173
+ "/Users/dtaniwaki/github/mandriller/spec/support/action_mailer.rb": [
174
+ 1,
175
+ 94,
176
+ 94,
177
+ 94,
178
+ 188,
179
+ 94,
180
+ 94,
181
+ null,
182
+ null,
183
+ 1,
184
+ 39,
185
+ 39,
186
+ 39,
187
+ 78,
188
+ 39,
189
+ 39,
190
+ null,
191
+ null,
192
+ 1,
193
+ 1,
194
+ 1,
195
+ 1,
196
+ 1,
197
+ null,
198
+ 2,
199
+ null,
200
+ null
201
+ ],
202
+ "/Users/dtaniwaki/github/mandriller/spec/mandriller/settings_methods_spec.rb": [
203
+ 1,
204
+ null,
205
+ 1,
206
+ 1,
207
+ 8,
208
+ 8,
209
+ null,
210
+ null,
211
+ 1,
212
+ 6,
213
+ 6,
214
+ null,
215
+ 6,
216
+ null,
217
+ null,
218
+ 1,
219
+ 1,
220
+ 1,
221
+ 1,
222
+ null,
223
+ 1,
224
+ 1,
225
+ null,
226
+ 1,
227
+ 1,
228
+ 1,
229
+ 1,
230
+ null,
231
+ 1,
232
+ 1,
233
+ 1,
234
+ null,
235
+ null,
236
+ 1,
237
+ 1,
238
+ 2,
239
+ 2,
240
+ null,
241
+ 2,
242
+ null,
243
+ 1,
244
+ 1,
245
+ 1,
246
+ 1,
247
+ null,
248
+ 1,
249
+ 1,
250
+ 1,
251
+ null,
252
+ null,
253
+ null,
254
+ 1,
255
+ 1,
256
+ 1,
257
+ 1,
258
+ 1,
259
+ null,
260
+ 1,
261
+ 1,
262
+ 1,
263
+ 1,
264
+ null,
265
+ 1,
266
+ 1,
267
+ 1,
268
+ 1,
269
+ 1,
270
+ null,
271
+ null,
272
+ null
273
+ ]
274
+ },
275
+ "timestamp": 1403939267
276
+ }
277
+ }
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'actionmailer', '~> 3.0'
4
+ gemspec :path => '../'
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'actionmailer', '~> 3.1'
4
+ gemspec :path => '../'
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'actionmailer', '~> 3.2'
4
+ gemspec :path => '../'
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'actionmailer', '~> 4.0'
4
+ gemspec :path => '../'
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'actionmailer', '~> 4.1'
4
+ gemspec :path => '../'
data/gemfiles/gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec :path => '../'
data/lib/mandriller.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'mandriller/version'
2
+ require 'mandriller/errors'
3
+ require 'mandriller/base'
4
+
5
+ module Mandriller
6
+ end
@@ -0,0 +1,114 @@
1
+ require 'action_mailer'
2
+ require_relative 'settings_methods'
3
+
4
+ class Mandriller::Base < ActionMailer::Base
5
+ include Mandriller::SettingsMethods
6
+
7
+ BOOLEAN_SETTINGS = {
8
+ autotext: 'X-MC-Autotext',
9
+ autohtml: 'X-MC-AutoHtml',
10
+ url_strip_qs: 'X-MC-URLStripQS',
11
+ preserve_recipients: 'X-MC-PreserveRecipients',
12
+ inline_css: 'X-MC-InlineCSS',
13
+ google_analytics_campaign: 'X-MC-GoogleAnalyticsCampaign',
14
+ view_content_link: 'X-MC-ViewContentLink',
15
+ import: 'X-MC-Important',
16
+ }
17
+ STRING_SETTINGS = {
18
+ tracking_domain: 'X-MC-TrackingDomain',
19
+ signing_domain: 'X-MC-SigningDomain',
20
+ subaccount: 'X-MC-Subaccount',
21
+ bcc_address: 'X-MC-BccAddress',
22
+ ip_pool: 'X-MC-IpPool',
23
+ return_path_domain: 'X-MC-ReturnPathDomain',
24
+ }
25
+ JSON_SETTINGS = {
26
+ metadata: 'X-MC-Metadata',
27
+ merge_vars: 'X-MC-MergeVars',
28
+ }
29
+ define_settings_methods BOOLEAN_SETTINGS.keys, default: true
30
+ define_settings_methods STRING_SETTINGS.keys
31
+ define_settings_methods JSON_SETTINGS.keys
32
+ define_settings_methods :open_track, default: true
33
+ define_settings_methods :click_track, default: 'clicks'
34
+ define_settings_methods :send_at
35
+
36
+ class_attribute :mandrill_template, :mandrill_google_analytics
37
+
38
+ class << self
39
+ def set_template(template_name, block_name)
40
+ self.mandrill_template = [template_name, block_name]
41
+ end
42
+
43
+ def set_google_analytics(*domains)
44
+ self.mandrill_google_analytics = domains.flatten
45
+ end
46
+ end
47
+
48
+ def set_template(template_name, block_name = nil)
49
+ @mandrill_template = [template_name, block_name].compact
50
+ end
51
+
52
+ def set_google_analytics(*domains)
53
+ @mandrill_google_analytics = domains.flatten
54
+ end
55
+
56
+ def mail(*args)
57
+ m = super(*args)
58
+
59
+ tracks = []
60
+ tracks << ((@mandrill_open_track.nil? ? self.mandrill_open_track : @mandrill_open_track) ? 'opens' : nil)
61
+ tracks << (@mandrill_click_track.nil? ? self.mandrill_click_track : @mandrill_click_track)
62
+ tracks = tracks.compact.map(&:to_s)
63
+ unless tracks.empty?
64
+ tracks.each do |track|
65
+ validate_values!(track, %w(opens clicks_all clicks clicks_htmlonly clicks_textonly))
66
+ end
67
+ end
68
+ self.headers['X-MC-Track'] = tracks.join(',')
69
+
70
+ v = get_mandrill_setting("template")
71
+ unless v.nil?
72
+ self.headers['X-MC-Template'] = v.join('|')
73
+ end
74
+
75
+ v = get_mandrill_setting("google_analytics")
76
+ unless v.nil?
77
+ self.headers['X-MC-GoogleAnalytics'] = v.join(',')
78
+ end
79
+
80
+ dt = @mandrill_send_at.nil? ? self.mandrill_send_at : @mandrill_send_at
81
+ unless dt.nil?
82
+ self.headers['X-MC-SendAt'] = dt.utc.strftime('%Y-%m-%d %H:%M:%S')
83
+ end
84
+
85
+ BOOLEAN_SETTINGS.each do |key, header_name|
86
+ v = get_mandrill_setting(key)
87
+ unless v.nil?
88
+ self.headers[header_name] = v ? 'true' : 'false'
89
+ end
90
+ end
91
+
92
+ STRING_SETTINGS.each do |key, header_name|
93
+ v = get_mandrill_setting(key)
94
+ unless v.nil?
95
+ self.headers[header_name] = v.to_s
96
+ end
97
+ end
98
+
99
+ JSON_SETTINGS.each do |key, header_name|
100
+ v = get_mandrill_setting(key)
101
+ unless v.nil?
102
+ self.headers[header_name] = v.to_json
103
+ end
104
+ end
105
+
106
+ m
107
+ end
108
+
109
+ private
110
+
111
+ def validate_values!(value, valid_values)
112
+ raise Mandriller::InvalidHeaderValue, "#{value} is not included in #{valid_values.join(', ')}" unless valid_values.include?(value)
113
+ end
114
+ end
@@ -0,0 +1,4 @@
1
+ module Mandriller
2
+ class Exception < ::Exception; end;
3
+ class InvalidHeaderValue < Exception; end;
4
+ end
@@ -0,0 +1,37 @@
1
+ module Mandriller
2
+ module SettingsMethods
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def define_settings_methods(*keys)
9
+ options = keys[-1].is_a?(Hash) ? keys.pop : {}
10
+ if default = options[:default]
11
+ arg_s = "v = #{default.inspect}"
12
+ else
13
+ arg_s = "v"
14
+ end
15
+
16
+ keys.flatten.each do |key|
17
+ class_eval <<-EOS
18
+ class_attribute :mandrill_#{key}
19
+ def self.set_#{key}(#{arg_s})
20
+ self.mandrill_#{key} = v
21
+ end
22
+ private_class_method :set_#{key}
23
+ def set_#{key}(#{arg_s})
24
+ @mandrill_#{key} = v
25
+ end
26
+ private :set_#{key}
27
+ EOS
28
+ end
29
+ end
30
+ end
31
+
32
+ def get_mandrill_setting(key)
33
+ instance_variable_defined?("@mandrill_#{key}") ? instance_variable_get("@mandrill_#{key}") : __send__("mandrill_#{key}")
34
+ end
35
+ private :get_mandrill_setting
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Mandriller
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../lib/mandriller/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "mandriller"
5
+ gem.version = Mandriller::VERSION
6
+ gem.platform = Gem::Platform::RUBY
7
+ gem.authors = ["Daisuke Taniwaki"]
8
+ gem.email = ["daisuketaniwaki@gmail.com"]
9
+ gem.homepage = "https://github.com/dtaniwaki/mandriller"
10
+ gem.summary = "Mandrill SMTP API integration for ActionMailer"
11
+ gem.description = "Mandrill SMTP API integration for ActionMailer"
12
+ gem.license = "MIT"
13
+
14
+ gem.files = `git ls-files`.split("\n")
15
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ gem.require_paths = ['lib']
18
+
19
+ gem.add_dependency "actionmailer", ">= 3.0"
20
+
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "rspec", ">= 3.0"
23
+ gem.add_development_dependency "coveralls"
24
+ end
@@ -0,0 +1,266 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mandriller::Base do
4
+ let(:global_settings) { lambda{} }
5
+ let(:local_settings) { lambda{} }
6
+ let(:klass) do
7
+ gs = global_settings
8
+ ls = local_settings
9
+ Class.new(Mandriller::Base) do
10
+ self.mailer_name = 'foo_mailer'
11
+ instance_exec(&gs)
12
+ define_method :foo do
13
+ instance_exec(&ls)
14
+ mail from: 'from@example.com', to: ['to@example.com']
15
+ end
16
+ end
17
+ end
18
+ subject { klass.foo }
19
+
20
+ BOOLEAN_SETTINGS = {
21
+ autotext: 'X-MC-Autotext',
22
+ autohtml: 'X-MC-AutoHtml',
23
+ url_strip_qs: 'X-MC-URLStripQS',
24
+ preserve_recipients: 'X-MC-PreserveRecipients',
25
+ inline_css: 'X-MC-InlineCSS',
26
+ google_analytics_campaign: 'X-MC-GoogleAnalyticsCampaign',
27
+ view_content_link: 'X-MC-ViewContentLink',
28
+ import: 'X-MC-Important',
29
+ }
30
+ BOOLEAN_SETTINGS.each do |key, header|
31
+ describe "#{header} header" do
32
+ context "no set" do
33
+ it_behaves_like "without header", header
34
+ end
35
+ context "set by #set_#{key}" do
36
+ context "set default" do
37
+ let(:local_settings) { lambda{ __send__("set_#{key}") } }
38
+ it_behaves_like "with header", header, true
39
+ end
40
+ context "set true" do
41
+ let(:local_settings) { lambda{ __send__("set_#{key}", true) } }
42
+ it_behaves_like "with header", header, true
43
+ end
44
+ context "set false" do
45
+ let(:local_settings) { lambda{ __send__("set_#{key}", false) } }
46
+ it_behaves_like "with header", header, false
47
+ end
48
+ end
49
+ context "set by ::set_#{key}" do
50
+ context "set default" do
51
+ let(:global_settings) { lambda{ __send__("set_#{key}") } }
52
+ it_behaves_like "with header", header, true
53
+ end
54
+ context "set true" do
55
+ let(:global_settings) { lambda{ __send__("set_#{key}", true) } }
56
+ it_behaves_like "with header", header, true
57
+ end
58
+ context "set false" do
59
+ let(:global_settings) { lambda{ __send__("set_#{key}", false) } }
60
+ end
61
+ end
62
+ context "set by both #set_#{key} and ::set_#{key}" do
63
+ context "set true globally and set false locally" do
64
+ let(:global_settings) { lambda{ __send__("set_#{key}", true) } }
65
+ let(:local_settings) { lambda{ __send__("set_#{key}", false) } }
66
+ it_behaves_like "with header", header, false
67
+ end
68
+ context "set false globally and set true locally" do
69
+ let(:global_settings) { lambda{ __send__("set_#{key}", false) } }
70
+ let(:local_settings) { lambda{ __send__("set_#{key}", true) } }
71
+ it_behaves_like "with header", header, true
72
+ end
73
+ context "set value globally but set nil locally" do
74
+ let(:global_settings) { lambda{ __send__("set_#{key}", true) } }
75
+ let(:local_settings) { lambda{ __send__("set_#{key}", nil) } }
76
+ it_behaves_like "without header", header
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ STRING_SETTINGS = {
83
+ tracking_domain: 'X-MC-TrackingDomain',
84
+ signing_domain: 'X-MC-SigningDomain',
85
+ subaccount: 'X-MC-Subaccount',
86
+ bcc_address: 'X-MC-BccAddress',
87
+ ip_pool: 'X-MC-IpPool',
88
+ return_path_domain: 'X-MC-ReturnPathDomain',
89
+ }
90
+ STRING_SETTINGS.each do |key, header|
91
+ describe "#{header} header" do
92
+ context "no set" do
93
+ it_behaves_like "without header", header
94
+ end
95
+ context "set by #set_#{key}" do
96
+ let(:local_settings) { lambda{ __send__("set_#{key}", 'local-string') } }
97
+ it_behaves_like "with header", header, 'local-string'
98
+ end
99
+ context "set by ::set_#{key}" do
100
+ let(:global_settings) { lambda{ __send__("set_#{key}", 'global-string') } }
101
+ it_behaves_like "with header", header, 'global-string'
102
+ end
103
+ context "set by both #set_#{key} and ::set_#{key}" do
104
+ context "set value globally and set value locally" do
105
+ let(:global_settings) { lambda{ __send__("set_#{key}", 'global-string') } }
106
+ let(:local_settings) { lambda{ __send__("set_#{key}", 'local-string') } }
107
+ it_behaves_like "with header", header, 'local-string'
108
+ end
109
+ context "set value globally but set nil locally" do
110
+ let(:global_settings) { lambda{ __send__("set_#{key}", 'global-string') } }
111
+ let(:local_settings) { lambda{ __send__("set_#{key}", nil) } }
112
+ it_behaves_like "without header", header
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ JSON_SETTINGS = {
119
+ metadata: 'X-MC-Metadata',
120
+ merge_vars: 'X-MC-MergeVars',
121
+ }
122
+ JSON_SETTINGS.each do |key, header|
123
+ describe "#{header} header" do
124
+ context "no set" do
125
+ it_behaves_like "without header", header
126
+ end
127
+ context "set by #set_#{key}" do
128
+ let(:local_settings) { lambda{ __send__("set_#{key}", {local: 1}) } }
129
+ it_behaves_like "with header", header, '{"local":1}'
130
+ end
131
+ context "set by ::set_#{key}" do
132
+ let(:global_settings) { lambda{ __send__("set_#{key}", {global: 1}) } }
133
+ it_behaves_like "with header", header, '{"global":1}'
134
+ end
135
+ context "set by both #set_#{key} and ::set_#{key}" do
136
+ context "set value globally and set value locally" do
137
+ let(:global_settings) { lambda{ __send__("set_#{key}", {global: 1}) } }
138
+ let(:local_settings) { lambda{ __send__("set_#{key}", {local: 1}) } }
139
+ it_behaves_like "with header", header, '{"local":1}'
140
+ end
141
+ context "set value globally but set nil locally" do
142
+ let(:global_settings) { lambda{ __send__("set_#{key}", {global: 1}) } }
143
+ let(:local_settings) { lambda{ __send__("set_#{key}", nil) } }
144
+ it_behaves_like "without header", header
145
+ end
146
+ end
147
+ end
148
+ end
149
+
150
+ describe "X-MC-Track header" do
151
+ header = "X-MC-Track"
152
+ context "no set" do
153
+ it_behaves_like "without header", header
154
+ end
155
+ context "set by #set_open_track" do
156
+ let(:local_settings) { lambda{ set_open_track } }
157
+
158
+ it_behaves_like "with header", 'X-MC-Track', 'opens'
159
+ end
160
+ context "set by #set_open_track" do
161
+ let(:global_settings) { lambda{ set_open_track } }
162
+
163
+ it_behaves_like "with header", 'X-MC-Track', 'opens'
164
+ end
165
+ context "set by #set_open_track" do
166
+ let(:local_settings) { lambda{ set_click_track :clicks } }
167
+ it_behaves_like "with header", 'X-MC-Track', 'clicks'
168
+ context "invalid type" do
169
+ let(:local_settings) { lambda{ set_click_track :invalid } }
170
+ it_behaves_like "raise an exception", Mandriller::InvalidHeaderValue
171
+ end
172
+ end
173
+ context "set by ::set_open_track" do
174
+ let(:global_settings) { lambda{ set_click_track :clicks } }
175
+ it_behaves_like "with header", 'X-MC-Track', 'clicks'
176
+ end
177
+ context "set by both ::set_open_track and ::set_click_track" do
178
+ let(:global_settings) { lambda{ set_open_track; set_click_track :clicks } }
179
+ it_behaves_like "with header", 'X-MC-Track', 'opens,clicks'
180
+ end
181
+ end
182
+
183
+ describe "X-MC-Template header" do
184
+ key = "template"
185
+ header = "X-MC-Template"
186
+ context "no set" do
187
+ it_behaves_like "without header", header
188
+ end
189
+ context "set by #set_#{key}" do
190
+ let(:local_settings) { lambda{ __send__("set_#{key}", 'template1', 'block1') } }
191
+ it_behaves_like "with header", header, 'template1|block1'
192
+ end
193
+ context "set by ::set_#{key}" do
194
+ let(:global_settings) { lambda{ __send__("set_#{key}", 'template1', 'block1') } }
195
+ it_behaves_like "with header", header, 'template1|block1'
196
+ end
197
+ context "set by both #set_#{key} and ::set_#{key}" do
198
+ context "set value globally and set value locally" do
199
+ let(:global_settings) { lambda{ __send__("set_#{key}", 'template1', 'block1') } }
200
+ let(:local_settings) { lambda{ __send__("set_#{key}", 'template2', 'block2') } }
201
+ it_behaves_like "with header", header, 'tempalte2|block2'
202
+ end
203
+ context "set value globally but set nil locally" do
204
+ let(:global_settings) { lambda{ __send__("set_#{key}", 'template1', 'block1') } }
205
+ let(:local_settings) { lambda{ __send__("set_#{key}", nil) } }
206
+ it_behaves_like "without header", header
207
+ end
208
+ end
209
+ end
210
+
211
+ describe "X-MC-GoogleAnalytics header" do
212
+ key = "google_analytics"
213
+ header = "X-MC-GoogleAnalytics"
214
+ context "no set" do
215
+ it_behaves_like "without header", header
216
+ end
217
+ context "set by #set_#{key}" do
218
+ let(:local_settings) { lambda{ __send__("set_#{key}", 'domain1', 'domain2') } }
219
+ it_behaves_like "with header", header, 'domain1,domain2'
220
+ end
221
+ context "set by ::set_#{key}" do
222
+ let(:global_settings) { lambda{ __send__("set_#{key}", 'domain1', 'domain2') } }
223
+ it_behaves_like "with header", header, 'domain1,domain2'
224
+ end
225
+ context "set by both #set_#{key} and ::set_#{key}" do
226
+ context "set value globally and set value locally" do
227
+ let(:global_settings) { lambda{ __send__("set_#{key}", 'domain1', 'domain2') } }
228
+ let(:local_settings) { lambda{ __send__("set_#{key}", 'domain2', 'domain3') } }
229
+ it_behaves_like "with header", header, 'domain2,domain3'
230
+ end
231
+ context "set value globally but set nil locally" do
232
+ let(:global_settings) { lambda{ __send__("set_#{key}", 'domain1', 'domain2') } }
233
+ let(:local_settings) { lambda{ __send__("set_#{key}", nil) } }
234
+ it_behaves_like "without header", header
235
+ end
236
+ end
237
+ end
238
+
239
+ describe "X-MC-SendAt header" do
240
+ key = 'send_at'
241
+ header = "X-MC-SendAt"
242
+ context "no set" do
243
+ it_behaves_like "without header", header
244
+ end
245
+ context "set by #set_#{key}" do
246
+ let(:local_settings) { lambda{ __send__("set_#{key}", DateTime.new(2001, 1, 2, 3, 4, 5)) } }
247
+ it_behaves_like "with header", header, '2001-01-02 03:04:05'
248
+ end
249
+ context "set by ::set_#{key}" do
250
+ let(:global_settings) { lambda{ __send__("set_#{key}", DateTime.new(2001, 1, 2, 3, 4, 5)) } }
251
+ it_behaves_like "with header", header, '2001-01-02 03:04:05'
252
+ end
253
+ context "set by both #set_#{key} and ::set_#{key}" do
254
+ context "set value globally and set value locally" do
255
+ let(:global_settings) { lambda{ __send__("set_#{key}", DateTime.new(2001, 1, 2, 3, 4, 5)) } }
256
+ let(:local_settings) { lambda{ __send__("set_#{key}", DateTime.new(2001, 1, 2, 3, 4, 6)) } }
257
+ it_behaves_like "with header", header, '2001-01-02 03:04:06'
258
+ end
259
+ context "set value globally but set nil locally" do
260
+ let(:global_settings) { lambda{ __send__("set_#{key}", DateTime.new(2001, 1, 2, 3, 4, 5)) } }
261
+ let(:local_settings) { lambda{ __send__("set_#{key}", nil) } }
262
+ it_behaves_like "without header", header
263
+ end
264
+ end
265
+ end
266
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mandriller::SettingsMethods do
4
+ let(:klass) do
5
+ Class.new do
6
+ include Mandriller::SettingsMethods
7
+ end
8
+ end
9
+ subject do
10
+ klass.class_eval do
11
+ define_settings_methods :foo
12
+ end
13
+ klass
14
+ end
15
+
16
+ it "defines the methods" do
17
+ expect(subject.private_methods).to include(:set_foo)
18
+ expect(subject).to respond_to(:mandrill_foo)
19
+ expect(subject.private_instance_methods).to include(:set_foo)
20
+
21
+ instance = subject.new
22
+ expect(instance.instance_variable_defined?("@mandrill_foo")).to eq(false)
23
+ end
24
+ it "sets the instance variable" do
25
+ instance = subject.new
26
+ instance.send :set_foo, 'foo'
27
+ expect(instance.instance_variable_get("@mandrill_foo")).to eq('foo')
28
+ end
29
+ it "sets the class attribute" do
30
+ subject.send :set_foo, 'foo'
31
+ expect(subject.mandrill_foo).to eq('foo')
32
+ end
33
+
34
+ context "with default option" do
35
+ subject do
36
+ klass.class_eval do
37
+ define_settings_methods :foo, default: 'bar'
38
+ end
39
+ klass
40
+ end
41
+ it "sets the instance variable with default value" do
42
+ instance = subject.new
43
+ instance.send :set_foo
44
+ expect(instance.instance_variable_get("@mandrill_foo")).to eq('bar')
45
+ end
46
+ it "sets the class attribute with default value" do
47
+ subject.send :set_foo
48
+ expect(subject.mandrill_foo).to eq('bar')
49
+ end
50
+ end
51
+
52
+ describe "#get_mandrill_setting" do
53
+ it "returns class_attribute" do
54
+ subject.send :set_foo, 1
55
+ instance = subject.new
56
+ expect(instance.send(:get_mandrill_setting, :foo)).to eq(1)
57
+ end
58
+ it "returns instance_variable" do
59
+ instance = subject.new
60
+ instance.send :set_foo, 2
61
+ expect(instance.send(:get_mandrill_setting, :foo)).to eq(2)
62
+ end
63
+ it "returns instance_variable over class_attribute" do
64
+ subject.send :set_foo, 1
65
+ instance = subject.new
66
+ instance.send :set_foo, 2
67
+ expect(instance.send(:get_mandrill_setting, :foo)).to eq(2)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+
5
+ require 'mandriller'
6
+
7
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f }
8
+
9
+ RSpec.configure do |config|
10
+ config.before :suite do
11
+ ActionMailer::Base.delivery_method = :test
12
+ end
13
+ end
14
+
@@ -0,0 +1,27 @@
1
+ shared_examples "with header" do |header, value|
2
+ it "sets header #{header}" do
3
+ expect {
4
+ subject.deliver!
5
+ }.to change { ActionMailer::Base.deliveries.count }.by(1)
6
+ m = ActionMailer::Base.deliveries.last
7
+ expect(m.header.to_s).to match(/(\r\n)?#{header}: #{value}(\r\n)?/)
8
+ end
9
+ end
10
+ shared_examples "without header" do |header|
11
+ it "does not set header #{header}" do
12
+ expect {
13
+ subject.deliver!
14
+ }.to change { ActionMailer::Base.deliveries.count }.by(1)
15
+ m = ActionMailer::Base.deliveries.last
16
+ expect(m.header.to_s).not_to match(/(\r\n)?#{header}: [^\r]*(\r\n)?/)
17
+ end
18
+ end
19
+ shared_examples "raise an exception" do |exception|
20
+ it "raises #{exception}" do
21
+ expect {
22
+ expect {
23
+ subject.deliver!
24
+ }.to raise_error(exception)
25
+ }.to change { ActionMailer::Base.deliveries.count }.by(0)
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mandriller
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daisuke Taniwaki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionmailer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Mandrill SMTP API integration for ActionMailer
70
+ email:
71
+ - daisuketaniwaki@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - aaa
82
+ - coverage/.last_run.json
83
+ - coverage/.resultset.json
84
+ - gemfiles/actionmailer.3.0.x.gemfile
85
+ - gemfiles/actionmailer.3.1.x.gemfile
86
+ - gemfiles/actionmailer.3.2.x.gemfile
87
+ - gemfiles/actionmailer.4.0.x.gemfile
88
+ - gemfiles/actionmailer.4.1.x.gemfile
89
+ - gemfiles/gemfile
90
+ - lib/mandriller.rb
91
+ - lib/mandriller/base.rb
92
+ - lib/mandriller/errors.rb
93
+ - lib/mandriller/settings_methods.rb
94
+ - lib/mandriller/version.rb
95
+ - mandriller.gemspec
96
+ - spec/mandriller/base_spec.rb
97
+ - spec/mandriller/settings_methods_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/support/action_mailer.rb
100
+ homepage: https://github.com/dtaniwaki/mandriller
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.2.2
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Mandrill SMTP API integration for ActionMailer
124
+ test_files:
125
+ - spec/mandriller/base_spec.rb
126
+ - spec/mandriller/settings_methods_spec.rb
127
+ - spec/spec_helper.rb
128
+ - spec/support/action_mailer.rb