FEATURE: Add S3 etag value to uploads table (#6795)

This commit is contained in:
Vinoth Kannan
2019-01-04 11:46:22 +05:30
committed by Guo Xiang Tan
parent 3a04e04ccb
commit 75dbb98cca
8 changed files with 88 additions and 14 deletions

View File

@ -1,4 +1,5 @@
require 'rails_helper'
require 'file_store/s3_store'
RSpec.describe UploadCreator do
let(:user) { Fabricate(:user) }
@ -166,5 +167,34 @@ RSpec.describe UploadCreator do
expect(upload.original_filename).to eq('should_be_jpeg.jpg')
end
end
describe 'uploading to s3' do
let(:filename) { "should_be_jpeg.png" }
let(:file) { file_from_fixtures(filename) }
before do
SiteSetting.s3_upload_bucket = "s3-upload-bucket"
SiteSetting.s3_access_key_id = "s3-access-key-id"
SiteSetting.s3_secret_access_key = "s3-secret-access-key"
SiteSetting.s3_region = 'us-west-1'
SiteSetting.enable_s3_uploads = true
store = FileStore::S3Store.new
s3_helper = store.instance_variable_get(:@s3_helper)
client = Aws::S3::Client.new(stub_responses: true)
s3_helper.stubs(:s3_client).returns(client)
Discourse.stubs(:store).returns(store)
end
it 'should store the file and return etag' do
expect {
UploadCreator.new(file, filename).create_for(user.id)
}.to change { Upload.count }.by(1)
upload = Upload.last
expect(upload.etag).to eq('ETag')
end
end
end
end