Skip to content

Commit

Permalink
fix: don't pass a string as the enable_starttls_auto mailer parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
did committed Nov 30, 2024
1 parent 08b029b commit 023a424
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
2 changes: 2 additions & 0 deletions lib/locomotive/steam.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module Steam

IsLAYOUT = /\Alayouts(\/|\z)/o.freeze

TRUTHY_VALUES = [1, '1', 'true', true]

class << self
attr_writer :configuration
attr_accessor :extension_configurations
Expand Down
2 changes: 1 addition & 1 deletion lib/locomotive/steam/middlewares/auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def email_handle
end

def disable_email
[1, '1', 'true', true].include?(params[:auth_disable_email])
Locomotive::Steam::TRUTHY_VALUES.include?(params[:auth_disable_email])
end

def entry
Expand Down
4 changes: 4 additions & 0 deletions lib/locomotive/steam/services/email_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def prepare_options(options, context)

options[:via] ||= :smtp
options[:via_options] ||= options.delete(:smtp).try(:symbolize_keys)

if (enable_starttls_auto = options[:via_options][:enable_starttls_auto]).present?
options[:via_options][:enable_starttls_auto] = Locomotive::Steam::TRUTHY_VALUES.include?(enable_starttls_auto)
end
end

def build_body(options, context, html = true)
Expand Down
47 changes: 35 additions & 12 deletions spec/unit/services/email_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

describe '#send' do

let(:smtp_options) { { address: 'smtp.example.com', user_name: 'user', password: 'password' } }
let(:enable_starttls_auto) { '0' }
let(:smtp_options) { { address: 'smtp.example.com', user_name: 'user', password: 'password', enable_starttls_auto: enable_starttls_auto } }
let(:options) { { to: '[email protected]', from: '[email protected]', subject: 'Hello world', body: 'Hello {{ to }}', smtp: smtp_options, html: false } }
let(:context) { ::Liquid::Context.new({ 'name' => 'John', 'to' => '[email protected]' }, {}, {}) }

Expand All @@ -30,12 +31,34 @@
via_options: {
address: 'smtp.example.com',
user_name: 'user',
password: 'password'
password: 'password',
enable_starttls_auto: false
}
})
subject
end

context "enable_starttls_auto is to '1'" do
let(:enable_starttls_auto) { '1' }

it 'sends the email over Pony' do
expect(Pony).to receive(:mail).with({
to: '[email protected]',
from: '[email protected]',
subject: 'Hello world',
body: 'Hello [email protected]',
via: :smtp,
via_options: {
address: 'smtp.example.com',
user_name: 'user',
password: 'password',
enable_starttls_auto: true
}
})
subject
end
end

context 'simulation mode' do

let(:simulation) { true }
Expand Down Expand Up @@ -70,7 +93,8 @@
via_options: {
address: 'smtp.example.com',
user_name: 'user',
password: 'password'
password: 'password',
enable_starttls_auto: false
}
})
subject
Expand Down Expand Up @@ -110,7 +134,8 @@
via_options: {
address: 'smtp.example.com',
user_name: 'user',
password: 'password'
password: 'password',
enable_starttls_auto: false
}
})
subject
Expand All @@ -134,7 +159,8 @@
via_options: {
address: 'smtp.example.com',
user_name: 'user',
password: 'password'
password: 'password',
enable_starttls_auto: false
}
})
subject
Expand All @@ -154,7 +180,8 @@
via_options: {
address: 'smtp.example.com',
user_name: 'user',
password: 'password'
password: 'password',
enable_starttls_auto: false
}
})
subject
Expand All @@ -179,7 +206,8 @@
via_options: {
address: 'smtp.example.com',
user_name: 'user',
password: 'password'
password: 'password',
enable_starttls_auto: false
}
})
subject
Expand All @@ -190,9 +218,4 @@
end

end

def default_options

end

end

0 comments on commit 023a424

Please sign in to comment.