DEV: Improve specs to use `upload_s3` fabricator.

This commit is contained in:
Guo Xiang Tan 2019-05-15 08:42:17 +08:00
parent 42b10a646d
commit ab1684999c
1 changed files with 11 additions and 5 deletions

View File

@ -209,27 +209,33 @@ describe UploadsController do
file: fake_logo, file: fake_logo,
type: "composer", type: "composer",
} }
expect(response.status).to eq(200)
url = JSON.parse(response.body)["url"] url = JSON.parse(response.body)["url"]
upload = Upload.where(url: url).first upload = Upload.where(url: url).first
upload upload
end end
context "when using external storage" do context "when using external storage" do
fab!(:upload) { upload_file("small.pdf", "pdf") }
before do before do
@upload = upload_file("small.pdf", "pdf")
SiteSetting.enable_s3_uploads = true SiteSetting.enable_s3_uploads = true
SiteSetting.s3_access_key_id = "fakeid7974664" SiteSetting.s3_access_key_id = "fakeid7974664"
SiteSetting.s3_secret_access_key = "fakesecretid7974664" SiteSetting.s3_secret_access_key = "fakesecretid7974664"
end end
it "returns 404" do it "returns 404 " do
@upload.update_column(:url, "//bucket.s3.amazonaws.com/#{@upload.url}") upload = Fabricate(:upload_s3)
get "/uploads/#{site}/#{@upload.sha1}.#{@upload.extension}" get "/uploads/#{site}/#{upload.sha1}.#{upload.extension}"
expect(response.response_code).to eq(404) expect(response.response_code).to eq(404)
end end
it "returns upload if url not migrated" do it "returns upload if url not migrated" do
get "/uploads/#{site}/#{@upload.sha1}.#{@upload.extension}" get "/uploads/#{site}/#{upload.sha1}.#{upload.extension}"
expect(response.status).to eq(200) expect(response.status).to eq(200)
end end
end end