sparkpost_rails 1.4.0 → 1.5.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: 1824c8a4ed0368d9063eadf820ff0e53b8469af7
4
- data.tar.gz: b7ba7d9806925dfcc2e6f859a484a85cd43e24f2
3
+ metadata.gz: 7dd8e6ff5990addebb68d59f37adda1b51f8b676
4
+ data.tar.gz: 0e250da6bd76270214b057608fc23a0fb835ccc3
5
5
  SHA512:
6
- metadata.gz: de4ea6d3e24d6414ec768867816d1ddb3f17a4dbe01994b05fa5ba43a3d53663ca315b5202c0d8d0b918c3d1b0f6b12b86738536f62049f12c2fcd813a0ca8e6
7
- data.tar.gz: c4431d3186b89221cc0f8270a04b7c698f31a1594d1de39bb8cf3068a2b4f6e999369b22c3244714fc28f2e51359f45d63adbb84a89a8638b73fe210efc3ef51
6
+ metadata.gz: 977a7c03477a3fb275317172f5eb8821127f1df2a063902eaa6781dd046b73019a10683daf3ee0fc057cfd48c7ef67deb109555a057bbae22c1c029f7338502d
7
+ data.tar.gz: f115139d0f015c8f97a57fd5eb55a7f6b49e1962831f9dc0088e409b48961378ef87a6a1437f1c914e622601294d42f8237886c79669534c4afc479d54c9a2e4
data/README.md CHANGED
@@ -4,90 +4,74 @@
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.sandbox = true # default: false
42
+ c.track_opens = true # default: false
43
+ c.track_clicks = true # default: false
44
+ c.return_path = 'BOUNCE-EMAIL@YOUR-DOMAIN.COM' # default: nil
45
+ c.campaign_id = 'YOUR-CAMPAIGN' # default: nil
46
+ c.transactional = true # default: false
47
+ c.ip_pool = "MY-POOL" # default: nil
48
+ c.inline_css = true # default: false
49
+ c.html_content_only = true # default: false
50
+ c.subaccount = "123" # default: nil
53
51
  end
54
52
  ```
55
53
 
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
54
  Usage
72
55
  -----
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.
56
+ 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
57
 
76
- ```
58
+ ```ruby
77
59
  result = MyMailer.welcome_message(user).deliver!
78
60
  ```
79
61
 
80
62
  Example:
81
63
 
82
- ```
83
- {"total_rejected_recipients"=>0, "total_accepted_recipients"=>1, "id"=>"00000000000000"}
64
+ ```ruby
65
+ {
66
+ "total_rejected_recipients" => 0,
67
+ "total_accepted_recipients" => 1,
68
+ "id" => "00000000000000"
69
+ }
84
70
  ```
85
71
 
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.
72
+ If the SparkPost API reponds with an error condition, SparkPostRails will raise a `SparkPostRails::DeliveryException`, which will include all the message data returned by the API.
88
73
 
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.
74
+ SparkPostRails will support multiple recipients, multilple CC, multiple BCC, ReplyTo address, file attachments, inline images, multi-part (HTML and plaintext) messages - all utilizing the standard `ActionMailer` methodologies.
91
75
 
92
76
  Handling Errors
93
77
  ---------------
@@ -95,79 +79,77 @@ If you are using `ActiveJob` and wish to do something special when the SparkPost
95
79
 
96
80
  `config/initializers/action_mailer.rb`
97
81
 
98
- ```
82
+ ```ruby
99
83
  ActionMailer::DeliveryJob.rescue_from(SparkPostRails::DeliveryException) do |exception|
100
84
  # do something special with the error
101
85
  end
102
86
  ```
103
87
 
104
- SparkPost Specific Features
88
+ SparkPost-Specific Features
105
89
  ---------------------------
106
90
 
107
91
  ### 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
- }
92
+ 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 to the mail message in a field named `sparkpost_data`:
93
+
94
+ ```ruby
95
+ data = {
96
+ track_opens: true,
97
+ track_clicks: false,
98
+ campaign_id: "My Campaign",
99
+ transactional: true,
100
+ ip_pool = "SPECIAL_POOL",
101
+ api_key = "MESSAGE_SPECIFIC_API_KEY"
102
+ subaccount = "123"
103
+ }
120
104
 
121
105
  mail(to: to_email, subject: "Test", body: "test", sparkpost_data: data)
122
106
  ```
123
107
 
124
- Additionally, return_path can be overriden on a specific email by setting that field on the mail message itself:
108
+ Additionally, `return_path` can be overriden on a specific email by setting that field on the mail message itself:
125
109
 
126
- ```
110
+ ```ruby
127
111
  mail(to: to_email, subject: "Test", body: "test", return_path: "bounces@example.com")
128
112
  ```
129
113
 
130
114
  ### Transmission Specific Settings
131
115
 
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:
116
+ 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
117
 
135
- ```
118
+ ```ruby
136
119
  data = { skip_suppression: true }
137
120
 
138
121
  mail(to: to_email, subject: "Test", body: "test", sparkpost_data: data)
139
122
  ```
140
123
 
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.
124
+ 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
125
 
143
- ```
126
+ ```ruby
144
127
  start_time = DateTime.now + 4.hours
145
128
 
146
129
  mail(to: to_email, subject: "Test", body: "test", date: start_time)
147
130
  ```
148
131
 
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.
132
+ 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
133
 
152
- ```
134
+ ```ruby
153
135
  data = { description: "My Important Message" }
154
136
 
155
137
  mail(to: to_email, subject: "Test", body: "test", sparkpost_data: data)
156
138
  ```
157
139
 
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.
140
+ 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
141
 
161
- ```
142
+ ```ruby
162
143
  data = { html_content_only: true }
163
144
 
164
145
  mail(to: to_email, subject: "Test", body: "<h1>test</h1>", sparkpost_data: data)
165
146
  ```
166
147
 
167
148
  ### Subaccounts
149
+
168
150
  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
151
 
170
- ```
152
+ ```ruby
171
153
  data = { api_key: "SUBACCOUNT_API_KEY" }
172
154
 
173
155
  mail(subject: "Test", body: "test", sparkpost_data: data)
@@ -175,42 +157,42 @@ mail(subject: "Test", body: "test", sparkpost_data: data)
175
157
 
176
158
  Subaccounts can also be leveraged using the subaccount ID with the master API key.
177
159
 
178
- ```
160
+ ```ruby
179
161
  data = { subaccount: "123" }
180
162
 
181
163
  mail(subject: "Test", body: "test", sparkpost_data: data)
182
164
  ```
183
165
 
184
166
  ### Recipient Lists
185
- SparkPostRails supports using SparkPost stored recipient lists. Simply add the list_id to the sparkpost_data hash on the mail message:
167
+ SparkPostRails supports using SparkPost stored recipient lists. Simply add the `list_id` to the `sparkpost_data` hash on the mail message:
186
168
 
187
- ```
169
+ ```ruby
188
170
  data = { list_id: "MY-LIST"}
189
171
 
190
172
  mail(subject: "Test", body: "test", sparkpost_data: data)
191
173
  ```
192
174
 
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.
175
+ **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
176
 
196
177
 
197
178
  ### 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.
179
+ 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
180
 
201
- ```
202
- sub_data = {first_name: "Sam",
203
- last_name: "Test}
181
+ ```ruby
182
+ sub_data = {
183
+ first_name: "Sam",
184
+ last_name: "Test
185
+ }
204
186
 
205
187
  data = { substitution_data: sub_data }
206
188
 
207
189
  mail(to: to_email, subject: "Test", body: "test", sparkpost_data: data)
208
190
  ```
209
191
 
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).
192
+ ### Recipient-Specific Data
193
+ 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
194
 
213
- ```
195
+ ```ruby
214
196
  recipients = ['recipient1@email.com', 'recipient2@email.com']
215
197
  sparkpost_data = {
216
198
  recipients: [
@@ -223,10 +205,9 @@ mail(to: recipients, sparkpost_data: sparkpost_data)
223
205
 
224
206
 
225
207
  ### 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:
208
+ 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
209
 
229
- ```
210
+ ```ruby
230
211
  data = { template_id: "MY-TEMPLATE" }
231
212
 
232
213
  mail(to: to_email, sparkpost_data: data) do |format|
@@ -234,15 +215,14 @@ mail(to: to_email, sparkpost_data: data) do |format|
234
215
  end
235
216
  ```
236
217
 
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.
218
+ **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
219
 
240
220
  ###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."
221
+ If you need to identify custom mail headers for your messages, use the `ActionMailer` `header[]` method. The gem will pass all approprite headers through to the API. Note, per the SparkPost API documentation
244
222
 
245
- ```
223
+ > Headers such as 'Content-Type' and 'Content-Transfer-Encoding' are not allowed here as they are auto-generated upon construction of the email.
224
+
225
+ ```ruby
246
226
  headers["Priority"] = "urgent"
247
227
  headers["Sensitivity"] = "private"
248
228
 
@@ -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)
@@ -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
 
@@ -381,7 +385,6 @@ module SparkPostRails
381
385
 
382
386
  request = Net::HTTP::Post.new(uri.path, @headers)
383
387
  request.body = JSON.generate(@data)
384
-
385
388
  http.request(request)
386
389
  end
387
390
 
@@ -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.0"
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/hmBQGZ1EWLD6roqB4W5QEdbNnJUFxWOaoTssce1rmOGznbTia3VtVDJy27aYYePjDi1KgOLPaidy7whC5V4Uh8l1hiNxVEdDcvSgCTnenIsCXVQEw+TIrBOstarPjtKNe5lj9mbLQ6/ak4eEeFjkOf+ai0aGFRY7JYZGjhUWOyWGRo4VFjsNhkeMeFjmKsyLHurnLuL7h4dTI2W4Zv8Wg3t1drHHhzV3iLxLc3bqmLNS6i6JQ6/asKNS6vSgKtW5raNQ6641a95uGRa2z3qj1rPXGbb3TiFA3+9l6WzQQPOwn662ehyJQ6z7+JO6qBNR6/1jefNc4sNtP1luJuMhwhLnW2+qIyDnCXOutBUTOEaYrvQY2DQKLvzT1d72rxoD2NPLqD4eGgNlfux7ZNTQurd11mts0NLZbJ2nz/9Hs328/vv32fnvV3/N6u/zUaH61d4bLjatIFLZJCL4owsKScEgm8n3/p9zazexi6yC6Wz2pqbo752diLBUfNN3QtP/6m9LdZ85tHkv40jB+B4fUd7cHmVB/Tm+2FQJnrPjbnYjPz6apPsyJ17RGx61fn/FcF5Yxynw3RP5OX1QanX/A4d0Q18iMSI8dFRd/q8i6CnVza8u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jcaNO+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
data/spec/spec_helper.rb CHANGED
@@ -6,12 +6,18 @@ require "sparkpost_rails"
6
6
  RSpec.configure do |config|
7
7
 
8
8
  config.before(:all) do
9
- SparkPostRails.configure do |c|
10
- c.api_key = "TESTKEY1234"
11
- end
9
+ ActionMailer::Base.send :include, SparkPostRails::DataOptions
12
10
  end
13
11
 
14
- config.before(:each) do
12
+ config.before(:each) do |example|
13
+ if example.metadata[:skip_configure]
14
+ SparkPostRails.configuration = nil # Reset configuration
15
+ else
16
+ SparkPostRails.configure do |c|
17
+ c.api_key = "TESTKEY1234"
18
+ end
19
+ end
20
+
15
21
  stub_request(:any, "https://api.sparkpost.com/api/v1/transmissions").
16
22
  to_return(body: "{\"results\":{\"total_rejected_recipients\":0,\"total_accepted_recipients\":1,\"id\":\"00000000000000000\"}}", status: 200)
17
23
  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.0
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: 2017-11-30 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: '5.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: '5.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
@@ -127,30 +130,32 @@ signing_key:
127
130
  specification_version: 4
128
131
  summary: SparkPost for Rails
129
132
  test_files:
133
+ - spec/recipients_spec.rb
134
+ - spec/template_spec.rb
135
+ - spec/substitution_data_spec.rb
130
136
  - spec/inline_content_spec.rb
137
+ - spec/campaign_id_spec.rb
131
138
  - spec/from_spec.rb
132
- - spec/subaccount_api_spec.rb
133
- - spec/recipients_spec.rb
134
- - spec/headers_spec.rb
135
- - spec/transactional_spec.rb
136
- - spec/bcc_recipients_spec.rb
137
- - spec/exceptions_spec.rb
138
139
  - spec/ip_pool_spec.rb
139
- - spec/attachments_spec.rb
140
- - spec/cc_recipients_spec.rb
141
140
  - spec/recipients_list_spec.rb
142
- - spec/template_spec.rb
143
- - spec/campaign_id_spec.rb
144
141
  - spec/reply_to_spec.rb
145
- - spec/spec_helper.rb
146
- - spec/description_spec.rb
147
142
  - spec/click_tracking_spec.rb
148
- - spec/skip_suppression_spec.rb
149
- - spec/substitution_data_spec.rb
150
- - spec/inline_css_spec.rb
143
+ - spec/return_path_spec.rb
144
+ - spec/headers_spec.rb
145
+ - spec/spec_helper.rb
146
+ - spec/exceptions_spec.rb
147
+ - spec/metadata_spec.rb
151
148
  - spec/response_spec.rb
152
149
  - spec/open_tracking_spec.rb
153
- - spec/sandbox_mode_spec.rb
150
+ - spec/inline_css_spec.rb
154
151
  - spec/recipient_specific_data_spec.rb
155
- - spec/return_path_spec.rb
152
+ - spec/bcc_recipients_spec.rb
156
153
  - spec/delivery_schedule_spec.rb
154
+ - spec/sandbox_mode_spec.rb
155
+ - spec/cc_recipients_spec.rb
156
+ - spec/configuration_spec.rb
157
+ - spec/description_spec.rb
158
+ - spec/attachments_spec.rb
159
+ - spec/subaccount_api_spec.rb
160
+ - spec/skip_suppression_spec.rb
161
+ - spec/transactional_spec.rb