mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
121 lines
3.6 KiB
Ruby
121 lines
3.6 KiB
Ruby
require File.dirname(__FILE__) + '/../../../spec_helper'
|
|
|
|
describe 'Fog::Google::Storage::File' do
|
|
|
|
before(:each) do
|
|
@directory = Google[:storage].directories.create(:key => 'fogdirectoryname')
|
|
end
|
|
|
|
after(:each) do
|
|
@directory.destroy
|
|
end
|
|
|
|
describe "#initialize" do
|
|
|
|
it "should remap attributes from parser" do
|
|
now = Time.now
|
|
directory = Fog::Google::Storage::File.new(
|
|
'Content-Length' => 10,
|
|
'Content-Type' => 'contenttype',
|
|
'Etag' => 'etag',
|
|
'Key' => 'key',
|
|
'Last-Modified' => now,
|
|
'Size' => 10,
|
|
'StorageClass' => 'storageclass'
|
|
)
|
|
directory.content_length == 10
|
|
directory.content_type.should == 'contenttype'
|
|
directory.etag.should == 'etag'
|
|
directory.key.should == 'key'
|
|
directory.last_modified.should == now
|
|
directory.size.should == 10
|
|
directory.storage_class.should == 'storageclass'
|
|
|
|
directory = Fog::Google::Storage::File.new(
|
|
'ETag' => 'etag',
|
|
'LastModified' => now
|
|
)
|
|
directory.etag.should == 'etag'
|
|
directory.last_modified.should == now
|
|
end
|
|
|
|
end
|
|
|
|
describe "#directory" do
|
|
|
|
it "should be the directory the file is related to" do
|
|
@file = @directory.files.new(:key => 'foo')
|
|
@file.directory.should == @directory
|
|
end
|
|
|
|
end
|
|
|
|
describe "#copy" do
|
|
|
|
it "should return a Fog::Google::Storage::File with matching attributes" do
|
|
other_directory = Google[:storage].directories.create(:key => 'fogotherdirectoryname')
|
|
data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
|
|
file = @directory.files.create(:key => 'fogfilename', :body => data)
|
|
other_file = file.copy('fogotherdirectoryname', 'fogotherfilename')
|
|
file.reload.attributes.reject{|key,value| [:key, :last_modified].include?(key)}.should == other_file.reload.attributes.reject{|key,value| [:key, :last_modified].include?(key)}
|
|
other_file.destroy
|
|
file.destroy
|
|
other_directory.destroy
|
|
end
|
|
|
|
end
|
|
|
|
describe "#destroy" do
|
|
|
|
it "should return true if the file is deleted" do
|
|
data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
|
|
file = @directory.files.create(:key => 'fogfilename', :body => data)
|
|
file.destroy.should be_true
|
|
end
|
|
|
|
it "should return true if the file does not exist" do
|
|
file = @directory.files.new(:key => 'fogfilename')
|
|
file.destroy.should be_true
|
|
end
|
|
|
|
end
|
|
|
|
describe "#reload" do
|
|
|
|
it "should reset attributes to remote state" do
|
|
data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
|
|
file = @directory.files.create(:key => 'fogfilename', :body => data)
|
|
file.last_modified = Time.now
|
|
file.reload.attributes.should == file.attributes
|
|
file.destroy
|
|
end
|
|
|
|
end
|
|
|
|
describe "#save" do
|
|
|
|
it "should return the success value" do
|
|
data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
|
|
file = @directory.files.new(:key => 'fogfilename', :body => data)
|
|
file.save.should be_true
|
|
file.destroy
|
|
end
|
|
|
|
end
|
|
|
|
# describe "#url" do
|
|
#
|
|
# it "should return a signed expiring url" do
|
|
# data = File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r')
|
|
# file = @directory.files.create(:key => 'fogfilename', :body => data)
|
|
# url = file.url(Time.now + 60 * 10)
|
|
# url.should include("fogfilename", "Expires")
|
|
# unless Fog.mocking?
|
|
# open(url).read.should == File.open(File.dirname(__FILE__) + '/../../../lorem.txt', 'r').read
|
|
# end
|
|
# file.destroy
|
|
# end
|
|
#
|
|
# end
|
|
|
|
end
|