A platform for community discussion. Free, open, simple.
DEV: Don't try to proxy avatars in test env (#40047)
Jarek Radosz6203b7bffd53
diff --git a/app/controllers/user_avatars_controller.rb b/app/controllers/user_avatars_controller.rbindex b7c623df818..c0c4966b4a1 100644--- a/app/controllers/user_avatars_controller.rb+++ b/app/controllers/user_avatars_controller.rb@@ -49,6 +49,9 @@ class UserAvatarsController < ApplicationControllerparams.require(:version)params.require(:size)+ # Don't try to proxy avatars in tests. The timeout could block the single worker. (QUnit case)+ return render_blank if disable_proxy?+hijack dobeginproxy_avatar(@@ -218,15 +221,14 @@ class UserAvatarsController < ApplicationControllersend_file path, disposition: nilend- protected-- # consider removal of hacks some time in 2019-def get_optimized_image(upload, size)return if !uploadreturn upload if upload.extension == "svg"upload.get_optimized_image(size, size)- # TODO decide if we want to detach here+ end++ def disable_proxy?+ Rails.env.test?endenddiff --git a/spec/requests/user_avatars_controller_spec.rb b/spec/requests/user_avatars_controller_spec.rbindex 3fc9878da3f..85eae3b41ee 100644--- a/spec/requests/user_avatars_controller_spec.rb+++ b/spec/requests/user_avatars_controller_spec.rb@@ -9,6 +9,7 @@ RSpec.describe UserAvatarsController doendit "returns an avatar if we are allowing the proxy" do+ UserAvatarsController.any_instance.stubs(:disable_proxy?).returns(false)stub_request(:get, "https://avatars.discourse-cdn.com/v3/letter/a/aaaaaa/360.png").to_return(body: "image",)@@ -20,7 +21,10 @@ RSpec.describe UserAvatarsController dodescribe "#proxy_avatar cache eviction" dolet(:proxy_path) { UserAvatarsController::PROXY_PATH }- before { FileUtils.rm_rf(proxy_path) }+ before do+ UserAvatarsController.any_instance.stubs(:disable_proxy?).returns(false)+ FileUtils.rm_rf(proxy_path)+ endafter { FileUtils.rm_rf(proxy_path) }