2013-07-31 17:26:34 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'fog'
|
|
|
|
require 'file_store/s3_store'
|
|
|
|
|
2013-11-05 13:04:47 -05:00
|
|
|
describe FileStore::S3Store do
|
2013-07-31 17:26:34 -04:00
|
|
|
|
2013-11-05 13:04:47 -05:00
|
|
|
let(:store) { FileStore::S3Store.new }
|
2013-07-31 17:26:34 -04:00
|
|
|
|
|
|
|
let(:upload) { build(:upload) }
|
2014-04-15 07:04:14 -04:00
|
|
|
let(:uploaded_file) { File.new("#{Rails.root}/spec/fixtures/images/logo.png") }
|
2013-07-31 17:26:34 -04:00
|
|
|
|
|
|
|
let(:optimized_image) { build(:optimized_image) }
|
2014-04-15 07:04:14 -04:00
|
|
|
let(:optimized_image_file) { File.new("#{Rails.root}/spec/fixtures/images/logo.png") }
|
2013-07-31 17:26:34 -04:00
|
|
|
|
2013-11-05 13:04:47 -05:00
|
|
|
let(:avatar) { build(:upload) }
|
2014-04-15 07:04:14 -04:00
|
|
|
let(:avatar_file) { File.new("#{Rails.root}/spec/fixtures/images/logo-dev.png") }
|
2013-11-05 13:04:47 -05:00
|
|
|
|
2013-07-31 17:26:34 -04:00
|
|
|
before(:each) 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!
|
2013-11-27 16:01:41 -05:00
|
|
|
Fog::Mock.reset
|
|
|
|
Fog::Mock.delay = 0
|
2013-07-31 17:26:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after(:each) { Fog.unmock! }
|
|
|
|
|
2013-11-05 13:04:47 -05:00
|
|
|
describe ".store_upload" do
|
2013-07-31 17:26:34 -04:00
|
|
|
|
2013-11-05 13:04:47 -05:00
|
|
|
it "returns an absolute schemaless url" do
|
2013-07-31 17:26:34 -04:00
|
|
|
upload.stubs(:id).returns(42)
|
2013-08-13 16:08:29 -04:00
|
|
|
upload.stubs(:extension).returns(".png")
|
2013-07-31 17:26:34 -04:00
|
|
|
store.store_upload(uploaded_file, upload).should == "//s3_upload_bucket.s3.amazonaws.com/42e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98.png"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-11-05 13:04:47 -05:00
|
|
|
describe ".store_optimized_image" do
|
2013-07-31 17:26:34 -04:00
|
|
|
|
2013-11-05 13:04:47 -05:00
|
|
|
it "returns an absolute schemaless url" do
|
2013-07-31 17:26:34 -04:00
|
|
|
optimized_image.stubs(:id).returns(42)
|
|
|
|
store.store_optimized_image(optimized_image_file, optimized_image).should == "//s3_upload_bucket.s3.amazonaws.com/4286f7e437faa5a7fce15d1ddcb9eaeaea377667b8_100x200.png"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-11-05 13:04:47 -05:00
|
|
|
describe ".store_avatar" do
|
2013-07-31 17:26:34 -04:00
|
|
|
|
2013-11-05 13:04:47 -05:00
|
|
|
it "returns an absolute schemaless url" do
|
|
|
|
avatar.stubs(:id).returns(42)
|
2014-04-14 16:55:57 -04:00
|
|
|
store.store_avatar(avatar_file, avatar, 100).should == "//s3_upload_bucket.s3.amazonaws.com/avatars/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98/100.png"
|
2013-07-31 17:26:34 -04:00
|
|
|
end
|
|
|
|
|
2013-11-05 13:04:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe ".remove_upload" do
|
|
|
|
|
|
|
|
it "calls remove_file with the url" do
|
|
|
|
store.expects(:remove_file).with(upload.url)
|
2013-08-13 16:08:29 -04:00
|
|
|
store.remove_upload(upload)
|
2013-07-31 17:26:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-11-05 13:04:47 -05:00
|
|
|
describe ".remove_optimized_image" do
|
2013-08-13 16:08:29 -04:00
|
|
|
|
2013-11-05 13:04:47 -05:00
|
|
|
it "calls remove_file with the url" do
|
|
|
|
store.expects(:remove_file).with(optimized_image.url)
|
|
|
|
store.remove_optimized_image(optimized_image)
|
|
|
|
end
|
2013-08-13 16:08:29 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-11-05 13:04:47 -05:00
|
|
|
describe ".has_been_uploaded?" do
|
2013-07-31 17:26:34 -04:00
|
|
|
|
|
|
|
it "identifies S3 uploads" do
|
|
|
|
store.has_been_uploaded?("//s3_upload_bucket.s3.amazonaws.com/1337.png").should == true
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not match other s3 urls" do
|
2013-11-05 13:04:47 -05:00
|
|
|
store.has_been_uploaded?("//s3.amazonaws.com/s3_upload_bucket/1337.png").should == false
|
|
|
|
store.has_been_uploaded?("//s4_upload_bucket.s3.amazonaws.com/1337.png").should == false
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ".absolute_base_url" do
|
|
|
|
|
|
|
|
it "returns a lowercase schemaless absolute url" do
|
|
|
|
store.absolute_base_url.should == "//s3_upload_bucket.s3.amazonaws.com"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is external" do
|
|
|
|
store.external?.should == true
|
|
|
|
store.internal?.should == false
|
|
|
|
end
|
|
|
|
|
2014-01-07 11:45:06 -05:00
|
|
|
describe ".avatar_template" do
|
2013-11-05 13:04:47 -05:00
|
|
|
|
|
|
|
it "is present" do
|
2014-04-14 16:55:57 -04:00
|
|
|
store.avatar_template(avatar).should == "//s3_upload_bucket.s3.amazonaws.com/avatars/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98/{size}.png"
|
2013-07-31 17:26:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|