spec/aliyun_spec.rb in carrierwave-aliyun-0.3.6 vs spec/aliyun_spec.rb in carrierwave-aliyun-0.4.0

- old
+ new

@@ -10,42 +10,61 @@ :aliyun_bucket => ALIYUN_BUCKET, :aliyun_area => "cn-hangzhou", :aliyun_internal => true, :aliyun_host => "http://bison-dev.cn-hangzhou.oss.aliyun-inc.com" } - @connection = CarrierWave::Storage::Aliyun::Connection.new(@opts) + + @uploader = CarrierWave::Uploader::Base.new + @connection = CarrierWave::Storage::Aliyun::Connection.new(@uploader) end it "should put" do url = @connection.put("a/a.jpg",load_file("foo.jpg")) - Net::HTTP.get_response(URI.parse(url)).code.should == "200" + res = Net::HTTP.get_response(URI.parse(url)) + expect(res.code).to eq "200" end it "should put with / prefix" do url = @connection.put("/a/a.jpg",load_file("foo.jpg")) - Net::HTTP.get_response(URI.parse(url)).code.should == "200" + res = Net::HTTP.get_response(URI.parse(url)) + expect(res.code).to eq "200" end - + it "should delete" do url = @connection.delete("/a/a.jpg") - Net::HTTP.get_response(URI.parse(url)).code.should == "404" + res = Net::HTTP.get_response(URI.parse(url)) + expect(res.code).to eq "404" end - + it "should support custom domain" do - @opts[:aliyun_host] = "https://foo.bar.com" - @connection = CarrierWave::Storage::Aliyun::Connection.new(@opts) + @uploader.aliyun_host = "https://foo.bar.com" + @connection = CarrierWave::Storage::Aliyun::Connection.new(@uploader) url = @connection.put("a/a.jpg",load_file("foo.jpg")) - url.should == "https://foo.bar.com/a/a.jpg" - @opts[:aliyun_host] = "http://foo.bar.com" - @connection = CarrierWave::Storage::Aliyun::Connection.new(@opts) + expect(url).to eq "https://foo.bar.com/a/a.jpg" + @uploader.aliyun_host = "http://foo.bar.com" + @connection = CarrierWave::Storage::Aliyun::Connection.new(@uploader) url = @connection.put("a/a.jpg",load_file("foo.jpg")) - url.should == "http://foo.bar.com/a/a.jpg" + expect(url).to eq "http://foo.bar.com/a/a.jpg" end - + + describe 'private read bucket' do + before do + @uploader.aliyun_private_read = true + @connection = CarrierWave::Storage::Aliyun::Connection.new(@uploader) + end + + it 'should get url include token' do + url = @connection.private_get_url('bar/foo.jpg') + # http://oss-cn-beijing.aliyuncs.com.//carrierwave-aliyun-test.oss-cn-beijing.aliyuncs.com/bar/foo.jpg?OSSAccessKeyId=1OpWEtPTjIDv5u8q&Expires=1455172009&Signature=4ibgQpfHOjVpqxG6162S8Ar3c6c= + expect(url).to include(*%w(Signature Expires OSSAccessKeyId)) + expect(url).to include "http://#{@uploader.aliyun_bucket}.oss-cn-beijing.aliyuncs.com/bar/foo.jpg" + end + end + describe 'File' do it 'should have respond_to identifier' do - f = CarrierWave::Storage::Aliyun::File.new(nil, nil, nil) - f.should respond_to(:identifier) - f.should respond_to(:filename) + f = CarrierWave::Storage::Aliyun::File.new(@uploader, '', '') + expect(f).to respond_to(:identifier) + expect(f).to respond_to(:filename) end end end