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}"
|
||||
return
|
||||
end
|
||||
logger.info "Fetchd image '#{url}', http code: #{response.code}"
|
||||
logger.info "Fetched image '#{url}', http code: #{response.code}"
|
||||
mime_type = 'image'
|
||||
if url.match?(%r{\.png}i)
|
||||
mime_type = 'image/png'
|
||||
|
|
|
@ -6,10 +6,13 @@ class Service::Image::Zammad
|
|||
OPEN_TIMEOUT = 4
|
||||
READ_TIMEOUT = 6
|
||||
TOTAL_TIMEOUT = 6
|
||||
DISABLE_IN_TEST_ENV = true
|
||||
|
||||
def self.user(email)
|
||||
raise Exceptions::UnprocessableEntity, 'no email given' if email.blank?
|
||||
|
||||
return if Rails.env.test? && DISABLE_IN_TEST_ENV
|
||||
|
||||
email.downcase!
|
||||
|
||||
return if email.match?(%r{@example.com$})
|
||||
|
@ -32,20 +35,20 @@ class Service::Image::Zammad
|
|||
return
|
||||
end
|
||||
Rails.logger.info "Fetched image for '#{email}', http code: #{response.code}"
|
||||
mime_type = 'image/jpeg'
|
||||
{
|
||||
content: response.body,
|
||||
mime_type: mime_type,
|
||||
mime_type: 'image/jpeg',
|
||||
}
|
||||
end
|
||||
|
||||
def self.organization(domain)
|
||||
raise Exceptions::UnprocessableEntity, 'no domain given' if domain.blank?
|
||||
|
||||
# strip, just use domain name
|
||||
domain = domain.sub(%r{^.+?@(.+?)$}, '\1')
|
||||
return if Rails.env.test? && DISABLE_IN_TEST_ENV
|
||||
|
||||
# strip, just use domain name
|
||||
domain = domain.sub(%r{^.+?@(.+?)$}, '\1').downcase
|
||||
|
||||
domain.downcase!
|
||||
return if domain == 'example.com'
|
||||
|
||||
# fetch org logo
|
||||
|
@ -61,16 +64,16 @@ class Service::Image::Zammad
|
|||
verify_ssl: true,
|
||||
},
|
||||
)
|
||||
response_code = response.code
|
||||
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
|
||||
end
|
||||
Rails.logger.info "Fetched image for '#{domain}', http code: #{response.code}"
|
||||
mime_type = 'image/png'
|
||||
Rails.logger.info "Fetched image for '#{domain}', http code: #{response_code}"
|
||||
|
||||
{
|
||||
content: response.body,
|
||||
mime_type: mime_type,
|
||||
mime_type: 'image/png',
|
||||
}
|
||||
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|
|
||||
|
||||
# check if user exists
|
||||
|
@ -310,6 +313,8 @@ class UserTest < ActiveSupport::TestCase
|
|||
|
||||
user.destroy!
|
||||
end
|
||||
|
||||
Service::Image::Zammad.const_set(:DISABLE_IN_TEST_ENV, default_disable_in_test_env)
|
||||
end
|
||||
|
||||
test 'strange spaces' do
|
||||
|
|
Loading…
Reference in a new issue