2019-04-30 10:27:42 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-04 15:00:07 +01:00
|
|
|
RSpec.describe UploadSerializer do
|
2019-05-07 03:12:20 +00:00
|
|
|
fab!(:upload) { Fabricate(:upload) }
|
2018-10-04 15:00:07 +01:00
|
|
|
let(:subject) { UploadSerializer.new(upload, root: false) }
|
|
|
|
|
|
|
|
it 'should render without errors' do
|
2021-10-27 11:39:28 +03:00
|
|
|
json_data = JSON.parse(subject.to_json)
|
2018-10-04 15:00:07 +01: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-15 09:19:59 +10:00
|
|
|
expect(json_data['short_path']).to eql upload.short_path
|
2018-10-04 15:00:07 +01:00
|
|
|
end
|
2020-01-16 13:50:27 +10:00
|
|
|
|
|
|
|
context "when the upload is secure" do
|
|
|
|
fab!(:upload) { Fabricate(:secure_upload) }
|
|
|
|
|
|
|
|
context "when secure media is disabled" do
|
|
|
|
it "just returns the normal URL, otherwise S3 errors are encountered" do
|
2020-07-03 13:23:10 +02:00
|
|
|
UrlHelper.expects(:cook_url).with(upload.url, secure: false)
|
|
|
|
subject.to_json
|
2020-01-16 13:50:27 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when secure media is enabled" do
|
|
|
|
before do
|
2020-09-14 13:32:25 +02:00
|
|
|
setup_s3
|
2020-01-16 13:50:27 +10:00
|
|
|
SiteSetting.secure_media = true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the cooked URL based on the upload URL" do
|
|
|
|
UrlHelper.expects(:cook_url).with(upload.url, secure: true)
|
|
|
|
subject.to_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-10-04 15:00:07 +01:00
|
|
|
end
|