Use webmock to stub external web requests.

This commit is contained in:
Guo Xiang Tan
2017-05-26 15:19:09 +08:00
parent f8f1548fd4
commit 56f98de7b2
10 changed files with 23 additions and 24 deletions

View File

@ -74,7 +74,8 @@ describe UploadsController do
controller.stubs(:is_api?).returns(true)
Jobs.expects(:enqueue).with(:create_avatar_thumbnails, anything)
Excon.stub({ method: :head, hostname: 'example.com' }, {})
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'))
xhr :post, :create, url: 'http://example.com/image.png', type: "avatar", synchronous: true

View File

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