2013-06-05 06:34:53 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'fog'
|
|
|
|
require 's3'
|
|
|
|
|
|
|
|
describe S3 do
|
|
|
|
|
|
|
|
describe "store_file" do
|
|
|
|
|
|
|
|
let(:file) do
|
|
|
|
ActionDispatch::Http::UploadedFile.new({
|
|
|
|
filename: 'logo.png',
|
|
|
|
content_type: 'image/png',
|
|
|
|
tempfile: File.new("#{Rails.root}/spec/fixtures/images/logo.png")
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:image_info) { FastImage.new(file) }
|
|
|
|
|
2013-06-15 17:52:40 +08:00
|
|
|
before(:each) do
|
2013-06-05 06:34:53 +08:00
|
|
|
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!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the url of the S3 upload if successful' do
|
2013-06-15 17:52:40 +08:00
|
|
|
S3.store_file(file, "SHA", image_info, 1).should == '//s3_upload_bucket.s3.amazonaws.com/1SHA.png'
|
2013-06-05 06:34:53 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
after(:each) do
|
|
|
|
Fog.unmock!
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|