DEV: Test against real `Upload#url` format.
This commit is contained in:
parent
419b14e58b
commit
c3f6b4d966
|
@ -30,7 +30,7 @@ describe Stylesheet::Importer do
|
||||||
background = Fabricate(:upload_s3)
|
background = Fabricate(:upload_s3)
|
||||||
category = Fabricate(:category, uploaded_background: background)
|
category = Fabricate(:category, uploaded_background: background)
|
||||||
|
|
||||||
expect(compile_css("category_backgrounds")).to include("body.category-#{category.full_slug}{background-image:url(https://s3.cdn/uploads")
|
expect(compile_css("category_backgrounds")).to include("body.category-#{category.full_slug}{background-image:url(https://s3.cdn/original")
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,18 +5,27 @@ Fabricator(:upload) do
|
||||||
filesize 1234
|
filesize 1234
|
||||||
width 100
|
width 100
|
||||||
height 200
|
height 200
|
||||||
url { sequence(:url) { |n| "/uploads/default/#{n}/1234567890123456.png" } }
|
|
||||||
|
url do |attrs|
|
||||||
|
sequence(:url) do |n|
|
||||||
|
Discourse.store.get_path_for(
|
||||||
|
"original", n + 1, attrs[:sha1], ".#{attrs[:extension]}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
extension "png"
|
extension "png"
|
||||||
end
|
end
|
||||||
|
|
||||||
Fabricator(:upload_s3, from: :upload) do
|
Fabricator(:upload_s3, from: :upload) do
|
||||||
url { sequence(:url) { |n| "#{Discourse.store.absolute_base_url}/uploads/default/#{n}/1234567890123456.png" } }
|
url do |attrs|
|
||||||
end
|
sequence(:url) do |n|
|
||||||
|
File.join(
|
||||||
Fabricator(:attachment, from: :upload) do
|
Discourse.store.absolute_base_url,
|
||||||
id 42
|
Discourse.store.get_path_for(
|
||||||
user
|
"original", n + 1, attrs[:sha1], ".#{attrs[:extension]}"
|
||||||
original_filename "archive.zip"
|
)
|
||||||
filesize 1234
|
)
|
||||||
url "/uploads/default/42/66b3ed1503efc936.zip"
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,23 +75,34 @@ describe Upload do
|
||||||
|
|
||||||
context ".get_from_url" do
|
context ".get_from_url" do
|
||||||
let(:sha1) { "10f73034616a796dfd70177dc54b6def44c4ba6f" }
|
let(:sha1) { "10f73034616a796dfd70177dc54b6def44c4ba6f" }
|
||||||
let(:url) { "/uploads/default/original/3X/1/0/#{sha1}.png" }
|
let(:upload) { Fabricate(:upload, sha1: sha1) }
|
||||||
let(:upload) { Fabricate(:upload, url: url, sha1: sha1) }
|
|
||||||
|
|
||||||
it "works when the file has been uploaded" do
|
it "works when the file has been uploaded" do
|
||||||
expect(Upload.get_from_url(upload.url)).to eq(upload)
|
expect(Upload.get_from_url(upload.url)).to eq(upload)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'for an extensionless url' do
|
describe 'for an extensionless url' do
|
||||||
let(:url) { "/uploads/default/original/1X/#{sha1}" }
|
before do
|
||||||
|
upload.update!(url: upload.url.sub('.png', ''))
|
||||||
|
upload.reload
|
||||||
|
end
|
||||||
|
|
||||||
it 'should return the right upload' do
|
it 'should return the right upload' do
|
||||||
expect(Upload.get_from_url(upload.url)).to eq(upload)
|
expect(Upload.get_from_url(upload.url)).to eq(upload)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'for a url without a tree' do
|
describe 'for a url a tree' do
|
||||||
let(:url) { "/uploads/default/original/1X/#{sha1}.png" }
|
before do
|
||||||
|
upload.update!(url:
|
||||||
|
Discourse.store.get_path_for(
|
||||||
|
"original",
|
||||||
|
16001,
|
||||||
|
upload.sha1,
|
||||||
|
".#{upload.extension}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
it 'should return the right upload' do
|
it 'should return the right upload' do
|
||||||
expect(Upload.get_from_url(upload.url)).to eq(upload)
|
expect(Upload.get_from_url(upload.url)).to eq(upload)
|
||||||
|
@ -124,8 +135,8 @@ describe Upload do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "s3 store" do
|
describe "s3 store" do
|
||||||
let(:path) { "/original/3X/1/0/10f73034616a796dfd70177dc54b6def44c4ba6f.png" }
|
let(:upload) { Fabricate(:upload_s3) }
|
||||||
let(:url) { "#{SiteSetting.Upload.absolute_base_url}#{path}" }
|
let(:path) { upload.url.sub(SiteSetting.Upload.s3_base_url, '') }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
SiteSetting.enable_s3_uploads = true
|
SiteSetting.enable_s3_uploads = true
|
||||||
|
@ -136,7 +147,7 @@ describe Upload do
|
||||||
|
|
||||||
it "should return the right upload when using base url (not CDN) for s3" do
|
it "should return the right upload when using base url (not CDN) for s3" do
|
||||||
upload
|
upload
|
||||||
expect(Upload.get_from_url(url)).to eq(upload)
|
expect(Upload.get_from_url(upload.url)).to eq(upload)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when using a cdn' do
|
describe 'when using a cdn' do
|
||||||
|
|
Loading…
Reference in New Issue