Skip to content

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.rb
index b7c623df818..c0c4966b4a1 100644
--- a/app/controllers/user_avatars_controller.rb
+++ b/app/controllers/user_avatars_controller.rb
@@ -49,6 +49,9 @@ class UserAvatarsController < ApplicationController
params.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 do
begin
proxy_avatar(
@@ -218,15 +221,14 @@ class UserAvatarsController < ApplicationController
send_file path, disposition: nil
end
- protected
-
- # consider removal of hacks some time in 2019
-
def get_optimized_image(upload, size)
return if !upload
return 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?
end
end
diff --git a/spec/requests/user_avatars_controller_spec.rb b/spec/requests/user_avatars_controller_spec.rb
index 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 do
end
it "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 do
describe "#proxy_avatar cache eviction" do
let(: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)
+ end
after { FileUtils.rm_rf(proxy_path) }