Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Artheanos committed Mar 22, 2024
1 parent 7fc010a commit c3abf8b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
15 changes: 7 additions & 8 deletions CHANGELOG.md
Expand Up @@ -5,15 +5,14 @@
- `sandbox` to use Mailtrap sandbox API
- `inbox_id` required when using Mailtrap sandbox API


- Removed Sending namespace, affected classes:
- `Mailtrap::Sending::Client`
- `Mailtrap::Sending::Error`
- `Mailtrap::Sending::AttachmentContentError`
- `Mailtrap::Sending::AuthorizationError`
- `Mailtrap::Sending::MailSizeError`
- `Mailtrap::Sending::RateLimitError`
- `Mailtrap::Sending::RejectionError`
- `Mailtrap::Sending::Client` -> `Mailtrap::Client`
- `Mailtrap::Sending::Error` -> `Mailtrap::Error`
- `Mailtrap::Sending::AttachmentContentError` -> `Mailtrap::AttachmentContentError`
- `Mailtrap::Sending::AuthorizationError` -> `Mailtrap::AuthorizationError`
- `Mailtrap::Sending::MailSizeError` -> `Mailtrap::MailSizeError`
- `Mailtrap::Sending::RateLimitError` -> `Mailtrap::RateLimitError`
- `Mailtrap::Sending::RejectionError` -> `Mailtrap::RejectionError`

## [1.2.2] - 2023-11-01

Expand Down
4 changes: 3 additions & 1 deletion lib/mailtrap/action_mailer/delivery_method.rb
Expand Up @@ -5,6 +5,8 @@ module ActionMailer
class DeliveryMethod
attr_accessor :settings

ALLOWED_PARAMS = %i[api_key api_host api_port bulk sandbox inbox_id].freeze

def initialize(settings)
self.settings = settings
end
Expand All @@ -18,7 +20,7 @@ def deliver!(message)
private

def client
@client ||= Mailtrap::Client.new(**settings.slice(:api_key, :api_host, :api_port))
@client ||= Mailtrap::Client.new(**settings.slice(*ALLOWED_PARAMS))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/mailtrap/client.rb
Expand Up @@ -7,7 +7,7 @@
module Mailtrap
class Client
SENDING_API_HOST = 'send.api.mailtrap.io'
BULK_SENDING_API_HOST = 'send.api.mailtrap.io'
BULK_SENDING_API_HOST = 'bulk.api.mailtrap.io'
SANDBOX_API_HOST = 'sandbox.api.mailtrap.io'
API_PORT = 443

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 14 additions & 9 deletions spec/mailtrap/action_mailer/delivery_method_spec.rb
Expand Up @@ -7,7 +7,18 @@
subject(:deliver!) { described_class.new(settings).deliver!(message) }

let(:settings) { { api_key: 'correct-api-key' } }
let(:message) { Mail::Message.new(params) }
let(:message) do
Mail::Message.new(params).tap do |message|
message.text_part = 'Some text'
message.html_part = '<div>HTML part</div>'
message.headers('X-Special-Domain-Specific-Header': 'SecretValue')
message.headers('One-more-custom-header': 'CustomValue')
message.attachments['file.txt'] = File.read('spec/fixtures/files/attachments/file.txt')
message.attachments['file.txt'].content_id = '<txt_content_id@test.mail>'
message.attachments.inline['file.png'] = File.read('spec/fixtures/files/attachments/file.png')
message.attachments['file.png'].content_id = '<png_content_id@test.mail>'
end
end
let(:params) do
{
from: 'Mailtrap Test <mailtrap@mailtrap.io>',
Expand All @@ -32,18 +43,12 @@

before do
allow(::Mail::ContentTypeField).to receive(:generate_boundary).and_return('--==_mimepart_random_boundary')
message.text_part = 'Some text'
message.html_part = '<div>HTML part</div>'
message.headers('X-Special-Domain-Specific-Header': 'SecretValue')
message.headers('One-more-custom-header': 'CustomValue')
message.attachments['file.txt'] = File.read('spec/fixtures/files/attachments/file.txt')
message.attachments['file.txt'].content_id = '<txt_content_id@test.mail>'
message.attachments.inline['file.png'] = File.read('spec/fixtures/files/attachments/file.png')
message.attachments['file.png'].content_id = '<png_content_id@test.mail>'
allow(Mailtrap::Client).to receive(:new).and_call_original
end

it 'converts the message and sends via API' do
expect(deliver!).to eq({ success: true, message_ids: expected_message_ids })
expect(Mailtrap::Client).to have_received(:new).with(api_key: 'correct-api-key')
end
end
end

0 comments on commit c3abf8b

Please sign in to comment.