FIX: automatically growing uploads tree

This commit is contained in:
Régis Hanol
2015-05-28 01:03:24 +02:00
parent 1b96a3acc1
commit 8e7bfd0f29
8 changed files with 38 additions and 46 deletions

View File

@ -118,7 +118,7 @@ describe CookedPostProcessor do
it "generates overlay information" do
cpp.post_process_images
expect(cpp.html).to match_html '<div class="lightbox-wrapper"><a data-download-href="/uploads/default/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98" href="/uploads/default/1/1234567890123456.jpg" class="lightbox" title="logo.png"><img src="/uploads/default/optimized/d/a/da39a3ee5e6b4b0d3255bfef95601890afd80709_690x1380.png" width="690" height="1380"><div class="meta">
expect(cpp.html).to match_html '<div class="lightbox-wrapper"><a data-download-href="/uploads/default/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98" href="/uploads/default/1/1234567890123456.jpg" class="lightbox" title="logo.png"><img src="/uploads/default/optimized/2X/e/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98_1_690x1380.png" width="690" height="1380"><div class="meta">
<span class="filename">logo.png</span><span class="informations">1000x2000 1.21 KB</span><span class="expand"></span>
</div></a></div>'
expect(cpp).to be_dirty
@ -145,7 +145,7 @@ describe CookedPostProcessor do
it "generates overlay information" do
cpp.post_process_images
expect(cpp.html).to match_html '<div class="lightbox-wrapper"><a data-download-href="/uploads/default/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98" href="/uploads/default/1/1234567890123456.jpg" class="lightbox" title="WAT"><img src="/uploads/default/optimized/d/a/da39a3ee5e6b4b0d3255bfef95601890afd80709_690x1380.png" title="WAT" width="690" height="1380"><div class="meta">
expect(cpp.html).to match_html '<div class="lightbox-wrapper"><a data-download-href="/uploads/default/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98" href="/uploads/default/1/1234567890123456.jpg" class="lightbox" title="WAT"><img src="/uploads/default/optimized/2X/e/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98_1_690x1380.png" title="WAT" width="690" height="1380"><div class="meta">
<span class="filename">WAT</span><span class="informations">1000x2000 1.21 KB</span><span class="expand"></span>
</div></a></div>'
expect(cpp).to be_dirty

View File

@ -309,7 +309,7 @@ This is a link http://example.com"
receiver.process
expect(topic.posts.count).to eq(start_count + 1)
expect(topic.posts.last.cooked).to match /<img src=['"](\/uploads\/default\/original\/#{upload_sha[0]}\/#{upload_sha[1]}\/#{upload_sha}\.png)['"] width=['"]289['"] height=['"]126['"]>/
expect(topic.posts.last.cooked).to match /<img src=['"](\/uploads\/default\/original\/.+\.png)['"] width=['"]289['"] height=['"]126['"]>/
expect(Upload.find_by(sha1: upload_sha)).not_to eq(nil)
end

View File

@ -5,20 +5,18 @@ describe FileStore::LocalStore do
let(:store) { FileStore::LocalStore.new }
let(:upload) { build(:upload) }
let(:upload) { Fabricate(:upload) }
let(:uploaded_file) { file_from_fixtures("logo.png") }
let(:optimized_image) { build(:optimized_image) }
let(:optimized_image) { Fabricate(:optimized_image) }
let(:avatar) { build(:upload) }
let(:avatar) { Fabricate(:upload) }
describe ".store_upload" do
it "returns a relative url" do
Time.stubs(:now).returns(Time.utc(2013, 2, 17, 12, 0, 0, 0))
upload.stubs(:id).returns(42)
store.expects(:copy_file)
expect(store.store_upload(uploaded_file, upload)).to eq("/uploads/default/original/e/9/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98.png")
expect(store.store_upload(uploaded_file, upload)).to eq("/uploads/default/original/2X/e/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98.png")
end
end
@ -27,7 +25,7 @@ describe FileStore::LocalStore do
it "returns a relative url" do
store.expects(:copy_file)
expect(store.store_optimized_image({}, optimized_image)).to eq("/uploads/default/optimized/8/6/86f7e437faa5a7fce15d1ddcb9eaeaea377667b8_100x200.png")
expect(store.store_optimized_image({}, optimized_image)).to eq("/uploads/default/optimized/2X/e/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98_#{OptimizedImage::VERSION}_100x200.png")
end
end

View File

@ -7,13 +7,13 @@ describe FileStore::S3Store do
let(:s3_helper) { stub }
let(:store) { FileStore::S3Store.new(s3_helper) }
let(:upload) { build(:upload) }
let(:upload) { Fabricate(:upload) }
let(:uploaded_file) { file_from_fixtures("logo.png") }
let(:optimized_image) { build(:optimized_image) }
let(:optimized_image) { Fabricate(:optimized_image) }
let(:optimized_image_file) { file_from_fixtures("logo.png") }
let(:avatar) { build(:upload) }
let(:avatar) { Fabricate(:upload) }
before(:each) do
SiteSetting.stubs(:s3_upload_bucket).returns("S3_Upload_Bucket")
@ -24,10 +24,8 @@ describe FileStore::S3Store do
describe ".store_upload" do
it "returns an absolute schemaless url" do
upload.stubs(:id).returns(42)
upload.stubs(:extension).returns(".png")
s3_helper.expects(:upload)
expect(store.store_upload(uploaded_file, upload)).to eq("//s3_upload_bucket.s3.amazonaws.com/original/e/9/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98.png")
expect(store.store_upload(uploaded_file, upload)).to eq("//s3_upload_bucket.s3.amazonaws.com/original/2X/e/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98.png")
end
end
@ -35,9 +33,8 @@ describe FileStore::S3Store do
describe ".store_optimized_image" do
it "returns an absolute schemaless url" do
optimized_image.stubs(:id).returns(42)
s3_helper.expects(:upload)
expect(store.store_optimized_image(optimized_image_file, optimized_image)).to eq("//s3_upload_bucket.s3.amazonaws.com/optimized/8/6/86f7e437faa5a7fce15d1ddcb9eaeaea377667b8_100x200.png")
expect(store.store_optimized_image(optimized_image_file, optimized_image)).to eq("//s3_upload_bucket.s3.amazonaws.com/optimized/2X/e/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98_#{OptimizedImage::VERSION}_100x200.png")
end
end