sparkpost_rails 1.4.0 → 1.5.5

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
- SHA1:
3
- metadata.gz: 1824c8a4ed0368d9063eadf820ff0e53b8469af7
4
- data.tar.gz: b7ba7d9806925dfcc2e6f859a484a85cd43e24f2
2
+ SHA256:
3
+ metadata.gz: fbc1ea8ef179754711a53da38a2d391a36c5415b44e6b0f0362e3767f04c4f0b
4
+ data.tar.gz: 15a7e2d9f0a9bc475620b3d07c8dfefb1e885106355e2134f099e2707c70efb3
5
5
  SHA512:
6
- metadata.gz: de4ea6d3e24d6414ec768867816d1ddb3f17a4dbe01994b05fa5ba43a3d53663ca315b5202c0d8d0b918c3d1b0f6b12b86738536f62049f12c2fcd813a0ca8e6
7
- data.tar.gz: c4431d3186b89221cc0f8270a04b7c698f31a1594d1de39bb8cf3068a2b4f6e999369b22c3244714fc28f2e51359f45d63adbb84a89a8638b73fe210efc3ef51
6
+ metadata.gz: 497d32ab3cc83ccaa0f098eb5b2f0d3f2b990f15f2942fc18da965e1442f26be5d7a495ebecf7f7d69f1cf0056c1d9ba47e431ae03a9efcd8d1d3af5ba149967
7
+ data.tar.gz: 5433af761e5ba2ad30e075b9ab188aedd58bc06213d84dc7c5b55efa17c7074eb1c16f101a221bfc7052cd8dd6df5ac1c8e118afe387f9bb11f17fd2ea407dcc
data/README.md CHANGED
@@ -4,90 +4,75 @@
4
4
  SparkPost Rails
5
5
  ===============
6
6
 
7
- This gem provides seamless integration of SparkPost with ActionMailer. It provides a delivery_method based upon the SparkPost API, and
8
- makes getting setup and sending email via SparkPost in a Rails app pretty painless.
7
+ This gem provides seamless integration of SparkPost with ActionMailer. It provides a `delivery_method` based upon the SparkPost API, and makes getting setup and sending email via SparkPost in a Rails app pretty painless.
9
8
 
10
9
  Getting Started
11
10
  ---------------
12
11
 
13
12
  Add the gem to your Gemfile
14
13
 
15
- ```
14
+ ```ruby
16
15
  gem 'sparkpost_rails'
17
16
  ```
18
17
 
19
18
  Then run the bundle command to install it.
20
19
 
21
- By default, the gem will look for your SparkPost API key in your environment, with the key 'SPARKPOST_API_KEY'. You can override this
22
- setting by identifying a different key in the initializer (`config/initializers/sparkpost_rails.rb`):
20
+ By default, the gem will look for your SparkPost API key in your environment, with the key `SPARKPOST_API_KEY`. You can override this setting by identifying a different key in the initializer (`config/initializers/sparkpost_rails.rb`):
23
21
 
24
- ```
22
+ ```ruby
25
23
  SparkPostRails.configure do |c|
26
24
  c.api_key = 'YOUR API KEY'
27
25
  end
28
26
  ```
27
+ Note that an initializer file is not required to use this gem. If an initializer is not provided, default values will be used. See ["Additional Configuration"](#additional-configuration) below for a list of all the default settings.
29
28
 
30
29
  In each environment configuration file from which you want to send emails via Sparkpost, (i.e. `config/environments/production.rb`) add
31
30
 
32
- ```
31
+ ```ruby
33
32
  config.action_mailer.delivery_method = :sparkpost
34
33
  ```
35
34
 
36
35
  Additional Configuration
37
36
  ------------------------
38
- You can establish values for a number of SparkPost settings in the initializer. These values will be used for every message sent
39
- from your application. You can override these settings on individual messages.
37
+ You can establish values for a number of SparkPost settings in the initializer. These values will be used for every message sent from your application. You can override these settings on individual messages.
40
38
 
41
- ```
39
+ ```ruby
42
40
  SparkPostRails.configure do |c|
43
- c.sandbox = true
44
- c.track_opens = true
45
- c.track_clicks = true
46
- c.return_path = 'BOUNCE-EMAIL@YOUR-DOMAIN.COM'
47
- c.campaign_id = 'YOUR-CAMPAIGN'
48
- c.transactional = true
49
- c.ip_pool = "MY-POOL"
50
- c.inline_css = true
51
- c.html_content_only = true
52
- c.subaccount = "123"
41
+ c.api_endpoint = "https://api.eu.sparkpost.com/api/" # default: "https://api.sparkpost.com/api/"
42
+ c.sandbox = true # default: false
43
+ c.track_opens = true # default: false
44
+ c.track_clicks = true # default: false
45
+ c.return_path = 'BOUNCE-EMAIL@YOUR-DOMAIN.COM' # default: nil
46
+ c.campaign_id = 'YOUR-CAMPAIGN' # default: nil
47
+ c.transactional = true # default: false
48
+ c.ip_pool = "MY-POOL" # default: nil
49
+ c.inline_css = true # default: false
50
+ c.html_content_only = true # default: false
51
+ c.subaccount = "123" # default: nil
53
52
  end
54
53
  ```
55
54
 
56
- The default values for these optional configuration settings are:
57
-
58
- ```
59
- sandbox = false
60
- track_opens = false
61
- track_clicks = false
62
- return_path = nil
63
- campaign_id = nil
64
- transactional = false
65
- ip_pool = nil
66
- inline_css = false
67
- html_content_only = false
68
- subaccount = nil
69
- ```
70
-
71
55
  Usage
72
56
  -----
73
- When calling the deliver! method on the mail object returned from your mailer, SparkPostRails provides the response data directly back
74
- from SparkPost as a hash.
57
+ When calling the `deliver!` method on the mail object returned from your mailer, `SparkPostRails` provides the response data directly back from SparkPost as a hash.
75
58
 
76
- ```
59
+ ```ruby
77
60
  result = MyMailer.welcome_message(user).deliver!
78
61
  ```
79
62
 
80
63
  Example:
81
64
 
82
- ```
83
- {"total_rejected_recipients"=>0, "total_accepted_recipients"=>1, "id"=>"00000000000000"}
65
+ ```ruby
66
+ {
67
+ "total_rejected_recipients" => 0,
68
+ "total_accepted_recipients" => 1,
69
+ "id" => "00000000000000"
70
+ }
84
71
  ```
85
72
 
86
- If the SparkPost API reponds with an error condition, SparkPostRails will raise a SparkPostRails::DeliveryException, which will include all the message
87
- data returned by the API.
73
+ If the SparkPost API responds with an error condition, SparkPostRails will raise a `SparkPostRails::DeliveryException`, which will include all the message data returned by the API.
88
74
 
89
- SparkPostRails will support multiple recipients, multilple CC, multiple BCC, ReplyTo address, file attachments, inline images, multi-part (HTML and plaintext) messages -
90
- all utilizing the standard ActionMailer methodologies.
75
+ SparkPostRails will support multiple recipients, multiple CC, multiple BCC, ReplyTo address, file attachments, inline images, multi-part (HTML and plaintext) messages - all utilizing the standard `ActionMailer` methodologies.
91
76
 
92
77
  Handling Errors
93
78
  ---------------
@@ -95,79 +80,78 @@ If you are using `ActiveJob` and wish to do something special when the SparkPost
95
80
 
96
81
  `config/initializers/action_mailer.rb`
97
82
 
98
- ```
83
+ ```ruby
99
84
  ActionMailer::DeliveryJob.rescue_from(SparkPostRails::DeliveryException) do |exception|
100
85
  # do something special with the error
86
+ # do something special with the error
101
87
  end
102
88
  ```
103
89
 
104
- SparkPost Specific Features
90
+ SparkPost-Specific Features
105
91
  ---------------------------
106
92
 
107
93
  ### Configuration Settings
108
- You can specifiy values for any or all of the configuration settings listed above on an individual message. Simply add a hash of these values
109
- to the mail message in a field named "sparkpost_data":
110
-
111
- ```
112
- data = { track_opens: true,
113
- track_clicks: false,
114
- campaign_id: "My Campaign",
115
- transactional: true,
116
- ip_pool = "SPECIAL_POOL",
117
- api_key = "MESSAGE_SPECIFIC_API_KEY"
118
- subaccount = "123"
119
- }
94
+ You can specify values for any or all of the configuration settings listed above on an individual message. Simply add a hash of these values to the mail message in a field named `sparkpost_data`:
95
+
96
+ ```ruby
97
+ data = {
98
+ track_opens: true,
99
+ track_clicks: false,
100
+ campaign_id: 'My Campaign',
101
+ transactional: true,
102
+ ip_pool: 'SPECIAL_POOL',
103
+ api_key: 'MESSAGE_SPECIFIC_API_KEY',
104
+ subaccount: '123'
105
+ }
120
106
 
121
107
  mail(to: to_email, subject: "Test", body: "test", sparkpost_data: data)
122
108
  ```
123
109
 
124
- Additionally, return_path can be overriden on a specific email by setting that field on the mail message itself:
110
+ Additionally, `return_path` can be overridden on a specific email by setting that field on the mail message itself:
125
111
 
126
- ```
112
+ ```ruby
127
113
  mail(to: to_email, subject: "Test", body: "test", return_path: "bounces@example.com")
128
114
  ```
129
115
 
130
116
  ### Transmission Specific Settings
131
117
 
132
- For an individual transmisison you can specifiy that SparkPost should ignore customer supression rules - if your SparkPost account allows for this
133
- feature. Simply include the flag in the "sparkpost_data" field on the message:
118
+ For an individual transmisison you can specifiy that SparkPost should ignore customer supression rules - if your SparkPost account allows for this feature. Simply include the flag in the `sparkpost_data` field on the message:
134
119
 
135
- ```
120
+ ```ruby
136
121
  data = { skip_suppression: true }
137
122
 
138
123
  mail(to: to_email, subject: "Test", body: "test", sparkpost_data: data)
139
124
  ```
140
125
 
141
- To schedule the generation of messages for a future date and time, specify a start time in the date parameter of the mail. Date must be in the future and less than 1 year from today. If date is in the past or too far in the future, no date will be passed, and no delivery schedule will be set.
126
+ To schedule the generation of messages for a future date and time, specify a start time in the `date` parameter of the mail. The `date` must be in the future and less than 1 year from today. If `date` is in the past or too far in the future, no date will be passed, and no delivery schedule will be set.
142
127
 
143
- ```
144
- start_time = DateTime.now + 4.hours
128
+ ```ruby
129
+ start_time = DateTime.now + 4.hours
145
130
 
146
131
  mail(to: to_email, subject: "Test", body: "test", date: start_time)
147
132
  ```
148
133
 
149
- You can set a description for a transmission via the "sparkpost_data" as well. The maximum length of the decription is 1024 characters - values
150
- longer than the maxium will be truncated.
134
+ You can set a `description` for a transmission via the `sparkpost_data` as well. The maximum length of the `decription` is 1024 characters - values longer than the maxium will be truncated.
151
135
 
152
- ```
136
+ ```ruby
153
137
  data = { description: "My Important Message" }
154
138
 
155
139
  mail(to: to_email, subject: "Test", body: "test", sparkpost_data: data)
156
140
  ```
157
141
 
158
- By default, content from single-part messages is sent at plain-text. If you are only intending to send HTML email, with no plain-text part, you can specify this
159
- as shown below. You can also set this in the configuration to ensure that all single-part emails are sent as html.
142
+ By default, content from single-part messages is sent at plain-text. If you are only intending to send HTML email, with no plain-text part, you can specify this as shown below. You can also set this in the configuration to ensure that all single-part emails are sent as HTML.
160
143
 
161
- ```
144
+ ```ruby
162
145
  data = { html_content_only: true }
163
146
 
164
147
  mail(to: to_email, subject: "Test", body: "<h1>test</h1>", sparkpost_data: data)
165
148
  ```
166
149
 
167
150
  ### Subaccounts
151
+
168
152
  SparkPostRails supports sending messages via subaccounts in two ways. The default API key set in the configuration can be overriden on a message-by-message basis with a subaccount API key.
169
153
 
170
- ```
154
+ ```ruby
171
155
  data = { api_key: "SUBACCOUNT_API_KEY" }
172
156
 
173
157
  mail(subject: "Test", body: "test", sparkpost_data: data)
@@ -175,42 +159,42 @@ mail(subject: "Test", body: "test", sparkpost_data: data)
175
159
 
176
160
  Subaccounts can also be leveraged using the subaccount ID with the master API key.
177
161
 
178
- ```
162
+ ```ruby
179
163
  data = { subaccount: "123" }
180
164
 
181
165
  mail(subject: "Test", body: "test", sparkpost_data: data)
182
166
  ```
183
167
 
184
168
  ### Recipient Lists
185
- SparkPostRails supports using SparkPost stored recipient lists. Simply add the list_id to the sparkpost_data hash on the mail message:
169
+ SparkPostRails supports using SparkPost stored recipient lists. Simply add the `list_id` to the `sparkpost_data` hash on the mail message:
186
170
 
187
- ```
188
- data = { list_id: "MY-LIST"}
171
+ ```ruby
172
+ data = { recipient_list_id: "MY-LIST"}
189
173
 
190
174
  mail(subject: "Test", body: "test", sparkpost_data: data)
191
175
  ```
192
176
 
193
- **NOTE**: If you supply a recipient list id, all To:, CC:, and BCC: data specified on the mail message will be ignored. The SparkPost API does
194
- not support utilizing both a recipient list and inline recipients.
177
+ **NOTE**: If you supply a recipient `list_id`, all `To:`, `CC:`, and `BCC:` data specified on the mail message will be ignored. The SparkPost API does not support utilizing both a recipient list and inline recipients.
195
178
 
196
179
 
197
180
  ### Substitution Data
198
- You can leverage SparkPost's substitution engine through the gem as well. To supply substitution data, simply add your hash of substitution data
199
- to your sparkpost_data hash, with the key :substitution_data.
181
+ You can leverage SparkPost's substitution engine through the gem as well. To supply substitution data, simply add your hash of substitution data to your `sparkpost_data` hash, with the key `substitution_data`.
200
182
 
201
- ```
202
- sub_data = {first_name: "Sam",
203
- last_name: "Test}
183
+ ```ruby
184
+ sub_data = {
185
+ first_name: "Sam",
186
+ last_name: "Test
187
+ }
204
188
 
205
189
  data = { substitution_data: sub_data }
206
190
 
207
191
  mail(to: to_email, subject: "Test", body: "test", sparkpost_data: data)
208
192
  ```
209
193
 
210
- ### Recipient-specific Data
211
- When sending to multiple recipients, you can pass an array of data to complement each recipient. Simply pass an array called recipients containing an array of the additional data (e.g. substitution_data).
194
+ ### Recipient-Specific Data
195
+ When sending to multiple recipients, you can pass an array of data to complement each recipient. Simply pass an array called `recipients` containing an array of the additional data (e.g. `substitution_data`).
212
196
 
213
- ```
197
+ ```ruby
214
198
  recipients = ['recipient1@email.com', 'recipient2@email.com']
215
199
  sparkpost_data = {
216
200
  recipients: [
@@ -223,10 +207,9 @@ mail(to: recipients, sparkpost_data: sparkpost_data)
223
207
 
224
208
 
225
209
  ### Using SparkPost Templates
226
- If you would rather leverage SparkPost's powerful templates rather than building ActionMailer views, SparkPostRails can support that as well. Simply
227
- add your template id to the sparkpost_data hash. By default, ActionMailer finds a template to use within views, a workaround to prevent this default action is to explicitly pass a block with an empty text part:
210
+ You can leverage SparkPost's powerful templates rather than building ActionMailer views using SparkPostRails. Add your `template_id` to the `sparkpost_data` hash. By default, `ActionMailer` finds a template to use within views. A workaround to prevent this default action is to explicitly pass a block with an empty `text` part:
228
211
 
229
- ```
212
+ ```ruby
230
213
  data = { template_id: "MY-TEMPLATE" }
231
214
 
232
215
  mail(to: to_email, sparkpost_data: data) do |format|
@@ -234,15 +217,14 @@ mail(to: to_email, sparkpost_data: data) do |format|
234
217
  end
235
218
  ```
236
219
 
237
- **NOTE**: All inline-content that may exist in your mail message will be ignored, as the SparkPost API does not accept that data when a template id is
238
- supplied. This includes Subject, From, ReplyTo, Attachments, and Inline Images.
220
+ **NOTE**: All inline-content that may exist in your mail message will be ignored, as the SparkPost API does not accept that data when a template id is supplied. This includes `Subject`, `From`, `ReplyTo`, Attachments, and Inline Images.
239
221
 
240
222
  ###Other Mail Headers
241
- If you need to identify custom mail headers for your messages, utilize the ActionMailer header[] method. The gem will pass all approprite headers through
242
- to the api. Note, per the SparkPost API documentation, "Headers such as 'Content-Type' and 'Content-Transfer-Encoding' are not allowed here as they are auto
243
- generated upon construction of the email."
223
+ If you need to identify custom mail headers for your messages, use the `ActionMailer` `header[]` method. The gem will pass all appropriate headers through to the API. Note, per the SparkPost API documentation
244
224
 
245
- ```
225
+ > Headers such as 'Content-Type' and 'Content-Transfer-Encoding' are not allowed here as they are auto-generated upon construction of the email.
226
+
227
+ ```ruby
246
228
  headers["Priority"] = "urgent"
247
229
  headers["Sensitivity"] = "private"
248
230
 
@@ -1,3 +1,4 @@
1
+ require "sparkpost_rails/data_options"
1
2
  require "sparkpost_rails/delivery_method"
2
3
  require "sparkpost_rails/exceptions"
3
4
  require "sparkpost_rails/railtie"
@@ -7,6 +8,10 @@ module SparkPostRails
7
8
  attr_accessor :configuration
8
9
  end
9
10
 
11
+ def self.configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
10
15
  def self.configure
11
16
  self.configuration ||= Configuration.new
12
17
  yield(configuration)
@@ -14,6 +19,7 @@ module SparkPostRails
14
19
 
15
20
  class Configuration
16
21
  attr_accessor :api_key
22
+ attr_accessor :api_endpoint
17
23
  attr_accessor :sandbox
18
24
 
19
25
  attr_accessor :track_opens
@@ -40,6 +46,8 @@ module SparkPostRails
40
46
  @api_key = ""
41
47
  end
42
48
 
49
+ @api_endpoint = "https://api.sparkpost.com/api/"
50
+
43
51
  @sandbox = false
44
52
 
45
53
  @track_opens = false
@@ -0,0 +1,25 @@
1
+ module SparkPostRails
2
+ module DataOptions
3
+
4
+ def self.included(base)
5
+ base.class_eval do
6
+ prepend InstanceMethods
7
+ end
8
+ end
9
+
10
+ module InstanceMethods
11
+
12
+ def mail(headers={}, &block)
13
+ headers = headers.clone
14
+ sparkpost_data = headers.delete(:sparkpost_data)
15
+ sparkpost_data ||= {}
16
+ super(headers, &block).tap do |message|
17
+ message.singleton_class.class_eval { attr_accessor "sparkpost_data" }
18
+ message.sparkpost_data = sparkpost_data
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
@@ -29,6 +29,7 @@ module SparkPostRails
29
29
  end
30
30
 
31
31
  prepare_substitution_data_from sparkpost_data
32
+ prepare_metadata_from sparkpost_data
32
33
  prepare_description_from sparkpost_data
33
34
  prepare_options_from mail, sparkpost_data
34
35
  prepare_additional_mail_headers_from mail
@@ -42,11 +43,7 @@ module SparkPostRails
42
43
 
43
44
  private
44
45
  def find_sparkpost_data_from mail
45
- if mail[:sparkpost_data]
46
- eval(mail[:sparkpost_data].value)
47
- else
48
- Hash.new
49
- end
46
+ mail.sparkpost_data
50
47
  end
51
48
 
52
49
  def prepare_recipients_from mail, sparkpost_data
@@ -68,14 +65,15 @@ module SparkPostRails
68
65
 
69
66
  def prepare_addresses emails, names
70
67
  emails = [emails] unless emails.is_a?(Array)
71
- emails.each_with_index.map {|email, index| prepare_address(email, index, names) }
68
+ header_to = emails.join(",")
69
+ emails.each_with_index.map {|email, index| prepare_address(email, index, names, header_to) }
72
70
  end
73
71
 
74
- def prepare_address email, index, names
72
+ def prepare_address email, index, names, header_to
75
73
  if !names[index].nil?
76
- { address: { email: email, name: names[index] } }
74
+ { address: { email: email, name: names[index], header_to: header_to } }
77
75
  else
78
- { address: { email: email } }
76
+ { address: { email: email, header_to: header_to } }
79
77
  end
80
78
  end
81
79
 
@@ -118,6 +116,12 @@ module SparkPostRails
118
116
  end
119
117
  end
120
118
 
119
+ def prepare_metadata_from sparkpost_data
120
+ if sparkpost_data[:metadata]
121
+ @data[:metadata] = sparkpost_data[:metadata]
122
+ end
123
+ end
124
+
121
125
  def prepare_from_address_from mail
122
126
  if !mail[:from].display_names.first.nil?
123
127
  from = { email: mail.from.first, name: mail[:from].display_names.first }
@@ -147,7 +151,7 @@ module SparkPostRails
147
151
  emails << copy[:address][:email]
148
152
  end
149
153
 
150
- @data[:content][:headers] = { cc: emails }
154
+ @data[:content][:headers] = { cc: emails.join(",") }
151
155
  end
152
156
  end
153
157
 
@@ -178,9 +182,9 @@ module SparkPostRails
178
182
  inline_images = Array.new
179
183
 
180
184
  mail.attachments.each do |attachment|
181
- #We decode and reencode here to ensure that attachments are
185
+ #We decode and reencode here to ensure that attachments are
182
186
  #Base64 encoded without line breaks as required by the API.
183
- attachment_data = { name: attachment.inline? ? attachment.url : attachment.filename,
187
+ attachment_data = { name: attachment.inline? ? attachment.cid : attachment.filename,
184
188
  type: attachment.content_type,
185
189
  data: Base64.strict_encode64(attachment.body.decoded) }
186
190
 
@@ -373,15 +377,13 @@ module SparkPostRails
373
377
  end
374
378
 
375
379
  def post_to_api
376
- url = "https://api.sparkpost.com/api/v1/transmissions"
380
+ uri = URI.join(SparkPostRails.configuration.api_endpoint, 'v1/transmissions')
377
381
 
378
- uri = URI.parse(url)
379
382
  http = Net::HTTP.new(uri.host, uri.port)
380
383
  http.use_ssl = true
381
384
 
382
385
  request = Net::HTTP::Post.new(uri.path, @headers)
383
386
  request.body = JSON.generate(@data)
384
-
385
387
  http.request(request)
386
388
  end
387
389
 
@@ -5,5 +5,11 @@ module SparkPostRails
5
5
  ActionMailer::Base.add_delivery_method :sparkpost, SparkPostRails::DeliveryMethod, return_response: true
6
6
  end
7
7
  end
8
+
9
+ initializer "sparkpost_rails.extend_with_data_options" do
10
+ ActiveSupport.on_load :action_mailer do
11
+ ActionMailer::Base.send :include, SparkPostRails::DataOptions
12
+ end
13
+ end
8
14
  end
9
15
  end
@@ -1,4 +1,4 @@
1
1
  module SparkPostRails
2
- VERSION = "1.4.0"
2
+ VERSION = "1.5.5"
3
3
  end
4
4
 
@@ -48,7 +48,7 @@ describe SparkPostRails::DeliveryMethod do
48
48
  expect(images.length).to eq(1)
49
49
  image = images[0]
50
50
  expect(image).to include(:name, :type=>"image/png; filename=image_0.png", :data=>"iVBORw0KGgoAAAANSUhEUgAAAfIAAACCCAMAAACKGrqXAAAAY1BMVEX////6ZCNVVVr6ZCP6ZCNVVVr6ZCNVVVr6ZCP6ZCNVVVpVVVr6ZCNVVVpVVVr6ZCNVVVpVVVr6ZCNVVVpVVVpVVVpVVVr6ZCP6ZCNVVVr6ZCP6ZCP6ZCP6ZCNVVVpVVVr6ZCO+CfRXAAAAH3RSTlMAgMBAEPBgoDAg4NBwkIDAUBDwQLBgMOCgIFCQ0LBwPgQxPgAADDFJREFUeF7s2kGLnEAYhOFqbERhSROHZFzXWer//8rAJo172jklhK73OXsrKItP9Q/hmBQGZ1EWLD6roqB4W5QEdbN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TT4ocMyCY6ViBgxxNe08gh5cCtx2Qq35i4/N542MfX6gxil96ZpDWEchFnpUxLjjj8ehbjBwjOu6Sb1nI0bSPPOS4v+O0yOsFgi7v1SPTK1R3LAPf8bZi+n3IZ6kbLUeO2Yy84TdzkKOZ8pGHHAsOBhXyok+yPtDTeV1f5NFd7iKn8FgSIkcctGYxcgQZ2eF7t7PCds9EHjtw2+vI9b98ef043Tl4rz+gGlQx6xYrAaMcdLtklltZZU458og3E5h+xUhwI0w72RRduKRBXnS6/A26nD+O/9b58jfqhC/VRyoHfeQhRyXPTzgRIUcg0nx6x0KOpt1GHnJ04WxUIS/MxfVbi3K3KmUP6sGYSYM0JzHrcuReUovGQpxGI0fTPjGR44ZBFzXIi17kxBGIr0LPBt6UQo4aPJu4HPkguuvZoz9FI0d0AxM5xitOhbzo6SInjhdJLORaJQdjk4kcK/kTssNhH/IJDCffu7cUN9q0Y1PChQsK5Lie07qc2pbXTmEY4xfIufdgjZrINdBNPuxDnhuhL81u5iJH0y5cE4oGFfKi5zOH+I+NRIpkqJ+50Sc1x7mjU5rkyHtyI5suEYjcaNO+sO8po5eqRE5XZmelPo+O/J00fVZMCh2R0iRGHi1EeYQ8jBHkxjHtmYkcN6N81CEvOhET/do+SolLR/4AoD4RKg7hfp/Vbl1qnsOdGj5ZDvfivMRQaTGGexFPKi2ZTZeATe8a54NCL9fGKn7k8Hi4ytu5GXBsdkbe86vDB63+6Pl42QLOz3tKXzjyHwC/TfqZfgXg/yj90dPb6kD1/Q+Af77e/0v98vny/zLB/+j0+vl5PP1uAP8CV/GqdTJ4tWwAAAAASUVORK5CYII=")
51
- expect(image[:name]).to match(/cid:.*@.*/)
51
+ expect(image[:name]).to match(/.*@.*/)
52
52
  end
53
53
 
54
54
  end
@@ -13,7 +13,8 @@ describe SparkPostRails::DeliveryMethod do
13
13
  test_email = Mailer.test_email bcc: "bcc@example.com"
14
14
  @delivery_method.deliver!(test_email)
15
15
 
16
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to@example.com"}}, {address: {email: "bcc@example.com", header_to: "to@example.com"}}])
16
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to@example.com", header_to: anything}}),
17
+ {address: {email: "bcc@example.com", header_to: "to@example.com"}}])
17
18
  expect(@delivery_method.data[:content]).not_to include(:headers)
18
19
  end
19
20
 
@@ -21,7 +22,9 @@ describe SparkPostRails::DeliveryMethod do
21
22
  test_email = Mailer.test_email to: "Joe Test <to1@example.com>, Sam Test <to2@example.com>", bcc: "Brock Test <bcc@example.com>"
22
23
  @delivery_method.deliver!(test_email)
23
24
 
24
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to1@example.com", name: "Joe Test"}}, {address: {email: "to2@example.com", name: "Sam Test"}}, {address: {email: "bcc@example.com", name: "Brock Test", header_to: "to1@example.com"}}])
25
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to1@example.com", name: "Joe Test", header_to: anything}}),
26
+ a_hash_including({address: {email: "to2@example.com", name: "Sam Test", header_to: anything}}),
27
+ {address: {email: "bcc@example.com", name: "Brock Test", header_to: "to1@example.com"}}])
25
28
  expect(@delivery_method.data[:content]).not_to include(:headers)
26
29
  end
27
30
  end
@@ -31,7 +34,10 @@ describe SparkPostRails::DeliveryMethod do
31
34
  test_email = Mailer.test_email bcc: "bcc1@example.com, bcc2@example.com"
32
35
  @delivery_method.deliver!(test_email)
33
36
 
34
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to@example.com"}}, {address: {email: "bcc1@example.com", header_to: "to@example.com"}}, {address: {email: "bcc2@example.com", header_to: "to@example.com"}}])
37
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to@example.com", header_to: anything}}),
38
+ {address: {email: "bcc1@example.com", header_to: "to@example.com"}},
39
+ {address: {email: "bcc2@example.com", header_to: "to@example.com"}}])
40
+
35
41
  expect(@delivery_method.data[:content]).not_to include(:headers)
36
42
  end
37
43
 
@@ -39,7 +45,9 @@ describe SparkPostRails::DeliveryMethod do
39
45
  test_email = Mailer.test_email to: "Joe Test <to@example.com>", bcc: "Brock Test <bcc1@example.com>, Brack Test <bcc2@example.com>"
40
46
  @delivery_method.deliver!(test_email)
41
47
 
42
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to@example.com", name: "Joe Test"}}, {address: {email: "bcc1@example.com", name: "Brock Test", header_to: "to@example.com"}}, {address: {email: "bcc2@example.com", name: "Brack Test", header_to: "to@example.com"}}])
48
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to@example.com", name: "Joe Test", header_to: anything}}),
49
+ {address: {email: "bcc1@example.com", name: "Brock Test", header_to: "to@example.com"}},
50
+ {address: {email: "bcc2@example.com", name: "Brack Test", header_to: "to@example.com"}}])
43
51
  expect(@delivery_method.data[:content]).not_to include(:headers)
44
52
  end
45
53
 
@@ -47,7 +55,9 @@ describe SparkPostRails::DeliveryMethod do
47
55
  test_email = Mailer.test_email to: "Joe Test <to@example.com>", bcc: "Brock Test <bcc1@example.com>, bcc2@example.com"
48
56
  @delivery_method.deliver!(test_email)
49
57
 
50
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to@example.com", name: "Joe Test"}}, {address: {email: "bcc1@example.com", name: "Brock Test", header_to: "to@example.com"}}, {address: {email: "bcc2@example.com", header_to: "to@example.com"}}])
58
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to@example.com", name: "Joe Test", header_to: anything}}),
59
+ {address: {email: "bcc1@example.com", name: "Brock Test", header_to: "to@example.com"}},
60
+ {address: {email: "bcc2@example.com", header_to: "to@example.com"}}])
51
61
  expect(@delivery_method.data[:content]).not_to include(:headers)
52
62
  end
53
63
  end
@@ -57,24 +67,35 @@ describe SparkPostRails::DeliveryMethod do
57
67
  test_email = Mailer.test_email to: "to1@example.com, to2@example.com", cc: "cc@example.com", bcc: "bcc@example.com"
58
68
  @delivery_method.deliver!(test_email)
59
69
 
60
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to1@example.com"}}, {address: {email: "to2@example.com"}}, {address: {email: "cc@example.com", header_to: "to1@example.com"}}, {address: {email: "bcc@example.com", header_to: "to1@example.com"}}])
61
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc@example.com"]})
70
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to1@example.com", header_to: anything}}),
71
+ a_hash_including({address: {email: "to2@example.com", header_to: anything}}),
72
+ {address: {email: "cc@example.com", header_to: "to1@example.com"}},
73
+ {address: {email: "bcc@example.com", header_to: "to1@example.com"}}])
74
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc@example.com"})
62
75
  end
63
76
 
64
77
  it "handles name and email" do
65
78
  test_email = Mailer.test_email to: "Joe Test <to1@example.com>, Sam Test <to2@example.com>", cc: "Carl Test <cc@example.com>", bcc: "Brock Test <bcc@example.com>"
66
79
  @delivery_method.deliver!(test_email)
67
80
 
68
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to1@example.com", name: "Joe Test"}}, {address: {email: "to2@example.com", name: "Sam Test"}}, {address: {email: "cc@example.com", name: "Carl Test", header_to: "to1@example.com"}}, {address: {email: "bcc@example.com", name: "Brock Test", header_to: "to1@example.com"}}])
69
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc@example.com"]})
81
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to1@example.com", name: "Joe Test", header_to: anything}}),
82
+ a_hash_including({address: {email: "to2@example.com", name: "Sam Test", header_to: anything}}),
83
+ {address: {email: "cc@example.com", name: "Carl Test", header_to: "to1@example.com"}},
84
+ {address: {email: "bcc@example.com", name: "Brock Test", header_to: "to1@example.com"}}])
85
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc@example.com"})
70
86
  end
71
87
 
72
88
  it "handles mix of email only and name/email" do
73
89
  test_email = Mailer.test_email to: "Joe Test <to1@example.com>, to2@example.com", cc: "cc1@example.com, Chris Test <cc2@example.com>", bcc: "Brock Test <bcc1@example.com>, bcc2@example.com"
74
90
  @delivery_method.deliver!(test_email)
75
91
 
76
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to1@example.com", name: "Joe Test"}}, {address: {email: "to2@example.com"}}, {address: {email: "cc1@example.com", header_to: "to1@example.com"}}, {address: {email: "cc2@example.com", name: "Chris Test", header_to: "to1@example.com"}}, {address: {email: "bcc1@example.com", name: "Brock Test", header_to: "to1@example.com"}}, {address: {email: "bcc2@example.com", header_to: "to1@example.com"}}])
77
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc1@example.com", "cc2@example.com"]})
92
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to1@example.com", name: "Joe Test", header_to: anything}}),
93
+ a_hash_including({address: {email: "to2@example.com", header_to: anything}}),
94
+ {address: {email: "cc1@example.com", header_to: "to1@example.com"}},
95
+ {address: {email: "cc2@example.com", name: "Chris Test", header_to: "to1@example.com"}},
96
+ {address: {email: "bcc1@example.com", name: "Brock Test", header_to: "to1@example.com"}},
97
+ {address: {email: "bcc2@example.com", header_to: "to1@example.com"}}])
98
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc1@example.com,cc2@example.com"})
78
99
  end
79
100
  end
80
101
  end
@@ -12,16 +12,18 @@ describe SparkPostRails::DeliveryMethod do
12
12
  test_email = Mailer.test_email cc: "cc@example.com"
13
13
  @delivery_method.deliver!(test_email)
14
14
 
15
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to@example.com"}}, {address: {email: "cc@example.com", header_to: "to@example.com"}}])
16
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc@example.com"]})
15
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to@example.com", header_to: anything}}),
16
+ {address: {email: "cc@example.com", header_to: "to@example.com"}}])
17
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc@example.com"})
17
18
  end
18
19
 
19
20
  it "handles name and email" do
20
21
  test_email = Mailer.test_email to: "Joe Test <to@example.com>", cc: "Carl Test <cc@example.com>"
21
22
  @delivery_method.deliver!(test_email)
22
23
 
23
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to@example.com", name: "Joe Test"}}, {address: {email: "cc@example.com", name: "Carl Test", header_to: "to@example.com"}}])
24
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc@example.com"]})
24
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to@example.com", name: "Joe Test", header_to: anything}}),
25
+ {address: {email: "cc@example.com", name: "Carl Test", header_to: "to@example.com"}}])
26
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc@example.com"})
25
27
  end
26
28
  end
27
29
 
@@ -30,24 +32,30 @@ describe SparkPostRails::DeliveryMethod do
30
32
  test_email = Mailer.test_email cc: "cc1@example.com, cc2@example.com"
31
33
  @delivery_method.deliver!(test_email)
32
34
 
33
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to@example.com"}}, {address: {email: "cc1@example.com", header_to: "to@example.com"}}, {address: {email: "cc2@example.com", header_to: "to@example.com"}}])
34
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc1@example.com", "cc2@example.com"]})
35
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to@example.com", header_to: anything}}),
36
+ {address: {email: "cc1@example.com", header_to: "to@example.com"}},
37
+ {address: {email: "cc2@example.com", header_to: "to@example.com"}}])
38
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc1@example.com,cc2@example.com"})
35
39
  end
36
40
 
37
41
  it "handles name and email" do
38
42
  test_email = Mailer.test_email to: "Joe Test <to@example.com>", cc: "Carl Test <cc1@example.com>, Chris Test <cc2@example.com>"
39
43
  @delivery_method.deliver!(test_email)
40
44
 
41
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to@example.com", name: "Joe Test"}}, {address: {email: "cc1@example.com", name: "Carl Test", header_to: "to@example.com"}}, {address: {email: "cc2@example.com", name: "Chris Test", header_to: "to@example.com"}}])
42
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc1@example.com", "cc2@example.com"]})
45
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to@example.com", name: "Joe Test", header_to: anything}}),
46
+ {address: {email: "cc1@example.com", name: "Carl Test", header_to: "to@example.com"}},
47
+ {address: {email: "cc2@example.com", name: "Chris Test", header_to: "to@example.com"}}])
48
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc1@example.com,cc2@example.com"})
43
49
  end
44
50
 
45
51
  it "handles mix of email only and name/email" do
46
52
  test_email = Mailer.test_email to: "Joe Test <to@example.com>", cc: "Carl Test <cc1@example.com>, cc2@example.com"
47
53
  @delivery_method.deliver!(test_email)
48
54
 
49
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to@example.com", name: "Joe Test"}}, {address: {email: "cc1@example.com", name: "Carl Test", header_to: "to@example.com"}}, {address: {email: "cc2@example.com", header_to: "to@example.com"}}])
50
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc1@example.com", "cc2@example.com"]})
55
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to@example.com", name: "Joe Test", header_to: anything}}),
56
+ {address: {email: "cc1@example.com", name: "Carl Test", header_to: "to@example.com"}},
57
+ {address: {email: "cc2@example.com", header_to: "to@example.com"}}])
58
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc1@example.com,cc2@example.com"})
51
59
  end
52
60
  end
53
61
 
@@ -56,16 +64,20 @@ describe SparkPostRails::DeliveryMethod do
56
64
  test_email = Mailer.test_email to: "to1@example.com, to2@example.com", cc: "cc@example.com"
57
65
  @delivery_method.deliver!(test_email)
58
66
 
59
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to1@example.com"}}, {address: {email: "to2@example.com"}}, {address: {email: "cc@example.com", header_to: "to1@example.com"}}])
60
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc@example.com"]})
67
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to1@example.com", header_to: anything}}),
68
+ a_hash_including({address: {email: "to2@example.com", header_to: anything}}),
69
+ {address: {email: "cc@example.com", header_to: "to1@example.com"}}])
70
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc@example.com"})
61
71
  end
62
72
 
63
73
  it "handles name and email" do
64
74
  test_email = Mailer.test_email to: "Joe Test <to1@example.com>, Sam Test <to2@example.com>", cc: "Carl Test <cc@example.com>"
65
75
  @delivery_method.deliver!(test_email)
66
76
 
67
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to1@example.com", name: "Joe Test"}}, {address: {email: "to2@example.com", name: "Sam Test"}}, {address: {email: "cc@example.com", name: "Carl Test", header_to: "to1@example.com"}}])
68
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc@example.com"]})
77
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to1@example.com", name: "Joe Test", header_to: anything}}),
78
+ a_hash_including({address: {email: "to2@example.com", name: "Sam Test", header_to: anything}}),
79
+ {address: {email: "cc@example.com", name: "Carl Test", header_to: "to1@example.com"}}])
80
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc@example.com"})
69
81
  end
70
82
  end
71
83
 
@@ -74,24 +86,33 @@ describe SparkPostRails::DeliveryMethod do
74
86
  test_email = Mailer.test_email to: "to1@example.com, to2@example.com", cc: "cc1@example.com, cc2@example.com"
75
87
  @delivery_method.deliver!(test_email)
76
88
 
77
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to1@example.com"}}, {address: {email: "to2@example.com"}}, {address: {email: "cc1@example.com", header_to: "to1@example.com"}}, {address: {email: "cc2@example.com", header_to: "to1@example.com"}}])
78
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc1@example.com", "cc2@example.com"]})
89
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to1@example.com", header_to: anything}}),
90
+ a_hash_including({address: {email: "to2@example.com", header_to: anything}}),
91
+ {address: {email: "cc1@example.com", header_to: "to1@example.com"}},
92
+ {address: {email: "cc2@example.com", header_to: "to1@example.com"}}])
93
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc1@example.com,cc2@example.com"})
79
94
  end
80
95
 
81
96
  it "handles name and email" do
82
97
  test_email = Mailer.test_email to: "Joe Test <to1@example.com>, Sam Test <to2@example.com>", cc: "Carl Test <cc1@example.com>, Chris Test <cc2@example.com>"
83
98
  @delivery_method.deliver!(test_email)
84
99
 
85
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to1@example.com", name: "Joe Test"}}, {address: {email: "to2@example.com", name: "Sam Test"}}, {address: {email: "cc1@example.com", name: "Carl Test", header_to: "to1@example.com"}}, {address: {email: "cc2@example.com", name: "Chris Test", header_to: "to1@example.com"}}])
86
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc1@example.com", "cc2@example.com"]})
100
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to1@example.com", name: "Joe Test", header_to: anything}}),
101
+ a_hash_including({address: {email: "to2@example.com", name: "Sam Test", header_to: anything}}),
102
+ {address: {email: "cc1@example.com", name: "Carl Test", header_to: "to1@example.com"}},
103
+ {address: {email: "cc2@example.com", name: "Chris Test", header_to: "to1@example.com"}}])
104
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc1@example.com,cc2@example.com"})
87
105
  end
88
106
 
89
107
  it "handles mix of email only and name/email for to recipients" do
90
108
  test_email = Mailer.test_email to: "Joe Test <to1@example.com>, to2@example.com", cc: "cc1@example.com, Chris Test <cc2@example.com>"
91
109
  @delivery_method.deliver!(test_email)
92
110
 
93
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to1@example.com", name: "Joe Test"}}, {address: {email: "to2@example.com"}}, {address: {email: "cc1@example.com", header_to: "to1@example.com"}}, {address: {email: "cc2@example.com", name: "Chris Test", header_to: "to1@example.com"}}])
94
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc1@example.com", "cc2@example.com"]})
111
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to1@example.com", name: "Joe Test", header_to: anything}}),
112
+ a_hash_including({address: {email: "to2@example.com", header_to: anything}}),
113
+ {address: {email: "cc1@example.com", header_to: "to1@example.com"}},
114
+ {address: {email: "cc2@example.com", name: "Chris Test", header_to: "to1@example.com"}}])
115
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc1@example.com,cc2@example.com"})
95
116
  end
96
117
  end
97
118
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe "SparkPostRails configuration" do
4
+ let(:delivery_method) { SparkPostRails::DeliveryMethod.new }
5
+
6
+ describe "#configuration" do
7
+ it "creates a new configuration + defaults if #configure is never called", skip_configure: true do
8
+ config = SparkPostRails.configuration
9
+ expect(config).to_not be_nil
10
+ end
11
+ end
12
+ end
data/spec/headers_spec.rb CHANGED
@@ -18,7 +18,7 @@ describe SparkPostRails::DeliveryMethod do
18
18
  test_email = Mailer.test_email cc: "Carl Test <cc@example.com>", headers: {"Priority" => "urgent", "Sensitivity" => "private"}
19
19
  @delivery_method.deliver!(test_email)
20
20
 
21
- expect(@delivery_method.data[:content][:headers]).to eq({cc: ["cc@example.com"], "Priority" => "urgent", "Sensitivity" => "private"})
21
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc@example.com", "Priority" => "urgent", "Sensitivity" => "private"})
22
22
  end
23
23
 
24
24
  it "does not pass inappropriate headers through to the API" do
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe SparkPostRails::DeliveryMethod do
4
+ subject { described_class.new }
5
+ let(:metadata) { {item_1: 'test data 1', item_2: 'test data 2'} }
6
+
7
+ describe 'Metadata' do
8
+ context 'template-based message' do
9
+ context 'when metadata is passed' do
10
+ it 'includes metadata' do
11
+ test_email = Mailer.test_email sparkpost_data: { template_id: 'test_template', metadata: metadata }
12
+ subject.deliver!(test_email)
13
+ expect(subject.data[:metadata]).to eq(metadata)
14
+ end
15
+ end
16
+
17
+ context "when metadata isn't passed" do
18
+ it "doesn't include metadata" do
19
+ test_email = Mailer.test_email sparkpost_data: { template_id: 'test_template' }
20
+ subject.deliver!(test_email)
21
+ expect(subject.data).to_not have_key(:metadata)
22
+ end
23
+ end
24
+ end
25
+
26
+ context 'inline-content message' do
27
+ context 'when metadata is passed' do
28
+ it 'includes metadata' do
29
+ test_email = Mailer.test_email sparkpost_data: { metadata: metadata }
30
+ subject.deliver!(test_email)
31
+ expect(subject.data[:metadata]).to eq(metadata)
32
+ end
33
+ end
34
+
35
+ context "when metadata isn't passed" do
36
+ it "doesn't include metadata" do
37
+ test_email = Mailer.test_email sparkpost_data: { metadata: nil }
38
+ subject.deliver!(test_email)
39
+ expect(subject.data).to_not have_key(:metadata)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -21,7 +21,7 @@ describe SparkPostRails::DeliveryMethod do
21
21
 
22
22
  actual_recipients = @delivery_method.data[:recipients]
23
23
  expect(actual_recipients.length).to eq(recipients.length)
24
- expect(actual_recipients).to eq(recipients.each_with_index.map { |recipient, index| recipients_data[index].merge(address: {email: recipient}) })
24
+ expect(actual_recipients).to match(recipients.each_with_index.map { |recipient, index| recipients_data[index].merge(address: {email: recipient, header_to: anything}) })
25
25
  end
26
26
 
27
27
  end
@@ -13,14 +13,14 @@ describe SparkPostRails::DeliveryMethod do
13
13
  test_email = Mailer.test_email
14
14
  @delivery_method.deliver!(test_email)
15
15
 
16
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to@example.com"}}])
16
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to@example.com", header_to: anything}})])
17
17
  end
18
18
 
19
19
  it "handles name and email" do
20
20
  test_email = Mailer.test_email to: "Joe Test <to@example.com>"
21
21
  @delivery_method.deliver!(test_email)
22
22
 
23
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to@example.com", name: "Joe Test"}}])
23
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to@example.com", name: "Joe Test", header_to: anything}})])
24
24
  end
25
25
  end
26
26
 
@@ -29,21 +29,33 @@ describe SparkPostRails::DeliveryMethod do
29
29
  test_email = Mailer.test_email to: "to1@example.com, to2@example.com"
30
30
  @delivery_method.deliver!(test_email)
31
31
 
32
- expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to1@example.com"}}, {address: {email: "to2@example.com"}}])
32
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "to1@example.com", header_to: anything}}),
33
+ a_hash_including({address: {email: "to2@example.com", header_to: anything}})])
33
34
  end
34
35
 
35
36
  it "handles name and email" do
36
37
  test_email = Mailer.test_email to: "Sam Test <to1@example.com>, Joe Test <to2@example.com>"
37
38
  @delivery_method.deliver!(test_email)
38
39
 
39
- expect(@delivery_method.data[:recipients]).to eq([{:address=>{:email=>"to1@example.com", :name=>"Sam Test"}}, {:address=>{:email=>"to2@example.com", :name=>"Joe Test"}}])
40
+ expect(@delivery_method.data[:recipients]).to match([a_hash_including({:address=>{:email=>"to1@example.com", :name=>"Sam Test", header_to: anything}}),
41
+ a_hash_including({:address=>{:email=>"to2@example.com", :name=>"Joe Test", header_to: anything}})])
40
42
  end
41
43
 
42
44
  it "handles mix of email only and name/email" do
43
45
  test_email = Mailer.test_email to: "Sam Test <to1@example.com>, to2@example.com"
44
46
  @delivery_method.deliver!(test_email)
45
47
 
46
- expect(@delivery_method.data[:recipients]).to eq([{:address=>{:email=>"to1@example.com", :name=>"Sam Test"}}, {:address=>{:email=>"to2@example.com"}}])
48
+ expect(@delivery_method.data[:recipients]).to match_array([a_hash_including({:address=>{:email=>"to1@example.com", :name=>"Sam Test", header_to: anything}}),
49
+ a_hash_including({:address=>{:email=>"to2@example.com", header_to: anything}})])
50
+ end
51
+
52
+ it "compiles list of email addresses to populate :header_to for each recipient" do
53
+ expected_header_to = "a@a.com,b@b.com"
54
+ test_email = Mailer.test_email to: "a <a@a.com>, b@b.com"
55
+ @delivery_method.deliver!(test_email)
56
+
57
+ expect(@delivery_method.data[:recipients].first[:address][:header_to]).to eql(expected_header_to)
58
+ expect(@delivery_method.data[:recipients].second[:address][:header_to]).to eql(expected_header_to)
47
59
  end
48
60
  end
49
61
  end
@@ -15,7 +15,8 @@ describe SparkPostRails::DeliveryMethod do
15
15
  end
16
16
 
17
17
  it "raises exception on error" do
18
- stub_request(:any, "https://api.sparkpost.com/api/v1/transmissions").
18
+ uri = URI.join(SparkPostRails.configuration.api_endpoint, 'v1/transmissions')
19
+ stub_request(:any, uri.to_s).
19
20
  to_return(body: "{\"errors\":[{\"message\":\"required field is missing\",\"description\":\"recipients or list_id required\",\"code\":\"1400\"}]}", status: 403)
20
21
 
21
22
  test_email = Mailer.test_email
data/spec/spec_helper.rb CHANGED
@@ -2,17 +2,24 @@ require 'webmock/rspec'
2
2
  require 'rails'
3
3
  require 'action_mailer'
4
4
  require "sparkpost_rails"
5
+ require "active_support/core_ext/integer/time"
5
6
 
6
7
  RSpec.configure do |config|
7
8
 
8
9
  config.before(:all) do
9
- SparkPostRails.configure do |c|
10
- c.api_key = "TESTKEY1234"
11
- end
10
+ ActionMailer::Base.send :include, SparkPostRails::DataOptions
12
11
  end
13
12
 
14
- config.before(:each) do
15
- stub_request(:any, "https://api.sparkpost.com/api/v1/transmissions").
13
+ config.before(:each) do |example|
14
+ if example.metadata[:skip_configure]
15
+ SparkPostRails.configuration = nil # Reset configuration
16
+ else
17
+ SparkPostRails.configure do |c|
18
+ c.api_key = "TESTKEY1234"
19
+ end
20
+ end
21
+ uri = URI.join(SparkPostRails.configuration.api_endpoint, 'v1/transmissions')
22
+ stub_request(:any, uri.to_s).
16
23
  to_return(body: "{\"results\":{\"total_rejected_recipients\":0,\"total_accepted_recipients\":1,\"id\":\"00000000000000000\"}}", status: 200)
17
24
  end
18
25
 
@@ -65,14 +72,14 @@ class Mailer < ActionMailer::Base
65
72
  if data.has_key?(:html_part)
66
73
 
67
74
  mail(data) do |format|
68
- format.text {render text: data[:text_part]}
69
- format.html {render text: data[:html_part]}
75
+ format.text {render plain: data[:text_part]}
76
+ format.html {render plain: data[:html_part]}
70
77
  end
71
78
 
72
79
  else
73
80
 
74
81
  mail(data) do |format|
75
- format.text {render text: data[:text_part]}
82
+ format.text {render plain: data[:text_part]}
76
83
  end
77
84
 
78
85
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sparkpost_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Kimball
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-17 00:00:00.000000000 Z
12
+ date: 2021-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: '4.0'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '5.1'
23
+ version: '6.2'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: '4.0'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.1'
33
+ version: '6.2'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: rspec
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -71,6 +71,7 @@ files:
71
71
  - LICENSE
72
72
  - README.md
73
73
  - lib/sparkpost_rails.rb
74
+ - lib/sparkpost_rails/data_options.rb
74
75
  - lib/sparkpost_rails/delivery_method.rb
75
76
  - lib/sparkpost_rails/exceptions.rb
76
77
  - lib/sparkpost_rails/railtie.rb
@@ -80,6 +81,7 @@ files:
80
81
  - spec/campaign_id_spec.rb
81
82
  - spec/cc_recipients_spec.rb
82
83
  - spec/click_tracking_spec.rb
84
+ - spec/configuration_spec.rb
83
85
  - spec/delivery_schedule_spec.rb
84
86
  - spec/description_spec.rb
85
87
  - spec/exceptions_spec.rb
@@ -88,6 +90,7 @@ files:
88
90
  - spec/inline_content_spec.rb
89
91
  - spec/inline_css_spec.rb
90
92
  - spec/ip_pool_spec.rb
93
+ - spec/metadata_spec.rb
91
94
  - spec/open_tracking_spec.rb
92
95
  - spec/recipient_specific_data_spec.rb
93
96
  - spec/recipients_list_spec.rb
@@ -121,36 +124,37 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
124
  - !ruby/object:Gem::Version
122
125
  version: '0'
123
126
  requirements: []
124
- rubyforge_project:
125
- rubygems_version: 2.2.2
127
+ rubygems_version: 3.1.2
126
128
  signing_key:
127
129
  specification_version: 4
128
130
  summary: SparkPost for Rails
129
131
  test_files:
130
- - spec/inline_content_spec.rb
132
+ - spec/reply_to_spec.rb
133
+ - spec/open_tracking_spec.rb
134
+ - spec/recipient_specific_data_spec.rb
135
+ - spec/response_spec.rb
136
+ - spec/click_tracking_spec.rb
137
+ - spec/substitution_data_spec.rb
138
+ - spec/spec_helper.rb
131
139
  - spec/from_spec.rb
140
+ - spec/ip_pool_spec.rb
141
+ - spec/metadata_spec.rb
132
142
  - spec/subaccount_api_spec.rb
143
+ - spec/return_path_spec.rb
144
+ - spec/campaign_id_spec.rb
145
+ - spec/inline_content_spec.rb
146
+ - spec/skip_suppression_spec.rb
133
147
  - spec/recipients_spec.rb
134
- - spec/headers_spec.rb
135
- - spec/transactional_spec.rb
136
- - spec/bcc_recipients_spec.rb
148
+ - spec/description_spec.rb
149
+ - spec/inline_css_spec.rb
137
150
  - spec/exceptions_spec.rb
138
- - spec/ip_pool_spec.rb
151
+ - spec/delivery_schedule_spec.rb
139
152
  - spec/attachments_spec.rb
140
- - spec/cc_recipients_spec.rb
153
+ - spec/headers_spec.rb
154
+ - spec/bcc_recipients_spec.rb
141
155
  - spec/recipients_list_spec.rb
142
- - spec/template_spec.rb
143
- - spec/campaign_id_spec.rb
144
- - spec/reply_to_spec.rb
145
- - spec/spec_helper.rb
146
- - spec/description_spec.rb
147
- - spec/click_tracking_spec.rb
148
- - spec/skip_suppression_spec.rb
149
- - spec/substitution_data_spec.rb
150
- - spec/inline_css_spec.rb
151
- - spec/response_spec.rb
152
- - spec/open_tracking_spec.rb
156
+ - spec/transactional_spec.rb
157
+ - spec/cc_recipients_spec.rb
153
158
  - spec/sandbox_mode_spec.rb
154
- - spec/recipient_specific_data_spec.rb
155
- - spec/return_path_spec.rb
156
- - spec/delivery_schedule_spec.rb
159
+ - spec/template_spec.rb
160
+ - spec/configuration_spec.rb