2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-04 10:00:07 -04:00
|
|
|
RSpec.describe UploadSerializer do
|
2023-06-21 10:00:19 -04:00
|
|
|
subject(:serializer) { UploadSerializer.new(upload, root: false) }
|
|
|
|
|
2019-05-06 23:12:20 -04:00
|
|
|
fab!(:upload) { Fabricate(:upload) }
|
2018-10-04 10:00:07 -04:00
|
|
|
|
|
|
|
it "should render without errors" do
|
2023-06-21 10:00:19 -04:00
|
|
|
json_data = JSON.parse(serializer.to_json)
|
2018-10-04 10:00:07 -04:00
|
|
|
|
|
|
|
expect(json_data["id"]).to eql upload.id
|
|
|
|
expect(json_data["width"]).to eql upload.width
|
|
|
|
expect(json_data["height"]).to eql upload.height
|
|
|
|
expect(json_data["thumbnail_width"]).to eql upload.thumbnail_width
|
|
|
|
expect(json_data["thumbnail_height"]).to eql upload.thumbnail_height
|
2020-04-14 19:19:59 -04:00
|
|
|
expect(json_data["short_path"]).to eql upload.short_path
|
2018-10-04 10:00:07 -04:00
|
|
|
end
|
2020-01-15 22:50:27 -05:00
|
|
|
|
|
|
|
context "when the upload is secure" do
|
|
|
|
fab!(:upload) { Fabricate(:secure_upload) }
|
|
|
|
|
2022-09-28 19:24:33 -04:00
|
|
|
context "when secure uploads is disabled" do
|
2020-01-15 22:50:27 -05:00
|
|
|
it "just returns the normal URL, otherwise S3 errors are encountered" do
|
2020-07-03 07:23:10 -04:00
|
|
|
UrlHelper.expects(:cook_url).with(upload.url, secure: false)
|
2023-06-21 10:00:19 -04:00
|
|
|
serializer.to_json
|
2020-01-15 22:50:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-09-28 19:24:33 -04:00
|
|
|
context "when secure uploads is enabled" do
|
2020-01-15 22:50:27 -05:00
|
|
|
before do
|
2020-09-14 07:32:25 -04:00
|
|
|
setup_s3
|
2022-09-28 19:24:33 -04:00
|
|
|
SiteSetting.secure_uploads = true
|
2020-01-15 22:50:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the cooked URL based on the upload URL" do
|
|
|
|
UrlHelper.expects(:cook_url).with(upload.url, secure: true)
|
2023-06-21 10:00:19 -04:00
|
|
|
serializer.to_json
|
2020-01-15 22:50:27 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-10-04 10:00:07 -04:00
|
|
|
end
|