diff --git a/app/models/avatar.rb b/app/models/avatar.rb index 6c6e3b3ce..3cd903151 100644 --- a/app/models/avatar.rb +++ b/app/models/avatar.rb @@ -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' diff --git a/lib/service/image/zammad.rb b/lib/service/image/zammad.rb index 7319d780b..f479abf75 100644 --- a/lib/service/image/zammad.rb +++ b/lib/service/image/zammad.rb @@ -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 diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 87612648a..f825c5976 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -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