mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
DEV: Clean up S3 specs, stubs, and helpers
Extracted commonly used spec helpers into spec/support/uploads_helpers.rb, removed unused stubs and let definitions. Makes it easier to write new S3-related specs without copy and pasting setup steps from other specs.
This commit is contained in:

committed by
Daniel Waterworth

parent
50d53508b1
commit
e00abbe1b7
@ -293,11 +293,7 @@ describe OptimizedImage do
|
||||
|
||||
describe "external store" do
|
||||
before do
|
||||
SiteSetting.enable_s3_uploads = true
|
||||
SiteSetting.s3_upload_bucket = "s3-upload-bucket"
|
||||
SiteSetting.s3_access_key_id = "some key"
|
||||
SiteSetting.s3_secret_access_key = "some secret key"
|
||||
SiteSetting.s3_region = "us-east-1"
|
||||
setup_s3
|
||||
end
|
||||
|
||||
context "when we have a bad file returned" do
|
||||
@ -318,8 +314,7 @@ describe OptimizedImage do
|
||||
before do
|
||||
stub_request(:head, "http://#{s3_upload.url}").to_return(status: 200)
|
||||
stub_request(:get, "http://#{s3_upload.url}").to_return(status: 200, body: file_from_fixtures("logo.png"))
|
||||
stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com/")
|
||||
stub_request(:put, "https://#{SiteSetting.s3_upload_bucket}.s3.amazonaws.com#{optimized_path}")
|
||||
stub_request(:put, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com#{optimized_path}")
|
||||
.to_return(status: 200, headers: { "ETag" => "someetag" })
|
||||
end
|
||||
|
||||
@ -330,14 +325,14 @@ describe OptimizedImage do
|
||||
expect(oi.extension).to eq(".png")
|
||||
expect(oi.width).to eq(100)
|
||||
expect(oi.height).to eq(200)
|
||||
expect(oi.url).to eq("//#{SiteSetting.s3_upload_bucket}.s3.dualstack.us-east-1.amazonaws.com#{optimized_path}")
|
||||
expect(oi.url).to eq("//#{SiteSetting.s3_upload_bucket}.s3.dualstack.us-west-1.amazonaws.com#{optimized_path}")
|
||||
expect(oi.filesize).to be > 0
|
||||
|
||||
oi.filesize = nil
|
||||
|
||||
stub_request(
|
||||
:get,
|
||||
"http://#{SiteSetting.s3_upload_bucket}.s3.dualstack.us-east-1.amazonaws.com#{optimized_path}"
|
||||
"http://#{SiteSetting.s3_upload_bucket}.s3.dualstack.us-west-1.amazonaws.com#{optimized_path}"
|
||||
).to_return(status: 200, body: file_from_fixtures("resized.png"))
|
||||
|
||||
expect(oi.filesize).to be > 0
|
||||
|
Reference in New Issue
Block a user