sparkpost_rails 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ describe SparkPostRails::DeliveryMethod do
4
+
5
+ before(:each) do
6
+ @delivery_method = SparkPostRails::DeliveryMethod.new
7
+ end
8
+
9
+ context "BCC Recipients" do
10
+
11
+ context "single bcc recipient, no cc recipients" do
12
+ it "handles email only" do
13
+ test_email = Mailer.test_email bcc: "bcc@example.com"
14
+ @delivery_method.deliver!(test_email)
15
+
16
+ expect(@delivery_method.data[:recipients]).to eq([{address: {email: "to@example.com"}}, {address: {email: "bcc@example.com", header_to: "to@example.com"}}])
17
+ expect(@delivery_method.data[:content]).not_to include(:headers)
18
+ end
19
+
20
+ it "handles name and email" do
21
+ test_email = Mailer.test_email to: "Joe Test <to1@example.com>, Sam Test <to2@example.com>", bcc: "Brock Test <bcc@example.com>"
22
+ @delivery_method.deliver!(test_email)
23
+
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[:content]).not_to include(:headers)
26
+ end
27
+ end
28
+
29
+ context "multiple bcc recipients, no cc recipientsa" do
30
+ it "handles email only" do
31
+ test_email = Mailer.test_email bcc: "bcc1@example.com, bcc2@example.com"
32
+ @delivery_method.deliver!(test_email)
33
+
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"}}])
35
+ expect(@delivery_method.data[:content]).not_to include(:headers)
36
+ end
37
+
38
+ it "handles name and email" do
39
+ test_email = Mailer.test_email to: "Joe Test <to@example.com>", bcc: "Brock Test <bcc1@example.com>, Brack Test <bcc2@example.com>"
40
+ @delivery_method.deliver!(test_email)
41
+
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"}}])
43
+ expect(@delivery_method.data[:content]).not_to include(:headers)
44
+ end
45
+
46
+ it "handles mix of email only and name/email" do
47
+ test_email = Mailer.test_email to: "Joe Test <to@example.com>", bcc: "Brock Test <bcc1@example.com>, bcc2@example.com"
48
+ @delivery_method.deliver!(test_email)
49
+
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"}}])
51
+ expect(@delivery_method.data[:content]).not_to include(:headers)
52
+ end
53
+ end
54
+
55
+ context "bcc and cc recipients" do
56
+ it "handles email only" do
57
+ test_email = Mailer.test_email to: "to1@example.com, to2@example.com", cc: "cc@example.com", bcc: "bcc@example.com"
58
+ @delivery_method.deliver!(test_email)
59
+
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"]})
62
+ end
63
+
64
+ it "handles name and email" do
65
+ 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
+ @delivery_method.deliver!(test_email)
67
+
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"]})
70
+ end
71
+
72
+ it "handles mix of email only and name/email" do
73
+ 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
+ @delivery_method.deliver!(test_email)
75
+
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"]})
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe SparkPostRails::DeliveryMethod do
4
+
5
+ before(:each) do
6
+ SparkPostRails.configuration.set_defaults
7
+ @delivery_method = SparkPostRails::DeliveryMethod.new
8
+ end
9
+
10
+ context "Campaign ID" do
11
+ it "handles campaign id in the configuration" do
12
+ SparkPostRails.configure do |c|
13
+ c.campaign_id = "ABCD1234"
14
+ end
15
+
16
+ test_email = Mailer.test_email
17
+ @delivery_method.deliver!(test_email)
18
+
19
+ expect(@delivery_method.data[:campaign_id]).to eq("ABCD1234")
20
+ end
21
+
22
+ it "handles campaign id on an individual message" do
23
+ test_email = Mailer.test_email sparkpost_data: {campaign_id: "My Campaign"}
24
+
25
+ @delivery_method.deliver!(test_email)
26
+
27
+ expect(@delivery_method.data[:campaign_id]).to eq("My Campaign")
28
+ end
29
+
30
+ it "handles the value on an individual message overriding configuration" do
31
+ SparkPostRails.configure do |c|
32
+ c.campaign_id = "ABCD1234"
33
+ end
34
+
35
+ test_email = Mailer.test_email sparkpost_data: {campaign_id: "My Campaign"}
36
+
37
+ @delivery_method.deliver!(test_email)
38
+
39
+ expect(@delivery_method.data[:campaign_id]).to eq("My Campaign")
40
+ end
41
+
42
+ it "handles the value on an individual message of nil overriding configuration" do
43
+ SparkPostRails.configure do |c|
44
+ c.campaign_id = "ABCD1234"
45
+ end
46
+
47
+ test_email = Mailer.test_email sparkpost_data: {campaign_id: nil}
48
+
49
+ @delivery_method.deliver!(test_email)
50
+
51
+ expect(@delivery_method.data.has_key?(:campaign_id)).to eq(false)
52
+ end
53
+
54
+ it "handles a default setting of none" do
55
+ test_email = Mailer.test_email
56
+ @delivery_method.deliver!(test_email)
57
+
58
+ expect(@delivery_method.data.has_key?(:campaign_id)).to eq(false)
59
+ end
60
+
61
+ end
62
+ end
63
+
64
+
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe SparkPostRails::DeliveryMethod do
4
+
5
+ before(:each) do
6
+ @delivery_method = SparkPostRails::DeliveryMethod.new
7
+ end
8
+
9
+ context "CC Recipients" do
10
+ context "single to recipient and single cc recipient" do
11
+ it "handles email only" do
12
+ test_email = Mailer.test_email cc: "cc@example.com"
13
+ @delivery_method.deliver!(test_email)
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"]})
17
+ end
18
+
19
+ it "handles name and email" do
20
+ test_email = Mailer.test_email to: "Joe Test <to@example.com>", cc: "Carl Test <cc@example.com>"
21
+ @delivery_method.deliver!(test_email)
22
+
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"]})
25
+ end
26
+ end
27
+
28
+ context "single to recipient and multiple cc recipients" do
29
+ it "handles email only" do
30
+ test_email = Mailer.test_email cc: "cc1@example.com, cc2@example.com"
31
+ @delivery_method.deliver!(test_email)
32
+
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
+ end
36
+
37
+ it "handles name and email" do
38
+ test_email = Mailer.test_email to: "Joe Test <to@example.com>", cc: "Carl Test <cc1@example.com>, Chris Test <cc2@example.com>"
39
+ @delivery_method.deliver!(test_email)
40
+
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"]})
43
+ end
44
+
45
+ it "handles mix of email only and name/email" do
46
+ test_email = Mailer.test_email to: "Joe Test <to@example.com>", cc: "Carl Test <cc1@example.com>, cc2@example.com"
47
+ @delivery_method.deliver!(test_email)
48
+
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"]})
51
+ end
52
+ end
53
+
54
+ context "multiple to recipients with single cc recipient" do
55
+ it "handles email only" do
56
+ test_email = Mailer.test_email to: "to1@example.com, to2@example.com", cc: "cc@example.com"
57
+ @delivery_method.deliver!(test_email)
58
+
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"]})
61
+ end
62
+
63
+ it "handles name and email" do
64
+ test_email = Mailer.test_email to: "Joe Test <to1@example.com>, Sam Test <to2@example.com>", cc: "Carl Test <cc@example.com>"
65
+ @delivery_method.deliver!(test_email)
66
+
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"]})
69
+ end
70
+ end
71
+
72
+ context "multiple to recipients with multiple cc recipients" do
73
+ it "handles email only" do
74
+ test_email = Mailer.test_email to: "to1@example.com, to2@example.com", cc: "cc1@example.com, cc2@example.com"
75
+ @delivery_method.deliver!(test_email)
76
+
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"]})
79
+ end
80
+
81
+ it "handles name and email" do
82
+ 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
+ @delivery_method.deliver!(test_email)
84
+
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"]})
87
+ end
88
+
89
+ it "handles mix of email only and name/email for to recipients" do
90
+ test_email = Mailer.test_email to: "Joe Test <to1@example.com>, to2@example.com", cc: "cc1@example.com, Chris Test <cc2@example.com>"
91
+ @delivery_method.deliver!(test_email)
92
+
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"]})
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe SparkPostRails::DeliveryMethod do
4
+
5
+ before(:each) do
6
+ SparkPostRails.configuration.set_defaults
7
+ @delivery_method = SparkPostRails::DeliveryMethod.new
8
+ end
9
+
10
+ context "Click Tracking" do
11
+ it "handles click tracking enabled in the configuration" do
12
+ SparkPostRails.configure do |c|
13
+ c.track_clicks = true
14
+ end
15
+
16
+ test_email = Mailer.test_email
17
+
18
+ @delivery_method.deliver!(test_email)
19
+
20
+ expect(@delivery_method.data[:options][:click_tracking]).to eq(true)
21
+ end
22
+
23
+ it "handles click tracking enabled on an individual message" do
24
+ test_email = Mailer.test_email sparkpost_data: {track_clicks: true}
25
+
26
+ @delivery_method.deliver!(test_email)
27
+
28
+ expect(@delivery_method.data[:options][:click_tracking]).to eq(true)
29
+ end
30
+
31
+ it "handles the value on an individual message overriding configuration" do
32
+ SparkPostRails.configure do |c|
33
+ c.track_clicks = true
34
+ end
35
+
36
+ test_email = Mailer.test_email sparkpost_data: {track_clicks: false}
37
+
38
+ @delivery_method.deliver!(test_email)
39
+
40
+ expect(@delivery_method.data[:options][:click_tracking]).to eq(false)
41
+ end
42
+
43
+ it "handles a default setting of 'false'" do
44
+ test_email = Mailer.test_email
45
+
46
+ @delivery_method.deliver!(test_email)
47
+
48
+ expect(@delivery_method.data[:options][:click_tracking]).to eq(false)
49
+ end
50
+
51
+ end
52
+ end
53
+
54
+
@@ -6,7 +6,7 @@ describe SparkPostRails::DeliveryMethod do
6
6
  @delivery_method = SparkPostRails::DeliveryMethod.new
7
7
  end
8
8
 
9
- context "Content" do
9
+ context "Inline Content" do
10
10
  it "sets the subject" do
11
11
  test_email = Mailer.test_email
12
12
  @delivery_method.deliver!(test_email)
@@ -29,6 +29,14 @@ describe SparkPostRails::DeliveryMethod do
29
29
  expect(@delivery_method.data[:content][:text]).to eq("Hello, Testing!")
30
30
  expect(@delivery_method.data[:content][:html]).to eq("<h1>Hello, Testing!</h1>")
31
31
  end
32
+
33
+ it "should not include template details" do
34
+ test_email = Mailer.test_email
35
+ @delivery_method.deliver!(test_email)
36
+
37
+ expect(@delivery_method.data[:content].has_key?(:template_id)).to eq(false)
38
+ expect(@delivery_method.data[:content].has_key?(:use_draft_template)).to eq(false)
39
+ end
32
40
  end
33
41
  end
34
42
 
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe SparkPostRails::DeliveryMethod do
4
+
5
+ before(:each) do
6
+ SparkPostRails.configuration.set_defaults
7
+ @delivery_method = SparkPostRails::DeliveryMethod.new
8
+ end
9
+
10
+ context "Open Tracking" do
11
+ it "handles open tracking enabled in the configuration" do
12
+ SparkPostRails.configure do |c|
13
+ c.track_opens = true
14
+ end
15
+
16
+ test_email = Mailer.test_email
17
+
18
+ @delivery_method.deliver!(test_email)
19
+
20
+ expect(@delivery_method.data[:options][:open_tracking]).to eq(true)
21
+ end
22
+
23
+ it "handles open tracking enabled on an individual message" do
24
+ test_email = Mailer.test_email sparkpost_data: {track_opens: true}
25
+
26
+ @delivery_method.deliver!(test_email)
27
+
28
+ expect(@delivery_method.data[:options][:open_tracking]).to eq(true)
29
+ end
30
+
31
+ it "handles the value on an individual message overriding configuration" do
32
+ SparkPostRails.configure do |c|
33
+ c.track_opens = true
34
+ end
35
+
36
+ test_email = Mailer.test_email sparkpost_data: {track_opens: false}
37
+
38
+ @delivery_method.deliver!(test_email)
39
+
40
+ expect(@delivery_method.data[:options][:open_tracking]).to eq(false)
41
+ end
42
+
43
+ it "handles a default setting of 'false'" do
44
+ test_email = Mailer.test_email
45
+
46
+ @delivery_method.deliver!(test_email)
47
+
48
+ expect(@delivery_method.data[:options][:open_tracking]).to eq(false)
49
+ end
50
+
51
+ end
52
+ end
53
+
54
+
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe SparkPostRails::DeliveryMethod do
4
+
5
+ before(:each) do
6
+ @delivery_method = SparkPostRails::DeliveryMethod.new
7
+ end
8
+
9
+ context "Recipients List" do
10
+
11
+ it "handles a list_id" do
12
+ test_email = Mailer.test_email sparkpost_data: {recipient_list_id: "List1"}
13
+ @delivery_method.deliver!(test_email)
14
+
15
+ expect(@delivery_method.data[:recipients]).to eq({list_id: "List1"})
16
+ end
17
+
18
+ it "ignores any CC addresses" do
19
+ test_email = Mailer.test_email cc: "cc@example.com", sparkpost_data: {recipient_list_id: "List1"}
20
+ @delivery_method.deliver!(test_email)
21
+
22
+ expect(@delivery_method.data[:recipients]).to eq({list_id: "List1"})
23
+ expect(@delivery_method.data[:content].has_key?(:headers)).to eq(false)
24
+ end
25
+
26
+ it "ignores any BCC addresses" do
27
+ test_email = Mailer.test_email bcc: "cc@example.com", sparkpost_data: {recipient_list_id: "List1"}
28
+ @delivery_method.deliver!(test_email)
29
+
30
+ expect(@delivery_method.data[:recipients]).to eq({list_id: "List1"})
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe SparkPostRails::DeliveryMethod do
4
+
5
+ before(:each) do
6
+ SparkPostRails.configuration.set_defaults
7
+ @delivery_method = SparkPostRails::DeliveryMethod.new
8
+ end
9
+
10
+ context "Return Path" do
11
+ it "handles return path set in the configuration" do
12
+ SparkPostRails.configure do |c|
13
+ c.return_path = "BOUNCE-EMAIL@EXAMPLE.COM"
14
+ end
15
+
16
+ test_email = Mailer.test_email
17
+ @delivery_method.deliver!(test_email)
18
+
19
+ expect(@delivery_method.data[:return_path]).to eq('BOUNCE-EMAIL@EXAMPLE.COM')
20
+ end
21
+
22
+ it "handles return path on an individual message" do
23
+ test_email = Mailer.test_email return_path: "bounce@example.com"
24
+
25
+ @delivery_method.deliver!(test_email)
26
+
27
+ expect(@delivery_method.data[:return_path]).to eq('bounce@example.com')
28
+ end
29
+
30
+ it "handles the value on an individual message overriding configuration" do
31
+ SparkPostRails.configure do |c|
32
+ c.return_path = "BOUNCE-EMAIL@EXAMPLE.COM"
33
+ end
34
+
35
+ test_email = Mailer.test_email return_path: "bounce@example.com"
36
+
37
+ @delivery_method.deliver!(test_email)
38
+
39
+ expect(@delivery_method.data[:return_path]).to eq('bounce@example.com')
40
+ end
41
+
42
+ it "handles a default setting of none" do
43
+ test_email = Mailer.test_email
44
+ @delivery_method.deliver!(test_email)
45
+
46
+ expect(@delivery_method.data.has_key?(:return_path)).to eq(false)
47
+ end
48
+
49
+ end
50
+ end