sparkpost_rails_eu 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,46 @@
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 "Delivery Schedule" do
10
+ it "handles supplied future DateTime value less than a year from now" do
11
+ start_time = (DateTime.now + 4.hours)
12
+ formatted_start_time = start_time.strftime("%Y-%m-%dT%H:%M:%S%:z")
13
+
14
+ test_email = Mailer.test_email date: start_time
15
+ @delivery_method.deliver!(test_email)
16
+
17
+ expect(@delivery_method.data[:options][:start_time]).to eq(formatted_start_time)
18
+ end
19
+
20
+ it "does not include start_time if date is in the past" do
21
+ start_time = (DateTime.now - 4.hours)
22
+
23
+ test_email = Mailer.test_email date: start_time
24
+ @delivery_method.deliver!(test_email)
25
+
26
+ expect(@delivery_method.data[:options].has_key?(:start_time)).to eq(false)
27
+ end
28
+
29
+ it "does not include start_time if date is more than 1 year from now" do
30
+ start_time = (DateTime.now + 4.years)
31
+
32
+ test_email = Mailer.test_email date: start_time
33
+ @delivery_method.deliver!(test_email)
34
+
35
+ expect(@delivery_method.data[:options].has_key?(:start_time)).to eq(false)
36
+ end
37
+
38
+ it "does not include start_time if not set" do
39
+ test_email = Mailer.test_email
40
+ @delivery_method.deliver!(test_email)
41
+
42
+ expect(@delivery_method.data[:options].has_key?(:start_time)).to eq(false)
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,39 @@
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 "Description" do
10
+ it "handles value from message" do
11
+ test_email = Mailer.test_email sparkpost_data: {description: "Test Email"}
12
+
13
+ @delivery_method.deliver!(test_email)
14
+
15
+ expect(@delivery_method.data[:description]).to eq("Test Email")
16
+ end
17
+
18
+ it "truncates values longer than 1024 characters" do
19
+ raw_description = "X" * 1050
20
+ truncated_description = ("X" * 1021) + "..."
21
+
22
+ test_email = Mailer.test_email sparkpost_data: {description: raw_description}
23
+
24
+ @delivery_method.deliver!(test_email)
25
+
26
+ expect(@delivery_method.data[:description]).to eq(truncated_description)
27
+ end
28
+
29
+ it "does not include description element if not supplied" do
30
+ test_email = Mailer.test_email
31
+ @delivery_method.deliver!(test_email)
32
+
33
+ expect(@delivery_method.data.has_key?(:description)).to eq(false)
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe SparkPostRails::DeliveryException do
4
+ subject { SparkPostRails::DeliveryException.new(error) }
5
+
6
+ describe 'string' do
7
+ let(:error) { 'Some delivery error' }
8
+
9
+ it 'preserves original message' do
10
+ begin
11
+ raise subject
12
+ rescue SparkPostRails::DeliveryException => err
13
+ expect(error).to eq(err.message)
14
+ end
15
+ end
16
+ end
17
+
18
+ describe 'array with error details' do
19
+ let(:error) { [{ 'message' => 'Message generation rejected', 'description' => 'recipient address suppressed due to customer policy', 'code' => '1902' }] }
20
+
21
+ it 'assigns message' do
22
+ expect(subject.service_message).to eq('Message generation rejected')
23
+ end
24
+
25
+ it 'assigns description' do
26
+ expect(subject.service_description).to eq('recipient address suppressed due to customer policy')
27
+ end
28
+
29
+ it 'assigns code' do
30
+ expect(subject.service_code).to eq('1902')
31
+ end
32
+
33
+ it 'preserves original message' do
34
+ begin
35
+ raise subject
36
+ rescue SparkPostRails::DeliveryException => err
37
+ expect(error.to_s).to eq(err.message)
38
+ end
39
+ end
40
+ end
41
+
42
+ describe 'array with partial details' do
43
+ let(:error) { [{ 'message' => 'end of world' }] }
44
+
45
+ it 'assigns message' do
46
+ expect(subject.service_message).to eq('end of world')
47
+ end
48
+
49
+ it 'assigns description' do
50
+ expect(subject.service_description).to be nil
51
+ end
52
+
53
+ it 'assigns code' do
54
+ expect(subject.service_code).to be nil
55
+ end
56
+
57
+ it 'preserves original message' do
58
+ begin
59
+ raise subject
60
+ rescue SparkPostRails::DeliveryException => err
61
+ expect(error.to_s).to eq(err.message)
62
+ end
63
+ end
64
+ end
65
+ end
data/spec/from_spec.rb ADDED
@@ -0,0 +1,24 @@
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 "From" do
10
+ it "handles email only" do
11
+ test_email = Mailer.test_email
12
+ @delivery_method.deliver!(test_email)
13
+
14
+ expect(@delivery_method.data[:content][:from]).to eq({email: "from@example.com"})
15
+ end
16
+
17
+ it "handles name and email" do
18
+ test_email = Mailer.test_email from: "Joe Test <from@example.com>"
19
+ @delivery_method.deliver!(test_email)
20
+
21
+ expect(@delivery_method.data[:content][:from]).to eq({:email=>"from@example.com", :name=>"Joe Test"})
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
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 "Headers" do
10
+ it "passes appropriate headers through to the API" do
11
+ test_email = Mailer.test_email headers: {"Priority" => "urgent", "Sensitivity" => "private"}
12
+ @delivery_method.deliver!(test_email)
13
+
14
+ expect(@delivery_method.data[:content][:headers]).to eq({"Priority" => "urgent", "Sensitivity" => "private"})
15
+ end
16
+
17
+ it "is compatible with CC functionality" do
18
+ test_email = Mailer.test_email cc: "Carl Test <cc@example.com>", headers: {"Priority" => "urgent", "Sensitivity" => "private"}
19
+ @delivery_method.deliver!(test_email)
20
+
21
+ expect(@delivery_method.data[:content][:headers]).to eq({cc: "cc@example.com", "Priority" => "urgent", "Sensitivity" => "private"})
22
+ end
23
+
24
+ it "does not pass inappropriate headers through to the API" do
25
+ test_email = Mailer.test_email headers: {content_type: "POSTSCRIPT", "Priority" => "urgent", "Sensitivity" => "private"}
26
+ @delivery_method.deliver!(test_email)
27
+
28
+ expect(@delivery_method.data[:content][:headers]).to eq({"Priority" => "urgent", "Sensitivity" => "private"})
29
+ end
30
+
31
+ end
32
+ end
33
+
@@ -0,0 +1,63 @@
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 "Inline Content" do
11
+ it "sets the subject" do
12
+ test_email = Mailer.test_email
13
+ @delivery_method.deliver!(test_email)
14
+
15
+ expect(@delivery_method.data[:content][:subject]).to eq("Test Email")
16
+ end
17
+
18
+ it "handles single part content" do
19
+ test_email = Mailer.test_email
20
+ @delivery_method.deliver!(test_email)
21
+
22
+ expect(@delivery_method.data[:content][:text]).to eq("Hello, Testing!")
23
+ expect(@delivery_method.data[:content].has_key?(:html)).to eq(false)
24
+ end
25
+
26
+ it "handles multi-part content" do
27
+ test_email = Mailer.test_email html_part: "<h1>Hello, Testing!</h1>"
28
+ @delivery_method.deliver!(test_email)
29
+
30
+ expect(@delivery_method.data[:content][:text]).to eq("Hello, Testing!")
31
+ expect(@delivery_method.data[:content][:html]).to eq("<h1>Hello, Testing!</h1>")
32
+ end
33
+
34
+ it "supports HTML-only content as a configuration setting" do
35
+ SparkPostRails.configure do |c|
36
+ c.html_content_only = true
37
+ end
38
+
39
+ test_email = Mailer.test_email
40
+ @delivery_method.deliver!(test_email)
41
+
42
+ expect(@delivery_method.data[:content].has_key?(:text)).to eq(false)
43
+ expect(@delivery_method.data[:content][:html]).to eq("Hello, Testing!")
44
+ end
45
+
46
+ it "supports HTML-only content as an option on an individual transmission" do
47
+ test_email = Mailer.test_email sparkpost_data: {html_content_only: true}
48
+ @delivery_method.deliver!(test_email)
49
+
50
+ expect(@delivery_method.data[:content].has_key?(:text)).to eq(false)
51
+ expect(@delivery_method.data[:content][:html]).to eq("Hello, Testing!")
52
+ end
53
+
54
+ it "should not include template details" do
55
+ test_email = Mailer.test_email
56
+ @delivery_method.deliver!(test_email)
57
+
58
+ expect(@delivery_method.data[:content].has_key?(:template_id)).to eq(false)
59
+ expect(@delivery_method.data[:content].has_key?(:use_draft_template)).to eq(false)
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,49 @@
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 "Inline css" do
11
+ it "handles inline_css set in the configuration" do
12
+ SparkPostRails.configure do |c|
13
+ c.inline_css = true
14
+ end
15
+
16
+ test_email = Mailer.test_email
17
+ @delivery_method.deliver!(test_email)
18
+
19
+ expect(@delivery_method.data[:options][:inline_css]).to eq(true)
20
+ end
21
+
22
+ it "handles inline_css set on an individual message" do
23
+ test_email = Mailer.test_email sparkpost_data: {inline_css: true}
24
+
25
+ @delivery_method.deliver!(test_email)
26
+
27
+ expect(@delivery_method.data[:options][:inline_css]).to eq(true)
28
+ end
29
+
30
+ it "handles the value on an individual message overriding configuration" do
31
+ SparkPostRails.configure do |c|
32
+ c.inline_css = false
33
+ end
34
+
35
+ test_email = Mailer.test_email sparkpost_data: {inline_css: true}
36
+
37
+ @delivery_method.deliver!(test_email)
38
+
39
+ expect(@delivery_method.data[:options][:inline_css]).to eq(true)
40
+ end
41
+
42
+ it "handles a default setting of inline_css" do
43
+ test_email = Mailer.test_email
44
+ @delivery_method.deliver!(test_email)
45
+
46
+ expect(@delivery_method.data[:options][:inline_css]).to eq(false)
47
+ end
48
+ end
49
+ 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 "IP Pool" do
11
+ it "handles ip_pool set in the configuration" do
12
+ SparkPostRails.configure do |c|
13
+ c.ip_pool = "default_ip"
14
+ end
15
+
16
+ test_email = Mailer.test_email
17
+ @delivery_method.deliver!(test_email)
18
+
19
+ expect(@delivery_method.data[:options][:ip_pool]).to eq("default_ip")
20
+ end
21
+
22
+ it "handles ip_pool set on an individual message" do
23
+ test_email = Mailer.test_email sparkpost_data: {ip_pool: "message_ip"}
24
+
25
+ @delivery_method.deliver!(test_email)
26
+
27
+ expect(@delivery_method.data[:options][:ip_pool]).to eq("message_ip")
28
+ end
29
+
30
+ it "handles the value on an individual message overriding configuration" do
31
+ SparkPostRails.configure do |c|
32
+ c.ip_pool = "default_ip"
33
+ end
34
+
35
+ test_email = Mailer.test_email sparkpost_data: {ip_pool: "message_ip"}
36
+
37
+ @delivery_method.deliver!(test_email)
38
+
39
+ expect(@delivery_method.data[:options][:ip_pool]).to eq("message_ip")
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[:options].has_key?(:ip_pool)).to eq(false)
47
+ end
48
+
49
+ end
50
+ end
@@ -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
@@ -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
+