2013-06-16 04:39:48 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe OptimizedImage do
|
|
|
|
|
|
|
|
it { should belong_to :upload }
|
|
|
|
|
2013-07-31 17:26:34 -04:00
|
|
|
let(:upload) { Fabricate(:upload) }
|
|
|
|
let(:oi) { OptimizedImage.create_for(upload, 100, 200) }
|
2013-06-16 20:46:42 -04:00
|
|
|
|
|
|
|
describe ".create_for" do
|
|
|
|
|
2013-07-31 17:26:34 -04:00
|
|
|
before { ImageSorcery.any_instance.expects(:convert).returns(true) }
|
|
|
|
|
|
|
|
describe "internal store" do
|
|
|
|
|
|
|
|
it "works" do
|
|
|
|
Tempfile.any_instance.expects(:close!)
|
|
|
|
oi.sha1.should == "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
|
|
|
oi.extension.should == ".jpg"
|
|
|
|
oi.width.should == 100
|
|
|
|
oi.height.should == 200
|
|
|
|
oi.url.should == "/uploads/default/_optimized/da3/9a3/ee5e6b4b0d3_100x200.jpg"
|
|
|
|
end
|
|
|
|
|
2013-06-16 20:46:42 -04:00
|
|
|
end
|
|
|
|
|
2013-07-31 17:26:34 -04:00
|
|
|
describe "external store" do
|
|
|
|
|
|
|
|
require 'file_store/s3_store'
|
|
|
|
require 'fog'
|
|
|
|
|
|
|
|
let(:store) { S3Store.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Discourse.stubs(:store).returns(store)
|
|
|
|
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 "works" do
|
|
|
|
# fake downloaded file
|
|
|
|
downloaded_file = {}
|
|
|
|
downloaded_file.expects(:path).returns("/path/to/fake.png")
|
|
|
|
downloaded_file.expects(:close!)
|
|
|
|
store.expects(:download).returns(downloaded_file)
|
|
|
|
# assertions
|
|
|
|
oi.sha1.should == "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
|
|
|
oi.extension.should == ".png"
|
|
|
|
oi.width.should == 100
|
|
|
|
oi.height.should == 200
|
|
|
|
oi.url.should =~ /^\/\/s3_upload_bucket.s3.amazonaws.com\/[0-9a-f]+_100x200.png/
|
|
|
|
end
|
|
|
|
|
2013-06-16 20:46:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2013-06-16 04:39:48 -04:00
|
|
|
end
|