From c99cac0d13fcdffadc83ee9c7199e284e8cd4cf5 Mon Sep 17 00:00:00 2001 From: "standard-ruby-action[bot]" Date: Mon, 28 Oct 2024 14:38:41 +0000 Subject: [PATCH] Apply Standard Ruby autofixes --- lib/mail-ses.rb | 6 +- lib/mail/ses.rb | 12 +-- lib/mail/ses/message_validator.rb | 4 +- lib/mail/ses/options_builder.rb | 14 ++-- lib/mail/ses/version.rb | 2 +- spec/mail_ses_spec.rb | 94 +++++++++++------------ spec/options_builder_spec.rb | 120 +++++++++++++++--------------- spec/spec_helper.rb | 10 +-- 8 files changed, 131 insertions(+), 131 deletions(-) diff --git a/lib/mail-ses.rb b/lib/mail-ses.rb index e641948..996e5ea 100644 --- a/lib/mail-ses.rb +++ b/lib/mail-ses.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'aws-sdk-sesv2' -require 'mail' -require 'mail/ses' +require "aws-sdk-sesv2" +require "mail" +require "mail/ses" diff --git a/lib/mail/ses.rb b/lib/mail/ses.rb index b18257a..040495f 100644 --- a/lib/mail/ses.rb +++ b/lib/mail/ses.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'mail/ses/version' -require 'mail/ses/message_validator' -require 'mail/ses/options_builder' +require "mail/ses/version" +require "mail/ses/message_validator" +require "mail/ses/options_builder" module Mail # Mail delivery method handler for AWS SES @@ -21,7 +21,7 @@ def initialize(options = {}) @mail_options = options.delete(:mail_options) || {} @error_handler = options.delete(:error_handler) - raise ArgumentError.new(':error_handler must be a Proc') if @error_handler && !@error_handler.is_a?(Proc) + raise ArgumentError.new(":error_handler must be a Proc") if @error_handler && !@error_handler.is_a?(Proc) @settings = { return_response: options.delete(:return_response), @@ -46,9 +46,9 @@ def deliver!(message, options = {}) begin response = client.send_email(send_options) - message.message_id = "#{response.to_h[:message_id]}@#{settings[:message_id_domain] || 'email.amazonses.com'}" + message.message_id = "#{response.to_h[:message_id]}@#{settings[:message_id_domain] || "email.amazonses.com"}" settings[:return_response] ? response : self - rescue StandardError => e + rescue => e handle_error(e, send_options) end end diff --git a/lib/mail/ses/message_validator.rb b/lib/mail/ses/message_validator.rb index c8d17d5..7a90e3e 100644 --- a/lib/mail/ses/message_validator.rb +++ b/lib/mail/ses/message_validator.rb @@ -21,7 +21,7 @@ def validate def validate_class return if @message.is_a?(Mail::Message) - raise ArgumentError.new('mail must be an instance of Mail::Message class') + raise ArgumentError.new("mail must be an instance of Mail::Message class") end def validate_delivery_params @@ -31,7 +31,7 @@ def validate_delivery_params def validate_attachments return unless @message.has_attachments? && @message.text_part.nil? && @message.html_part.nil? - raise ArgumentError.new('Attachment provided without message body') + raise ArgumentError.new("Attachment provided without message body") end end end diff --git a/lib/mail/ses/options_builder.rb b/lib/mail/ses/options_builder.rb index 1bde316..eb50a78 100644 --- a/lib/mail/ses/options_builder.rb +++ b/lib/mail/ses/options_builder.rb @@ -5,12 +5,12 @@ class SES # Builds options for Aws::SESV2::Client#send_email class OptionsBuilder SES_FIELDS = %i[ from_email_address - from_email_address_identity_arn - reply_to_addresses - feedback_forwarding_email_address - feedback_forwarding_email_address_identity_arn - email_tags - configuration_set_name ].freeze + from_email_address_identity_arn + reply_to_addresses + feedback_forwarding_email_address + feedback_forwarding_email_address_identity_arn + email_tags + configuration_set_name ].freeze # message - The Mail::Message object to be sent. # options - The Hash options which override any defaults @@ -41,7 +41,7 @@ def message_options cc_addresses: extract_value(:cc) || [], bcc_addresses: extract_value(:bcc) || [] }, - content: { raw: { data: @message.to_s } } + content: {raw: {data: @message.to_s}} }.compact end diff --git a/lib/mail/ses/version.rb b/lib/mail/ses/version.rb index 223d74b..e14e2d3 100644 --- a/lib/mail/ses/version.rb +++ b/lib/mail/ses/version.rb @@ -2,6 +2,6 @@ module Mail class SES - VERSION = '1.1.0' + VERSION = "1.1.0" end end diff --git a/spec/mail_ses_spec.rb b/spec/mail_ses_spec.rb index 3578ff9..0df66a6 100644 --- a/spec/mail_ses_spec.rb +++ b/spec/mail_ses_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe Mail::SES do - let(:ses_options) { { stub_responses: true } } + let(:ses_options) { {stub_responses: true} } let(:ses) do described_class.new(ses_options) @@ -11,75 +11,75 @@ let(:mail) do Mail.new do - from 'from@abc.com' + from "from@abc.com" to %w[to1@def.com to2@xyz.com] cc %w[cc1@xyz.com cc2@def.com] bcc %w[bcc1@abc.com bcc2@def.com] - body 'This is the body' + body "This is the body" end end - describe '::VERSION' do + describe "::VERSION" do it { expect(described_class::VERSION).to match(/\A\d+\.\d+\.\d+/) } end - describe '#settings' do + describe "#settings" do it do expect(ses).to respond_to(:settings, :settings=) expect(ses.settings).to eq(return_response: nil, message_id_domain: nil) end end - describe '#initialize' do - it 'accepts valid :error_handler' do + describe "#initialize" do + it "accepts valid :error_handler" do expect(described_class.new(ses_options)).to be_a(Mail::SES) end - it 'accepts valid :error_handler' do + it "accepts valid :error_handler" do expect(described_class.new(ses_options.merge(error_handler: ->(a, b) {}))).to be_a(Mail::SES) end - it 'rejects invalid :error_handler' do - expect { described_class.new(ses_options.merge(error_handler: 'foobar')) }.to raise_error(ArgumentError, ':error_handler must be a Proc') + it "rejects invalid :error_handler" do + expect { described_class.new(ses_options.merge(error_handler: "foobar")) }.to raise_error(ArgumentError, ":error_handler must be a Proc") end - it 'handles :use_iam_profile option' do - allow_any_instance_of(Aws::InstanceProfileCredentials).to receive(:get_credentials).and_return('{}') + it "handles :use_iam_profile option" do + allow_any_instance_of(Aws::InstanceProfileCredentials).to receive(:get_credentials).and_return("{}") ses = described_class.new(ses_options.merge(use_iam_profile: true)) expect(ses.client.config.credentials).to be_a(Aws::InstanceProfileCredentials) end - it 'passes through options to AWS' do + it "passes through options to AWS" do ses = described_class.new(ses_options.merge(log_level: :debug, retry_limit: 5)) expect(ses.client.config.log_level).to eq :debug expect(ses.client.config.retry_limit).to eq 5 end end - describe '#deliver!' do - it 'validates that mail is a Mail' do - expect { ses.deliver!(foo: :bar) }.to raise_error(ArgumentError, 'mail must be an instance of Mail::Message class') + describe "#deliver!" do + it "validates that mail is a Mail" do + expect { ses.deliver!(foo: :bar) }.to raise_error(ArgumentError, "mail must be an instance of Mail::Message class") end - it 'validates integrity of Mail' do - expect { ses.deliver!(Mail.new) }.to raise_error(ArgumentError, 'SMTP From address may not be blank: nil') - expect { ses.deliver!(Mail.new { from 'foo@bar.com' }) }.to raise_error(ArgumentError, 'SMTP To address may not be blank: []') + it "validates integrity of Mail" do + expect { ses.deliver!(Mail.new) }.to raise_error(ArgumentError, "SMTP From address may not be blank: nil") + expect { ses.deliver!(Mail.new { from "foo@bar.com" }) }.to raise_error(ArgumentError, "SMTP To address may not be blank: []") end - it 'validates attachment without body' do + it "validates attachment without body" do mail.body = nil mail.add_file __FILE__ - expect { ses.deliver!(mail) }.to raise_error(ArgumentError, 'Attachment provided without message body') + expect { ses.deliver!(mail) }.to raise_error(ArgumentError, "Attachment provided without message body") end - context 'when options set' do - before { allow(mail).to receive(:to_s).and_return('Fixed message body') } - let(:ses_options) { { stub_responses: true, mail_options: { from_email_address: 'foo@bar.com', from_email_address_identity_arn: 'sa1' } } } + context "when options set" do + before { allow(mail).to receive(:to_s).and_return("Fixed message body") } + let(:ses_options) { {stub_responses: true, mail_options: {from_email_address: "foo@bar.com", from_email_address_identity_arn: "sa1"}} } let(:exp) do { - from_email_address: 'foo@bar.com', - from_email_address_identity_arn: 'sa2', + from_email_address: "foo@bar.com", + from_email_address_identity_arn: "sa2", destination: { to_addresses: %w[to1@def.com to2@xyz.com], cc_addresses: %w[cc1@xyz.com cc2@def.com], @@ -87,58 +87,58 @@ }, content: { raw: { - data: 'Fixed message body' + data: "Fixed message body" } } } end - it 'allows pass-thru and override of default options' do + it "allows pass-thru and override of default options" do expect(ses.client).to receive(:send_email).with(exp) - ses.deliver!(mail, from_email_address_identity_arn: 'sa2') + ses.deliver!(mail, from_email_address_identity_arn: "sa2") end end context "without message_id_domain config" do - it 'sets the default domain as mail.message_id' do + it "sets the default domain as mail.message_id" do ses.deliver!(mail) - expect(mail.message_id).to eq('OutboundMessageId@email.amazonses.com') + expect(mail.message_id).to eq("OutboundMessageId@email.amazonses.com") end end context "with message_id_domain config" do - let(:ses_options) { { stub_responses: true, message_id_domain: 'eu-west-1.amazonses.com' } } - it 'sets as mail.message_id with the configured domain' do + let(:ses_options) { {stub_responses: true, message_id_domain: "eu-west-1.amazonses.com"} } + it "sets as mail.message_id with the configured domain" do ses.deliver!(mail) - expect(mail.message_id).to eq('OutboundMessageId@eu-west-1.amazonses.com') + expect(mail.message_id).to eq("OutboundMessageId@eu-west-1.amazonses.com") end end - it 'returns the AWS response' do + it "returns the AWS response" do expect(ses.deliver!(mail)).to be_a(Mail::SES) end - context 'when :return_response set' do - let(:ses_options) { { stub_responses: true, return_response: true } } + context "when :return_response set" do + let(:ses_options) { {stub_responses: true, return_response: true} } - it 'returns the AWS response' do + it "returns the AWS response" do expect(ses.deliver!(mail)).to be_a(Seahorse::Client::Response) end end - context 'error handling' do - before { allow_any_instance_of(Aws::SESV2::Client).to receive(:send_email).and_raise(RuntimeError.new('test')) } + context "error handling" do + before { allow_any_instance_of(Aws::SESV2::Client).to receive(:send_email).and_raise(RuntimeError.new("test")) } - context 'when :error_handler not set' do - it 'raises the error' do - expect { ses.deliver!(mail) }.to raise_error(RuntimeError, 'test') + context "when :error_handler not set" do + it "raises the error" do + expect { ses.deliver!(mail) }.to raise_error(RuntimeError, "test") end end - context 'when :error_handler set' do - let(:ses_options) { { stub_responses: true, error_handler: ->(a, b) {} } } + context "when :error_handler set" do + let(:ses_options) { {stub_responses: true, error_handler: ->(a, b) {}} } - it 'calls the error handler' do + it "calls the error handler" do expect(ses_options[:error_handler]).to receive(:call).and_call_original ses.deliver!(mail) end diff --git a/spec/options_builder_spec.rb b/spec/options_builder_spec.rb index e8451bc..dc697ed 100644 --- a/spec/options_builder_spec.rb +++ b/spec/options_builder_spec.rb @@ -1,37 +1,37 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" RSpec.describe Mail::SES::OptionsBuilder do - describe 'build' do + describe "build" do let(:mail) do Mail.new do from '"My From" ' - reply_to ['reply-to1@def.com', '', 'My Reply-To '] - to ['to1@def.com', 'My To ', ''] - cc ['', 'cc1@xyz.com', 'My CC '] - bcc ['My BCC ', '', 'bcc2@def.com'] - body 'This is the body' + reply_to ["reply-to1@def.com", "", "My Reply-To "] + to ["to1@def.com", "My To ", ""] + cc ["", "cc1@xyz.com", "My CC "] + bcc ["My BCC ", "", "bcc2@def.com"] + body "This is the body" end end let(:options) { {} } subject { described_class.new(mail, options).build } - before { allow(mail).to receive(:to_s).and_return('Fixed message body') } + before { allow(mail).to receive(:to_s).and_return("Fixed message body") } - context 'without options' do + context "without options" do let(:exp) do { - from_email_address: 'My From ', - reply_to_addresses: ['reply-to1@def.com', 'My Reply-To '], + from_email_address: "My From ", + reply_to_addresses: ["reply-to1@def.com", "My Reply-To "], destination: { - to_addresses: ['to1@def.com', 'My To '], - cc_addresses: ['cc1@xyz.com', 'My CC '], - bcc_addresses: ['My BCC ', 'bcc2@def.com'] + to_addresses: ["to1@def.com", "My To "], + cc_addresses: ["cc1@xyz.com", "My CC "], + bcc_addresses: ["My BCC ", "bcc2@def.com"] }, content: { raw: { - data: 'Fixed message body' + data: "Fixed message body" } } } @@ -39,13 +39,13 @@ it { expect(subject).to eq(exp) } - context 'without mail from' do - before { mail.from = nil } + context "without mail from" do + before { mail.from = nil } it { expect(subject.key?(:from_email_address)).to eq(false) } end - context 'without mail destination' do + context "without mail destination" do before do mail.to = nil mail.cc = nil @@ -64,36 +64,36 @@ end end - context 'with options' do + context "with options" do let(:options) do - { from_email_address: 'source@source.com', - from_email_address_identity_arn: 'from_arn', - feedback_forwarding_email_address: 'feedback@feedback.com', - feedback_forwarding_email_address_identity_arn: 'feedback_arn', - email_tags: [{ name: 'Name', value: 'Value' }], - configuration_set_name: 'configuration_set_name', - other: 'other' } + {from_email_address: "source@source.com", + from_email_address_identity_arn: "from_arn", + feedback_forwarding_email_address: "feedback@feedback.com", + feedback_forwarding_email_address_identity_arn: "feedback_arn", + email_tags: [{name: "Name", value: "Value"}], + configuration_set_name: "configuration_set_name", + other: "other"} end let(:exp) do { - from_email_address: 'source@source.com', - from_email_address_identity_arn: 'from_arn', - feedback_forwarding_email_address: 'feedback@feedback.com', - feedback_forwarding_email_address_identity_arn: 'feedback_arn', + from_email_address: "source@source.com", + from_email_address_identity_arn: "from_arn", + feedback_forwarding_email_address: "feedback@feedback.com", + feedback_forwarding_email_address_identity_arn: "feedback_arn", email_tags: [ - { name: 'Name', value: 'Value' } + {name: "Name", value: "Value"} ], - configuration_set_name: 'configuration_set_name', - reply_to_addresses: ['reply-to1@def.com', 'My Reply-To '], + configuration_set_name: "configuration_set_name", + reply_to_addresses: ["reply-to1@def.com", "My Reply-To "], destination: { - to_addresses: ['to1@def.com', 'My To '], - cc_addresses: ['cc1@xyz.com', 'My CC '], - bcc_addresses: ['My BCC ', 'bcc2@def.com'] + to_addresses: ["to1@def.com", "My To "], + cc_addresses: ["cc1@xyz.com", "My CC "], + bcc_addresses: ["My BCC ", "bcc2@def.com"] }, content: { raw: { - data: 'Fixed message body' + data: "Fixed message body" } } } @@ -102,55 +102,55 @@ it { expect(subject).to eq(exp) } end - context 'when addresses contain non-ascii chars' do + context "when addresses contain non-ascii chars" do let(:mail) do Mail.new do - from '了承ございます ' - reply_to ['了承ございます. ', '', 'My Reply-To '] - to ['to1@def.com', 'To テスト ', ''] - cc ['', 'cc1@xyz.com', 'CC テスト '] - bcc ['BCC テストです。 ', '', 'bcc2@def.com'] - body 'This is the body' + from "了承ございます " + reply_to ["了承ございます. ", "", "My Reply-To "] + to ["to1@def.com", "To テスト ", ""] + cc ["", "cc1@xyz.com", "CC テスト "] + bcc ["BCC テストです。 ", "", "bcc2@def.com"] + body "This is the body" end end let(:exp) do { - from_email_address: '=?UTF-8?B?5LqG5om/44GU44GW44GE44G+44GZ?= ', - reply_to_addresses: ['=?UTF-8?B?5LqG5om/44GU44GW44GE44G+44GZLg==?= ', 'My Reply-To '], + from_email_address: "=?UTF-8?B?5LqG5om/44GU44GW44GE44G+44GZ?= ", + reply_to_addresses: ["=?UTF-8?B?5LqG5om/44GU44GW44GE44G+44GZLg==?= ", "My Reply-To "], destination: { - to_addresses: ['to1@def.com', '=?UTF-8?B?VG8g44OG44K544OI?= '], - cc_addresses: ['cc1@xyz.com', '=?UTF-8?B?Q0Mg44OG44K544OI?= '], - bcc_addresses: ['=?UTF-8?B?QkNDIOODhuOCueODiOOBp+OBmeOAgg==?= ', 'bcc2@def.com'] + to_addresses: ["to1@def.com", "=?UTF-8?B?VG8g44OG44K544OI?= "], + cc_addresses: ["cc1@xyz.com", "=?UTF-8?B?Q0Mg44OG44K544OI?= "], + bcc_addresses: ["=?UTF-8?B?QkNDIOODhuOCueODiOOBp+OBmeOAgg==?= ", "bcc2@def.com"] }, - content: { raw: { data: 'Fixed message body' } } + content: {raw: {data: "Fixed message body"}} } end it { expect(subject).to eq(exp) } end - context 'when addresses are invalid' do + context "when addresses are invalid" do let(:mail) do Mail.new do - from '了承ございます