mailgun-ruby 1.4.5 → 1.4.6
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -1
- data/README.md +3 -1
- data/lib/mailgun/api_keys/api_keys.rb +2 -2
- data/lib/mailgun/client.rb +1 -1
- data/lib/mailgun/domains/domain_keys.rb +5 -5
- data/lib/mailgun/domains/domains.rb +12 -9
- data/lib/mailgun/events/events.rb +1 -1
- data/lib/mailgun/helpers/api_version_checker.rb +23 -12
- data/lib/mailgun/helpers/deprecation.rb +32 -0
- data/lib/mailgun/lists/mailing_lists.rb +250 -0
- data/lib/mailgun/messages/message_builder.rb +17 -7
- data/lib/mailgun/response.rb +1 -1
- data/lib/mailgun/routes/routes.rb +98 -0
- data/lib/mailgun/tags/analytics_tags.rb +2 -2
- data/lib/mailgun/tags/tags.rb +16 -8
- data/lib/mailgun/version.rb +1 -1
- data/lib/mailgun/webhooks/account_webhooks.rb +2 -2
- data/lib/mailgun/webhooks/webhooks.rb +17 -9
- data/lib/mailgun.rb +1 -0
- metadata +6 -326
- data/.github/workflows/ci.yml +0 -49
- data/.github_changelog_generator +0 -1
- data/.gitignore +0 -24
- data/.rubocop.yml +0 -68
- data/.ruby-env.yml.example +0 -13
- data/Gemfile +0 -9
- data/Rakefile +0 -32
- data/docs/AccountWebhooks.md +0 -55
- data/docs/AnalyticsTags.md +0 -63
- data/docs/ApiKeys.md +0 -65
- data/docs/DomainKeys.md +0 -49
- data/docs/Domains.md +0 -82
- data/docs/EmailValidation.md +0 -34
- data/docs/Events.md +0 -48
- data/docs/Logs.md +0 -67
- data/docs/MessageBuilder.md +0 -120
- data/docs/Metrics.md +0 -108
- data/docs/OptInHandler.md +0 -103
- data/docs/Snippets.md +0 -519
- data/docs/Subaccounts.md +0 -68
- data/docs/Suppressions.md +0 -92
- data/docs/Templates.md +0 -92
- data/docs/Webhooks.md +0 -65
- data/docs/railgun/EmailValidation.md +0 -34
- data/docs/railgun/Overview.md +0 -11
- data/docs/railgun/Parameters.md +0 -83
- data/mailgun.gemspec +0 -47
- data/spec/integration/account_webhooks_spec.rb +0 -57
- data/spec/integration/analytics_tags_spec.rb +0 -54
- data/spec/integration/api_keys_spec.rb +0 -50
- data/spec/integration/bounces_spec.rb +0 -45
- data/spec/integration/campaign_spec.rb +0 -62
- data/spec/integration/complaints_spec.rb +0 -40
- data/spec/integration/domain_keys_spec.rb +0 -124
- data/spec/integration/domains_spec.rb +0 -201
- data/spec/integration/email_validation_spec.rb +0 -73
- data/spec/integration/events_spec.rb +0 -28
- data/spec/integration/list_members_spec.rb +0 -64
- data/spec/integration/list_spec.rb +0 -59
- data/spec/integration/logs_spec.rb +0 -105
- data/spec/integration/mailer_spec.rb +0 -65
- data/spec/integration/mailgun_spec.rb +0 -198
- data/spec/integration/messages/sample_data/mime.txt +0 -38
- data/spec/integration/metrics_spec.rb +0 -224
- data/spec/integration/routes_spec.rb +0 -91
- data/spec/integration/stats_spec.rb +0 -17
- data/spec/integration/subaccounts_spec.rb +0 -57
- data/spec/integration/suppressions_spec.rb +0 -320
- data/spec/integration/templates_spec.rb +0 -137
- data/spec/integration/unsubscribes_spec.rb +0 -44
- data/spec/integration/webhook_spec.rb +0 -79
- data/spec/spec_helper.rb +0 -53
- data/spec/unit/client_spec.rb +0 -448
- data/spec/unit/connection/test_client.rb +0 -169
- data/spec/unit/events/events_spec.rb +0 -88
- data/spec/unit/exceptions/exceptions_spec.rb +0 -31
- data/spec/unit/helpers/api_version_checker_spec.rb +0 -206
- data/spec/unit/lists/opt_in_handler_spec.rb +0 -28
- data/spec/unit/mailgun_spec.rb +0 -171
- data/spec/unit/messages/batch_message_spec.rb +0 -148
- data/spec/unit/messages/message_builder_spec.rb +0 -745
- data/spec/unit/messages/sample_data/mailgun_icon.png +0 -0
- data/spec/unit/messages/sample_data/mime.txt +0 -38
- data/spec/unit/messages/sample_data/rackspace_logo.jpg +0 -0
- data/spec/unit/messages/sample_data/unknown.type +0 -0
- data/spec/unit/railgun/content_type_spec.rb +0 -89
- data/spec/unit/railgun/mailer_spec.rb +0 -391
- data/spec/unit/response_spec.rb +0 -225
- data/spec/unit/webhooks_spec.rb +0 -121
- data/vcr_cassettes/For_the_suppressions_handling_class/creates_a_single_bounce.yml +0 -55
- data/vcr_cassettes/account_webhooks.yml +0 -269
- data/vcr_cassettes/analytics_tags.yml +0 -187
- data/vcr_cassettes/api_keys.yml +0 -212
- data/vcr_cassettes/bounces.yml +0 -136
- data/vcr_cassettes/complaints.yml +0 -315
- data/vcr_cassettes/domains.todo.yml +0 -42
- data/vcr_cassettes/domains.yml +0 -1243
- data/vcr_cassettes/email_validation.yml +0 -152
- data/vcr_cassettes/events.yml +0 -69
- data/vcr_cassettes/exceptions-invalid-api-key.yml +0 -52
- data/vcr_cassettes/exceptions-invalid-data.yml +0 -52
- data/vcr_cassettes/exceptions-not-allowed.yml +0 -54
- data/vcr_cassettes/exceptions.yml +0 -92
- data/vcr_cassettes/list_members.yml +0 -328
- data/vcr_cassettes/logs.yml +0 -53
- data/vcr_cassettes/mailer_invalid_domain.yml +0 -109
- data/vcr_cassettes/mailing_list.todo.yml +0 -43
- data/vcr_cassettes/mailing_list.yml +0 -682
- data/vcr_cassettes/message_deliver.yml +0 -149
- data/vcr_cassettes/metrics.yml +0 -116
- data/vcr_cassettes/routes.yml +0 -359
- data/vcr_cassettes/send_message.yml +0 -158
- data/vcr_cassettes/stats.yml +0 -48
- data/vcr_cassettes/subaccounts.yml +0 -270
- data/vcr_cassettes/suppressions.yml +0 -1392
- data/vcr_cassettes/templates.yml +0 -1065
- data/vcr_cassettes/unsubscribes.yml +0 -401
- data/vcr_cassettes/webhooks.yml +0 -246
- data/vcr_cassettes/webhooks_v4.yml +0 -275
|
Binary file
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
X-SBRS: 5.6
|
|
2
|
-
X-SenderGroup: WHITELIST
|
|
3
|
-
X-MailFlowPolicy: $TRUSTED
|
|
4
|
-
DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=trstx.com; q=dns/txt; s=mx;
|
|
5
|
-
t=1381182797; h=Mime-Version: Content-Type: Subject: From: To:
|
|
6
|
-
Message-Id: Date: Sender: Content-Transfer-Encoding;
|
|
7
|
-
bh=r6P1omjKL3m7gDuZC6dZEJU6trgWm1IRwAJb8h4wtfg=; b=UPFaFGiuDx2yZjCmiMEji0fIXvGMNwXUsuaX4Ss9p5EUkqE25eYjeJaJZ5w5FK+t0jsUPZqu
|
|
8
|
-
FIH6sftQv7GBEbSktY6sv7dgv5q2yVlY8YNG7CXvUZdWmvwfQVvfL9j1RHJo9H3QpXT9c8bZ
|
|
9
|
-
p9rpYmqZtZEz2ZesPj4kzUaB0lU=
|
|
10
|
-
DomainKey-Signature: a=rsa-sha1; c=nofws; d=trstx.com; s=mx; q=dns;
|
|
11
|
-
h=Mime-Version: Content-Type: Subject: From: To: Message-Id: Date:
|
|
12
|
-
Sender: Content-Transfer-Encoding;
|
|
13
|
-
b=QUYQf9OP16DphNAjeF95+G7V6DaqL4FA+m1sjIEWHdLzrGTQkiYTpzJdne3lzSypB0DwaG
|
|
14
|
-
AT9zOhjjN64DWFOkJD2Ce5t6vfHa/GC3FCUMq3xz/Big94g+kOciawkHyUhCrmPyh/D7kWx1
|
|
15
|
-
J75UIAdmE9XQ9bCSPhZ2MRaOv7b8c=
|
|
16
|
-
Received: by luna.mailgun.net with HTTP; Mon, 07 Oct 2013 21:53:16 +0000
|
|
17
|
-
Content-Type: text/plain; charset="ascii"
|
|
18
|
-
Subject: Test Subject
|
|
19
|
-
From: <joe@example.com>
|
|
20
|
-
To: <bob@sample.com>
|
|
21
|
-
Message-ID: <20131007215316.27052.7818@example.com>
|
|
22
|
-
X-Mailgun-Sid: WyI4MzY1OSIsICJ0cmF2aXMuc3dpZW50ZWtAcmFja3NwYWasdfewNvbSIsICJjZjQ4Il0=
|
|
23
|
-
Date: Mon, 7 Oct 2013 21:53:17 +0000
|
|
24
|
-
Sender: <joe@example.com>
|
|
25
|
-
Content-Transfer-Encoding: 7bit
|
|
26
|
-
MIME-Version: 1.0
|
|
27
|
-
|
|
28
|
-
--3a8c26e9f23c4ac193606295aa17fa6f
|
|
29
|
-
Content-Type: text/plain; charset="ascii"
|
|
30
|
-
Content-Transfer-Encoding: 7bit
|
|
31
|
-
|
|
32
|
-
Testing some Mailgun awesomness!
|
|
33
|
-
--3a8c26e9f23c4ac193606295aa17fa6f
|
|
34
|
-
Content-Type: text/html; charset="ascii"
|
|
35
|
-
Content-Transfer-Encoding: 7bit
|
|
36
|
-
|
|
37
|
-
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">Test
|
|
38
|
-
--3a8c26e9f23c4ac193606295aa17fa6f--
|
|
Binary file
|
|
File without changes
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
require 'mailgun'
|
|
5
|
-
require 'railgun'
|
|
6
|
-
|
|
7
|
-
describe 'extract_body' do
|
|
8
|
-
let(:text_mail_option) do
|
|
9
|
-
{
|
|
10
|
-
from: 'bob@example.com',
|
|
11
|
-
to: 'sally@example.com',
|
|
12
|
-
subject: 'RAILGUN TEST SAMPLE',
|
|
13
|
-
body: text_content,
|
|
14
|
-
content_type: 'text/plain'
|
|
15
|
-
}
|
|
16
|
-
end
|
|
17
|
-
let(:text_content) { '[TEST] Hello, world.' }
|
|
18
|
-
|
|
19
|
-
let(:html_mail_option) do
|
|
20
|
-
{
|
|
21
|
-
from: 'bob@example.com',
|
|
22
|
-
to: 'sally@example.com',
|
|
23
|
-
subject: 'RAILGUN TEST SAMPLE',
|
|
24
|
-
body: html_content,
|
|
25
|
-
content_type: 'text/html'
|
|
26
|
-
}
|
|
27
|
-
end
|
|
28
|
-
let(:html_content) { '<h3> [TEST] </h3> <br/> Hello, world!' }
|
|
29
|
-
|
|
30
|
-
let(:amp_mail_option) do
|
|
31
|
-
{
|
|
32
|
-
from: 'bob@example.com',
|
|
33
|
-
to: 'sally@example.com',
|
|
34
|
-
subject: 'RAILGUN TEST SAMPLE',
|
|
35
|
-
body: amp_content,
|
|
36
|
-
content_type: 'text/x-amp-html'
|
|
37
|
-
}
|
|
38
|
-
end
|
|
39
|
-
let(:amp_content) { '<h3> [TEST] </h3> <br/> Hello from AMP!' }
|
|
40
|
-
|
|
41
|
-
context 'with <Content-Type: text/plain>' do
|
|
42
|
-
let(:sample_mail) { Mail.new(text_mail_option) }
|
|
43
|
-
|
|
44
|
-
it 'returns body text' do
|
|
45
|
-
expect(Railgun.extract_body_text(sample_mail)).to eq(text_content)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'does not return body html' do
|
|
49
|
-
expect(Railgun.extract_body_html(sample_mail)).to be_nil
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
context 'with <Content-Type: text/html>' do
|
|
54
|
-
let(:sample_mail) { Mail.new(html_mail_option) }
|
|
55
|
-
|
|
56
|
-
it 'does not return body text' do
|
|
57
|
-
expect(Railgun.extract_body_text(sample_mail)).to be_nil
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it 'returns body html' do
|
|
61
|
-
expect(Railgun.extract_body_html(sample_mail)).to eq(html_content)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
context 'with <Content-Type: multipart/alternative>' do
|
|
66
|
-
let(:text_mail) { Mail.new(text_mail_option) }
|
|
67
|
-
let(:html_mail) { Mail.new(html_mail_option) }
|
|
68
|
-
let(:amp_mail) { Mail.new(amp_mail_option) }
|
|
69
|
-
|
|
70
|
-
before do
|
|
71
|
-
@sample_mail = Mail::Part.new(content_type: 'multipart/alternative')
|
|
72
|
-
@sample_mail.add_part text_mail
|
|
73
|
-
@sample_mail.add_part amp_mail
|
|
74
|
-
@sample_mail.add_part html_mail
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it 'returns body text' do
|
|
78
|
-
expect(Railgun.extract_body_text(@sample_mail)).to eq(text_content)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it 'returns body html' do
|
|
82
|
-
expect(Railgun.extract_body_html(@sample_mail)).to eq(html_content)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'returns AMP html' do
|
|
86
|
-
expect(Railgun.extract_amp_html(@sample_mail)).to eq(amp_content)
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'json'
|
|
4
|
-
require 'logger'
|
|
5
|
-
require 'spec_helper'
|
|
6
|
-
require 'mailgun'
|
|
7
|
-
require 'railgun'
|
|
8
|
-
|
|
9
|
-
ActionMailer::Base.raise_delivery_errors = true
|
|
10
|
-
ActionMailer::Base.delivery_method = :test
|
|
11
|
-
Rails.logger = Logger.new('/dev/null')
|
|
12
|
-
Rails.logger.level = Logger::DEBUG
|
|
13
|
-
|
|
14
|
-
class UnitTestMailer < ActionMailer::Base
|
|
15
|
-
default from: 'unittest@example.org'
|
|
16
|
-
|
|
17
|
-
def plain_message(address, subject, headers)
|
|
18
|
-
headers(headers)
|
|
19
|
-
mail(to: address, subject: subject) do |format|
|
|
20
|
-
format.text { render plain: 'Test!' }
|
|
21
|
-
format.html { render html: '<p>Test!</p>'.html_safe }
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def message_with_attachment(address, subject)
|
|
26
|
-
attachments['info.txt'] = {
|
|
27
|
-
content: File.read('docs/railgun/Overview.md'),
|
|
28
|
-
mime_type: 'text/plain'
|
|
29
|
-
}
|
|
30
|
-
mail(to: address, subject: subject) do |format|
|
|
31
|
-
format.text { render plain: 'Test!' }
|
|
32
|
-
format.html { render html: '<p>Test!</p>'.html_safe }
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def message_with_template(address, subject, template_name)
|
|
37
|
-
mail(to: address, subject: subject, template: template_name) do |format|
|
|
38
|
-
format.text { render plain: 'Test!' }
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def message_with_domain(address, subject, domain)
|
|
43
|
-
mail(to: address, subject: subject, domain: domain) do |format|
|
|
44
|
-
format.text { render plain: 'Test!' }
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe 'Railgun::Mailer' do
|
|
50
|
-
it 'has a mailgun_client property which returns a Mailgun::Client' do
|
|
51
|
-
config = {
|
|
52
|
-
api_key: {},
|
|
53
|
-
domain: {}
|
|
54
|
-
}
|
|
55
|
-
@mailer_obj = Railgun::Mailer.new(config)
|
|
56
|
-
|
|
57
|
-
expect(@mailer_obj.mailgun_client).to be_a(Mailgun::Client)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
context 'when config does not have api_key or domain' do
|
|
61
|
-
it 'raises configuration error' do
|
|
62
|
-
config = {
|
|
63
|
-
api_key: {}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
expect { Railgun::Mailer.new(config) }.to raise_error(Railgun::ConfigurationError)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
context 'when fake_message_send is present in config' do
|
|
71
|
-
it 'enables test mode' do
|
|
72
|
-
config = {
|
|
73
|
-
api_key: {},
|
|
74
|
-
domain: {},
|
|
75
|
-
fake_message_send: true
|
|
76
|
-
}
|
|
77
|
-
client_double = double(Mailgun::Client)
|
|
78
|
-
allow(Mailgun::Client).to receive(:new).and_return(client_double)
|
|
79
|
-
expect(client_double).to receive(:enable_test_mode!)
|
|
80
|
-
|
|
81
|
-
Railgun::Mailer.new(config)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'properly creates a message body' do
|
|
86
|
-
message = UnitTestMailer.plain_message('test@example.org', 'Test!', {})
|
|
87
|
-
body = Railgun.transform_for_mailgun(message)
|
|
88
|
-
|
|
89
|
-
[:from, :subject, :text, :html, 'to'].each do |param|
|
|
90
|
-
expect(body).to include(param)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
expect(body[:from][0].value).to eq('unittest@example.org')
|
|
94
|
-
expect(body['to']).to eq(['test@example.org'])
|
|
95
|
-
expect(body[:subject]).to eq(['Test!'])
|
|
96
|
-
expect(body[:text]).to eq(['Test!'])
|
|
97
|
-
expect(body[:html]).to eq(['<p>Test!</p>'.html_safe])
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it 'adds options to message body' do
|
|
101
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {})
|
|
102
|
-
message.mailgun_options ||= {
|
|
103
|
-
'tracking-opens' => 'true'
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
body = Railgun.transform_for_mailgun(message)
|
|
107
|
-
|
|
108
|
-
expect(body).to include('o:tracking-opens')
|
|
109
|
-
expect(body['o:tracking-opens']).to eq('true')
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
it 'accepts frozen options to message body' do
|
|
113
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {})
|
|
114
|
-
message.mailgun_options ||= {
|
|
115
|
-
'tags' => ['some-tag']
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
body = Railgun.transform_for_mailgun(message)
|
|
119
|
-
|
|
120
|
-
expect(body).to include('o:tags')
|
|
121
|
-
expect(body['o:tags']).to eq(['some-tag'])
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
it 'adds variables to message body' do
|
|
125
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {})
|
|
126
|
-
message.mailgun_variables ||= {
|
|
127
|
-
'user' => { id: '1', name: 'tstark' }
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
body = Railgun.transform_for_mailgun(message)
|
|
131
|
-
|
|
132
|
-
expect(body).to include('v:user')
|
|
133
|
-
|
|
134
|
-
var_body = JSON.parse(body['v:user'])
|
|
135
|
-
expect(var_body).to include('id')
|
|
136
|
-
expect(var_body).to include('name')
|
|
137
|
-
expect(var_body['id']).to eq('1')
|
|
138
|
-
expect(var_body['name']).to eq('tstark')
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
it 'adds headers to message body' do
|
|
142
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {})
|
|
143
|
-
message.mailgun_headers ||= {
|
|
144
|
-
'x-unit-test' => 'true'
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
body = Railgun.transform_for_mailgun(message)
|
|
148
|
-
|
|
149
|
-
expect(body).to include('h:x-unit-test')
|
|
150
|
-
expect(body['h:x-unit-test']).to eq('true')
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
it 'adds headers to message body from mailer' do
|
|
154
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {
|
|
155
|
-
'x-unit-test-2' => 'true'
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
body = Railgun.transform_for_mailgun(message)
|
|
159
|
-
|
|
160
|
-
expect(body).to include('h:x-unit-test-2')
|
|
161
|
-
expect(body['h:x-unit-test-2']).to eq('true')
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
it 'properly handles headers that are passed as separate POST params' do
|
|
165
|
-
message = UnitTestMailer.plain_message(
|
|
166
|
-
'test@example.org', 'Test!',
|
|
167
|
-
{
|
|
168
|
-
# `From`, `To`, and `Subject` are set on the envelope, so they should be ignored as headers
|
|
169
|
-
'From' => 'units@example.net',
|
|
170
|
-
'To' => 'user@example.com',
|
|
171
|
-
'Subject' => 'This should disappear',
|
|
172
|
-
# If `Bcc` or `Cc` are set as headers, they should be carried over as POST params, not headers
|
|
173
|
-
'Bcc' => ['list@example.org'],
|
|
174
|
-
'Cc' => ['admin@example.com'],
|
|
175
|
-
# This is an arbitrary header and should be carried over properly
|
|
176
|
-
'X-Source' => 'unit tests'
|
|
177
|
-
}
|
|
178
|
-
)
|
|
179
|
-
|
|
180
|
-
body = Railgun.transform_for_mailgun(message)
|
|
181
|
-
|
|
182
|
-
%w[From To Subject].each do |header|
|
|
183
|
-
expect(body).not_to include("h:#{header}")
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
['bcc', 'cc', 'to', 'h:x-source'].each do |param|
|
|
187
|
-
expect(body).to include(param)
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
expect(body[:from][0].value).to eq('unittest@example.org')
|
|
191
|
-
expect(body['to']).to eq(['test@example.org'])
|
|
192
|
-
expect(body[:subject]).to eq(['Test!'])
|
|
193
|
-
expect(body[:text]).to eq(['Test!'])
|
|
194
|
-
expect(body[:html]).to eq(['<p>Test!</p>'.html_safe])
|
|
195
|
-
expect(body['bcc']).to eq(['list@example.org'])
|
|
196
|
-
expect(body['cc']).to eq(['admin@example.com'])
|
|
197
|
-
expect(body['h:x-source']).to eq('unit tests')
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
context 'when mailgun_variables are present' do
|
|
201
|
-
it 'accepts valid JSON and stores it as message[param].' do
|
|
202
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {}).tap do |message|
|
|
203
|
-
message.mailgun_variables = {
|
|
204
|
-
'my-data' => '{"key":"value"}'
|
|
205
|
-
}
|
|
206
|
-
end
|
|
207
|
-
body = Railgun.transform_for_mailgun(message)
|
|
208
|
-
expect(body['v:my-data']).to be_a(String)
|
|
209
|
-
expect(body['v:my-data'].to_s).to eq('{"key":"value"}')
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
it 'accepts a hash and appends as data to the message.' do
|
|
213
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {}).tap do |message|
|
|
214
|
-
message.mailgun_variables = {
|
|
215
|
-
'my-data' => { 'key' => 'value' }
|
|
216
|
-
}
|
|
217
|
-
end
|
|
218
|
-
body = Railgun.transform_for_mailgun(message)
|
|
219
|
-
|
|
220
|
-
expect(body['v:my-data']).to be_a(String)
|
|
221
|
-
expect(body['v:my-data'].to_s).to eq('{"key":"value"}')
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
it 'accepts string values' do
|
|
225
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {}).tap do |message|
|
|
226
|
-
message.mailgun_variables = {
|
|
227
|
-
'my-data' => 'String Value.'
|
|
228
|
-
}
|
|
229
|
-
end
|
|
230
|
-
body = Railgun.transform_for_mailgun(message)
|
|
231
|
-
|
|
232
|
-
expect(body['v:my-data']).to be_a(String)
|
|
233
|
-
expect(body['v:my-data'].to_s).to eq('String Value.')
|
|
234
|
-
end
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
it 'properly adds attachments' do
|
|
238
|
-
message = UnitTestMailer.message_with_attachment('test@example.org', '')
|
|
239
|
-
body = Railgun.transform_for_mailgun(message)
|
|
240
|
-
|
|
241
|
-
expect(body).to include(:attachment)
|
|
242
|
-
attachment = body[:attachment][0]
|
|
243
|
-
|
|
244
|
-
expect(attachment.filename).to eq('info.txt')
|
|
245
|
-
expect(attachment.content_type).to eq('text/plain')
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
it 'delivers!' do
|
|
249
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {})
|
|
250
|
-
message.deliver_now
|
|
251
|
-
|
|
252
|
-
expect(ActionMailer::Base.deliveries).to include(message)
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
it 'ignores `reply-to` in headers' do
|
|
256
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {
|
|
257
|
-
'reply-to' => 'user@example.com'
|
|
258
|
-
})
|
|
259
|
-
message.mailgun_headers = {
|
|
260
|
-
'Reply-To' => 'administrator@example.org'
|
|
261
|
-
}
|
|
262
|
-
message.headers({ 'REPLY-TO' => 'admin@example.net' })
|
|
263
|
-
message.reply_to = 'dude@example.com.au'
|
|
264
|
-
|
|
265
|
-
body = Railgun.transform_for_mailgun(message)
|
|
266
|
-
expect(body).to include('h:reply-to')
|
|
267
|
-
expect(body).not_to include('h:Reply-To')
|
|
268
|
-
expect(body['h:reply-to']).to eq('dude@example.com.au')
|
|
269
|
-
end
|
|
270
|
-
|
|
271
|
-
it 'ignores `mime-version` in headers' do
|
|
272
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {
|
|
273
|
-
'mime-version' => '1.0'
|
|
274
|
-
})
|
|
275
|
-
message.mailgun_headers = {
|
|
276
|
-
'Mime-Version' => '1.1'
|
|
277
|
-
}
|
|
278
|
-
message.headers({ 'MIME-VERSION' => '1.2' })
|
|
279
|
-
|
|
280
|
-
body = Railgun.transform_for_mailgun(message)
|
|
281
|
-
expect(body).not_to include('h:mime-version')
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
it 'treats `headers()` names as case-insensitve' do
|
|
285
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {
|
|
286
|
-
'X-BIG-VALUE' => 1
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
body = Railgun.transform_for_mailgun(message)
|
|
290
|
-
expect(body).to include('h:x-big-value')
|
|
291
|
-
expect(body['h:x-big-value']).to eq('1')
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
it 'treats `mailgun_headers` names as case-insensitive' do
|
|
295
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {})
|
|
296
|
-
message.mailgun_headers = {
|
|
297
|
-
'X-BIG-VALUE' => 1
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
body = Railgun.transform_for_mailgun(message)
|
|
301
|
-
expect(body).to include('h:x-big-value')
|
|
302
|
-
expect(body['h:x-big-value']).to eq('1')
|
|
303
|
-
end
|
|
304
|
-
|
|
305
|
-
it 'handles multi-value, mixed case headers correctly' do
|
|
306
|
-
message = UnitTestMailer.plain_message('test@example.org', '', {})
|
|
307
|
-
message.headers({
|
|
308
|
-
'x-neat-header' => 'foo',
|
|
309
|
-
'X-Neat-Header' => 'bar',
|
|
310
|
-
'X-NEAT-HEADER' => 'zoop'
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
body = Railgun.transform_for_mailgun(message)
|
|
314
|
-
expect(body).to include('h:x-neat-header')
|
|
315
|
-
expect(body['h:x-neat-header']).to include('foo')
|
|
316
|
-
expect(body['h:x-neat-header']).to include('bar')
|
|
317
|
-
expect(body['h:x-neat-header']).to include('zoop')
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
context 'when message with template' do
|
|
321
|
-
it 'adds template header to message from mailer params' do
|
|
322
|
-
template_name = 'template.name'
|
|
323
|
-
message = UnitTestMailer.message_with_template('test@example.org', '', template_name)
|
|
324
|
-
|
|
325
|
-
body = Railgun.transform_for_mailgun(message)
|
|
326
|
-
|
|
327
|
-
expect(body).to include('template')
|
|
328
|
-
expect(body['template']).to eq(template_name)
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
context 'when mailgun_template_variables are assigned' do
|
|
332
|
-
it 'adds template variables to message body' do
|
|
333
|
-
message = UnitTestMailer.message_with_template('test@example.org', '', 'template.name')
|
|
334
|
-
version = 'version_1'
|
|
335
|
-
message.mailgun_template_variables ||= {
|
|
336
|
-
'version' => version,
|
|
337
|
-
'text' => 'yes'
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
body = Railgun.transform_for_mailgun(message)
|
|
341
|
-
|
|
342
|
-
expect(body).to include('t:version')
|
|
343
|
-
expect(body['t:version']).to eq('version_1')
|
|
344
|
-
expect(body).to include('t:text')
|
|
345
|
-
expect(body['t:text']).to eq('yes')
|
|
346
|
-
end
|
|
347
|
-
end
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
describe 'deliver!' do
|
|
351
|
-
let(:config) do
|
|
352
|
-
{
|
|
353
|
-
api_key: 'api_key',
|
|
354
|
-
domain: 'domain'
|
|
355
|
-
}
|
|
356
|
-
end
|
|
357
|
-
let(:mail) { UnitTestMailer.plain_message('test@example.org', '', {}) }
|
|
358
|
-
let(:response) do
|
|
359
|
-
response = Struct.new(:code, :id)
|
|
360
|
-
response.new(200, rand(50..100))
|
|
361
|
-
end
|
|
362
|
-
|
|
363
|
-
it 'initiates client message send' do
|
|
364
|
-
result = { from: 'test@example.org' }
|
|
365
|
-
allow(Railgun).to receive(:transform_for_mailgun).and_return(result)
|
|
366
|
-
|
|
367
|
-
expect_any_instance_of(Mailgun::Client).to receive(:send_message)
|
|
368
|
-
.with(config[:domain], result)
|
|
369
|
-
.and_return(response)
|
|
370
|
-
Railgun::Mailer.new(config).deliver!(mail)
|
|
371
|
-
end
|
|
372
|
-
|
|
373
|
-
it 'returns response' do
|
|
374
|
-
expect_any_instance_of(Mailgun::Client).to receive(:send_message).and_return(response)
|
|
375
|
-
expect(Railgun::Mailer.new(config).deliver!(mail)).to eq(response)
|
|
376
|
-
end
|
|
377
|
-
|
|
378
|
-
context 'when domain is provided in arguments' do
|
|
379
|
-
let(:new_domain) { 'new_domain' }
|
|
380
|
-
let(:mail) { UnitTestMailer.message_with_domain('test@example.org', '', new_domain) }
|
|
381
|
-
|
|
382
|
-
it 'uses provided domain' do
|
|
383
|
-
result = { from: 'test@example.org' }
|
|
384
|
-
allow(Railgun).to receive(:transform_for_mailgun).and_return(result)
|
|
385
|
-
expect_any_instance_of(Mailgun::Client).to receive(:send_message)
|
|
386
|
-
.with(new_domain, result).and_return(response)
|
|
387
|
-
Railgun::Mailer.new(config).deliver!(mail)
|
|
388
|
-
end
|
|
389
|
-
end
|
|
390
|
-
end
|
|
391
|
-
end
|