Skip to content
代码片段 群组 项目
未验证 提交 2a463111 编辑于 作者: Stan Hu's avatar Stan Hu
浏览文件

Merge branch 'test-mail-smtp-pool-ruby-3-2' into 'master'

Test mail-smtp_pool on Ruby 3.1 and 3.2

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/130045



Merged-by: default avatarStan Hu <stanhu@gmail.com>
Approved-by: default avatarHitesh Raghuvanshi <hraghuvanshi@gitlab.com>
Approved-by: default avatarStan Hu <stanhu@gmail.com>
Reviewed-by: default avatarHeinrich Lee Yu <heinrich@gitlab.com>
Co-authored-by: default avatarHeinrich Lee Yu <heinrich@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -100,7 +100,7 @@ PATH ...@@ -100,7 +100,7 @@ PATH
specs: specs:
mail-smtp_pool (0.1.0) mail-smtp_pool (0.1.0)
connection_pool (~> 2.0) connection_pool (~> 2.0)
mail (~> 2.7) mail (~> 2.8)
PATH PATH
remote: vendor/gems/microsoft_graph_mailer remote: vendor/gems/microsoft_graph_mailer
......
...@@ -3,8 +3,3 @@ include: ...@@ -3,8 +3,3 @@ include:
inputs: inputs:
gem_name: "mail-smtp_pool" gem_name: "mail-smtp_pool"
gem_path_prefix: "vendor/gems/" gem_path_prefix: "vendor/gems/"
rspec:
parallel:
matrix:
- RUBY_VERSION: ["3.0"] # 3.1 & 3.2 aren't supported yet
...@@ -3,16 +3,29 @@ PATH ...@@ -3,16 +3,29 @@ PATH
specs: specs:
mail-smtp_pool (0.1.0) mail-smtp_pool (0.1.0)
connection_pool (~> 2.0) connection_pool (~> 2.0)
mail (~> 2.7) mail (~> 2.8)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
connection_pool (2.2.3) connection_pool (2.4.1)
date (3.3.3)
diff-lcs (1.4.4) diff-lcs (1.4.4)
mail (2.7.1) mail (2.8.1)
mini_mime (>= 0.1.1) mini_mime (>= 0.1.1)
mini_mime (1.0.2) net-imap
net-pop
net-smtp
mini_mime (1.1.5)
net-imap (0.3.7)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
timeout
net-smtp (0.3.3)
net-protocol
rspec (3.10.0) rspec (3.10.0)
rspec-core (~> 3.10.0) rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0) rspec-expectations (~> 3.10.0)
...@@ -26,6 +39,7 @@ GEM ...@@ -26,6 +39,7 @@ GEM
diff-lcs (>= 1.2.0, < 2.0) diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0) rspec-support (~> 3.10.0)
rspec-support (3.10.2) rspec-support (3.10.2)
timeout (0.4.0)
PLATFORMS PLATFORMS
ruby ruby
......
...@@ -19,7 +19,7 @@ Gem::Specification.new do |spec| ...@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
# Please maintain alphabetical order for dependencies # Please maintain alphabetical order for dependencies
spec.add_runtime_dependency 'connection_pool', '~> 2.0' spec.add_runtime_dependency 'connection_pool', '~> 2.0'
spec.add_runtime_dependency 'mail', '~> 2.7' spec.add_runtime_dependency 'mail', '~> 2.8'
# Please maintain alphabetical order for dev dependencies # Please maintain alphabetical order for dev dependencies
spec.add_development_dependency 'rspec', '~> 3.10.0' spec.add_development_dependency 'rspec', '~> 3.10.0'
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
end end
after do after do
MockSMTP.clear_deliveries MockSMTP.reset
end end
describe '#deliver!' do describe '#deliver!' do
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
context 'with an SMTP error' do context 'with an SMTP error' do
before do before do
expect(mock_smtp).to receive(:rset).once.and_raise(Net::SMTPServerBusy) expect(mock_smtp).to receive(:rset).once.and_raise(Net::SMTPServerBusy, nil)
end end
it 'creates a new SMTP connection' do it 'creates a new SMTP connection' do
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
end end
after do after do
MockSMTP.clear_deliveries MockSMTP.reset
end end
it 'delivers mail using a connection from the pool' do it 'delivers mail using a connection from the pool' do
......
...@@ -2,21 +2,46 @@ ...@@ -2,21 +2,46 @@
require 'mail/smtp_pool' require 'mail/smtp_pool'
# Based on https://github.com/mikel/mail/blob/2.8.1/spec/spec_helper.rb#L73-L155
class Net::SMTP
class << self
alias unstubbed_new new
end
def self.new(*args)
MockSMTP.new
end
end
# Original mockup from ActionMailer # Original mockup from ActionMailer
# Based on https://github.com/mikel/mail/blob/22a7afc23f253319965bf9228a0a430eec94e06d/spec/spec_helper.rb#L74-L138
class MockSMTP class MockSMTP
attr_accessor :open_timeout, :read_timeout
def self.reset
test = Net::SMTP.unstubbed_new('example.com')
@@tls = test.tls?
@@starttls = test.starttls?
@@deliveries = []
@started = false
end
reset
def self.deliveries def self.deliveries
@@deliveries @@deliveries
end end
def self.security def self.tls
@@security @@tls
end
def self.starttls
@@starttls
end end
def initialize def initialize
@@deliveries = [] self.class.reset
@@security = nil
@started = false
end end
def sendmail(mail, from, to) def sendmail(mail, from, to)
...@@ -50,35 +75,29 @@ def finish ...@@ -50,35 +75,29 @@ def finish
return true return true
end end
def self.clear_deliveries
@@deliveries = []
end
def self.clear_security
@@security = nil
end
def enable_tls(context) def enable_tls(context)
raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @@security && @@security != :enable_tls raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @@starttls == :always
@@security = :enable_tls @@tls = true
context context
end end
def disable_tls
@@tls = false
end
def enable_starttls(context = nil) def enable_starttls(context = nil)
raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @@security == :enable_tls raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @@tls
@@security = :enable_starttls @@starttls = :always
context context
end end
def enable_starttls_auto(context) def enable_starttls_auto(context)
raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @@security == :enable_tls raise ArgumentError, "SMTPS and STARTTLS is exclusive" if @@tls
@@security = :enable_starttls_auto @@starttls = :auto
context context
end end
end
class Net::SMTP def disable_starttls
def self.new(*args) @@starttls = false
MockSMTP.new
end end
end end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册