Maintenance: Disable default user avatar fetching in test environment.
This commit is contained in:
parent
048ce041e7
commit
afb75b23ae
3 changed files with 18 additions and 10 deletions
|
@ -148,7 +148,7 @@ add avatar by url
|
||||||
logger.info "Can't fetch '#{url}' (maybe no avatar available), http code: #{response.code}"
|
logger.info "Can't fetch '#{url}' (maybe no avatar available), http code: #{response.code}"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
logger.info "Fetchd image '#{url}', http code: #{response.code}"
|
logger.info "Fetched image '#{url}', http code: #{response.code}"
|
||||||
mime_type = 'image'
|
mime_type = 'image'
|
||||||
if url.match?(%r{\.png}i)
|
if url.match?(%r{\.png}i)
|
||||||
mime_type = 'image/png'
|
mime_type = 'image/png'
|
||||||
|
|
|
@ -6,10 +6,13 @@ class Service::Image::Zammad
|
||||||
OPEN_TIMEOUT = 4
|
OPEN_TIMEOUT = 4
|
||||||
READ_TIMEOUT = 6
|
READ_TIMEOUT = 6
|
||||||
TOTAL_TIMEOUT = 6
|
TOTAL_TIMEOUT = 6
|
||||||
|
DISABLE_IN_TEST_ENV = true
|
||||||
|
|
||||||
def self.user(email)
|
def self.user(email)
|
||||||
raise Exceptions::UnprocessableEntity, 'no email given' if email.blank?
|
raise Exceptions::UnprocessableEntity, 'no email given' if email.blank?
|
||||||
|
|
||||||
|
return if Rails.env.test? && DISABLE_IN_TEST_ENV
|
||||||
|
|
||||||
email.downcase!
|
email.downcase!
|
||||||
|
|
||||||
return if email.match?(%r{@example.com$})
|
return if email.match?(%r{@example.com$})
|
||||||
|
@ -32,20 +35,20 @@ class Service::Image::Zammad
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
Rails.logger.info "Fetched image for '#{email}', http code: #{response.code}"
|
Rails.logger.info "Fetched image for '#{email}', http code: #{response.code}"
|
||||||
mime_type = 'image/jpeg'
|
|
||||||
{
|
{
|
||||||
content: response.body,
|
content: response.body,
|
||||||
mime_type: mime_type,
|
mime_type: 'image/jpeg',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.organization(domain)
|
def self.organization(domain)
|
||||||
raise Exceptions::UnprocessableEntity, 'no domain given' if domain.blank?
|
raise Exceptions::UnprocessableEntity, 'no domain given' if domain.blank?
|
||||||
|
|
||||||
# strip, just use domain name
|
return if Rails.env.test? && DISABLE_IN_TEST_ENV
|
||||||
domain = domain.sub(%r{^.+?@(.+?)$}, '\1')
|
|
||||||
|
# strip, just use domain name
|
||||||
|
domain = domain.sub(%r{^.+?@(.+?)$}, '\1').downcase
|
||||||
|
|
||||||
domain.downcase!
|
|
||||||
return if domain == 'example.com'
|
return if domain == 'example.com'
|
||||||
|
|
||||||
# fetch org logo
|
# fetch org logo
|
||||||
|
@ -61,16 +64,16 @@ class Service::Image::Zammad
|
||||||
verify_ssl: true,
|
verify_ssl: true,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
response_code = response.code
|
||||||
if !response.success?
|
if !response.success?
|
||||||
Rails.logger.info "Can't fetch image for '#{domain}' (maybe no avatar available), http code: #{response.code}"
|
Rails.logger.info "Can't fetch image for '#{domain}' (maybe no avatar available), http code: #{response_code}"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
Rails.logger.info "Fetched image for '#{domain}', http code: #{response.code}"
|
Rails.logger.info "Fetched image for '#{domain}', http code: #{response_code}"
|
||||||
mime_type = 'image/png'
|
|
||||||
|
|
||||||
{
|
{
|
||||||
content: response.body,
|
content: response.body,
|
||||||
mime_type: mime_type,
|
mime_type: 'image/png',
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -261,6 +261,9 @@ class UserTest < ActiveSupport::TestCase
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
default_disable_in_test_env = Service::Image::Zammad.const_get(:DISABLE_IN_TEST_ENV)
|
||||||
|
Service::Image::Zammad.const_set(:DISABLE_IN_TEST_ENV, false)
|
||||||
|
|
||||||
tests.each do |test|
|
tests.each do |test|
|
||||||
|
|
||||||
# check if user exists
|
# check if user exists
|
||||||
|
@ -310,6 +313,8 @@ class UserTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
user.destroy!
|
user.destroy!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Service::Image::Zammad.const_set(:DISABLE_IN_TEST_ENV, default_disable_in_test_env)
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'strange spaces' do
|
test 'strange spaces' do
|
||||||
|
|
Loading…
Reference in a new issue