FIX: don't double request when downloading a file

This commit is contained in:
Régis Hanol
2018-02-24 12:35:57 +01:00
parent b731d5d9b5
commit 0559a4736a
17 changed files with 80 additions and 132 deletions

View File

@ -35,11 +35,8 @@ describe OneboxController do
url = "http://noodle.com/"
stub_request(:head, url).
to_return(status: 200, body: "", headers: {}).then.to_raise
stub_request(:get, url)
.to_return(status: 200, headers: {}, body: onebox_html).then.to_raise
stub_request(:head, url)
stub_request(:get, url).to_return(body: onebox_html).then.to_raise
get :show, params: { url: url, refresh: "true" }, format: :json

View File

@ -59,21 +59,20 @@ describe UploadsController do
expect(id).to be
end
it 'is successful with synchronous api' do
it 'is successful with api' do
SiteSetting.authorized_extensions = "*"
controller.stubs(:is_api?).returns(true)
FinalDestination.stubs(:lookup_ip).returns("1.2.3.4")
Jobs.expects(:enqueue).with(:create_avatar_thumbnails, anything)
stub_request(:head, 'http://example.com/image.png')
stub_request(:get, "http://example.com/image.png").to_return(body: File.read('spec/fixtures/images/logo.png'))
url = "http://example.com/image.png"
png = File.read(Rails.root + "spec/fixtures/images/logo.png")
post :create, params: {
url: 'http://example.com/image.png',
type: "avatar",
synchronous: true,
format: :json
}
stub_request(:get, url).to_return(status: 200, body: png)
post :create, params: { url: url, type: "avatar", format: :json }
json = ::JSON.parse(response.body)

View File

@ -31,7 +31,6 @@ describe UserAvatarsController do
SiteSetting.s3_upload_bucket = "test"
SiteSetting.s3_cdn_url = "http://cdn.com"
stub_request(:head, "http://cdn.com/something/else")
stub_request(:get, "http://cdn.com/something/else").to_return(body: 'image')
GlobalSetting.expects(:cdn_url).returns("http://awesome.com/boom")