mirror of
https://github.com/discourse/discourse.git
synced 2025-09-11 21:04:42 +08:00
FIX: automatic backup uploads to S3 when using a region
This commit is contained in:
parent
6c275cd64d
commit
bfdbb70b3b
9 changed files with 345 additions and 212 deletions
|
@ -1,10 +1,10 @@
|
|||
require 'spec_helper'
|
||||
require 'fog'
|
||||
require 'file_store/s3_store'
|
||||
|
||||
describe FileStore::S3Store do
|
||||
|
||||
let(:store) { FileStore::S3Store.new }
|
||||
let(:s3_helper) { stub }
|
||||
let(:store) { FileStore::S3Store.new(s3_helper) }
|
||||
|
||||
let(:upload) { build(:upload) }
|
||||
let(:uploaded_file) { file_from_fixtures("logo.png") }
|
||||
|
@ -19,18 +19,14 @@ describe FileStore::S3Store do
|
|||
SiteSetting.stubs(:s3_upload_bucket).returns("S3_Upload_Bucket")
|
||||
SiteSetting.stubs(:s3_access_key_id).returns("s3_access_key_id")
|
||||
SiteSetting.stubs(:s3_secret_access_key).returns("s3_secret_access_key")
|
||||
Fog.mock!
|
||||
Fog::Mock.reset
|
||||
Fog::Mock.delay = 0
|
||||
end
|
||||
|
||||
after(:each) { Fog.unmock! }
|
||||
|
||||
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)
|
||||
store.store_upload(uploaded_file, upload).should == "//s3_upload_bucket.s3.amazonaws.com/42e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98.png"
|
||||
end
|
||||
|
||||
|
@ -40,6 +36,7 @@ describe FileStore::S3Store do
|
|||
|
||||
it "returns an absolute schemaless url" do
|
||||
optimized_image.stubs(:id).returns(42)
|
||||
s3_helper.expects(:upload)
|
||||
store.store_optimized_image(optimized_image_file, optimized_image).should == "//s3_upload_bucket.s3.amazonaws.com/4286f7e437faa5a7fce15d1ddcb9eaeaea377667b8_100x200.png"
|
||||
end
|
||||
|
||||
|
@ -49,6 +46,7 @@ describe FileStore::S3Store do
|
|||
|
||||
it "returns an absolute schemaless url" do
|
||||
avatar.stubs(:id).returns(42)
|
||||
s3_helper.expects(:upload)
|
||||
store.store_avatar(avatar_file, avatar, 100).should == "//s3_upload_bucket.s3.amazonaws.com/avatars/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98/100.png"
|
||||
end
|
||||
|
||||
|
@ -98,6 +96,23 @@ describe FileStore::S3Store do
|
|||
store.internal?.should == false
|
||||
end
|
||||
|
||||
describe ".download" do
|
||||
|
||||
it "does nothing if the file hasn't been uploaded to that store" do
|
||||
upload.stubs(:url).returns("/path/to/image.png")
|
||||
FileHelper.expects(:download).never
|
||||
store.download(upload)
|
||||
end
|
||||
|
||||
it "works" do
|
||||
upload.stubs(:url).returns("//s3_upload_bucket.s3.amazonaws.com/1337.png")
|
||||
max_file_size = [SiteSetting.max_image_size_kb, SiteSetting.max_attachment_size_kb].max.kilobytes
|
||||
FileHelper.expects(:download).with("http://s3_upload_bucket.s3.amazonaws.com/1337.png", max_file_size, "discourse-s3", true)
|
||||
store.download(upload)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe ".avatar_template" do
|
||||
|
||||
it "is present" do
|
||||
|
@ -106,4 +121,13 @@ describe FileStore::S3Store do
|
|||
|
||||
end
|
||||
|
||||
describe ".purge_tombstone" do
|
||||
|
||||
it "updates tombstone lifecycle" do
|
||||
s3_helper.expects(:update_tombstone_lifecycle)
|
||||
store.purge_tombstone(1.day)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue