Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Conflicts:
	Gemfile.lock
  • Loading branch information
panterch committed Jun 24, 2012
2 parents facc1e6 + 7f883fe commit 130af4a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
4 changes: 3 additions & 1 deletion .rvmrc
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
rvm use 1.8.7@dummy_dropbox
rvm use 1.8.7@dummy_dropbox --create
echo rvm_auto_reload_flag=1 >> ~/.rvmrc
echo rvm_auto_reload_flag=2 >> ~/.rvmrc
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ PATH
GEM
remote: http://rubygems.org/
specs:
dropbox-sdk (1.1)
dropbox-sdk (1.3)
json
json (1.6.1)
mime-types (1.18)
json (1.7.3)
mime-types (1.19)

PLATFORMS
ruby
Expand Down
12 changes: 7 additions & 5 deletions lib/dummy_dropbox_sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,32 @@ def initialize(session, root="app_folder", locale=nil)
end

def file_create_folder(path, options={})
FileUtils.mkdir( "#{DummyDropbox::root_path}/#{path}" )
file_path = File.join(DummyDropbox::root_path, path)
raise DropboxError.new("Folder exists!") if File.exists?(file_path)
FileUtils.mkdir(file_path)
# intercepted result:
# {"modified"=>"Wed, 23 Nov 2011 10:24:37 +0000", "bytes"=>0, "size"=>"0
# bytes", "is_dir"=>true, "rev"=>"2f04dc6147", "icon"=>"folder",
# "root"=>"app_folder", "path"=>"/test_from_console", "thumb_exists"=>false,
# "revision"=>47}
return self.metadata( path )
return self.metadata(path)
end

def metadata(path, options={})
dummy_path = "#{DummyDropbox::root_path}/#{path}"
dummy_path = File.join(DummyDropbox::root_path, path)
raise DropboxError.new("File not found") unless File.exists?(dummy_path)

list_hash_files = []
if File.directory?(dummy_path)
Dir.entries(dummy_path).each do |file_name|
file_path = "#{dummy_path}/#{file_name}"
file_path = File.join(dummy_path, file_name)
unless File.directory?(file_path)
list_hash_files << {"size" => readable_file_size(File.size(file_path), 2),
"bytes" => File.size(file_path),
"is_dir" => false,
"modified" => File.mtime(file_path),
"mime_type" => MIME::Types.type_for(file_path)[0].content_type,
"path" => "#{path}/#{file_name}"}
"path" => File.join(path, file_name)}
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DummyDropbox
VERSION = '0.0.13'
VERSION = '0.0.14'
end
30 changes: 17 additions & 13 deletions test/dummy_dropbox_sdk_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def setup
@session = DropboxSession.new('key', 'secret')
@client = DropboxClient.new(@session)
end

def test_serialize
assert_equal("--- dummy serial\n", @session.serialize )
end
Expand All @@ -29,29 +29,32 @@ def test_create_folder
metadata = @client.file_create_folder '/tmp_folder'
assert( File.directory?( "#{DummyDropbox.root_path}/tmp_folder" ) )
assert_equal(true, metadata["is_dir"])

FileUtils.rm_r( "#{DummyDropbox.root_path}/tmp_folder" )
end

def test_upload
FileUtils.rm_r( "#{DummyDropbox.root_path}/file.txt" ) if File.exists?( "#{DummyDropbox.root_path}/file.txt" )
file_fixture = File.new("#{File.dirname(__FILE__)}/fixtures/file.txt")
File.open("test/file.txt", "w"){|f| f.write("file content")}
DummyDropbox.root_path = "test/"

file_fixture = File.new("#{File.dirname(__FILE__)}/file.txt")
metadata = @client.put_file('file.txt', file_fixture)
assert_equal(
file_fixture.read,
assert_equal(
File.read("#{File.dirname(__FILE__)}/file.txt"),
File.read( "#{DummyDropbox.root_path}/file.txt" )
)
assert( !metadata['is_dir'] )
assert(!metadata["is_dir"])
FileUtils.rm_r( "#{DummyDropbox.root_path}/file.txt" )
end

# TODO these methods I don't used yet. They are commented out because they
# have to be checked against the api if the signature match

# def test_download
# assert_equal( "File 1", @session.download( '/file1.txt' ) )
# end
#
#
# def test_list
# assert_equal(['/file1.txt', '/folder1'], @session.list('').map{ |e| e.path } )
# assert_equal(['folder1/file2.txt', 'folder1/file3.txt'], @session.list('folder1').map{ |e| e.path } )
Expand All @@ -61,14 +64,15 @@ def test_upload
# FileUtils.mkdir_p( "#{DummyDropbox.root_path}/tmp_folder" )
# 3.times { |i| FileUtils.touch( "#{DummyDropbox.root_path}/tmp_folder/#{i}.txt" ) }
#
# assert( File.exists?( "#{DummyDropbox.root_path}/tmp_folder" ) )
# assert( File.exists?( "#{DummyDropbox.root_path}/tmp_folder" ) )
# assert( File.exists?( "#{DummyDropbox.root_path}/tmp_folder/0.txt" ) )
#
#
# metadata = @session.delete '/tmp_folder/0.txt'
# assert( !File.exists?( "#{DummyDropbox.root_path}/tmp_folder/0.txt" ) )
#
#
# metadata = @session.delete '/tmp_folder'
# assert( !File.exists?( "#{DummyDropbox.root_path}/tmp_folder" ) )
# end

end

1 change: 0 additions & 1 deletion test/fixtures/file.txt

This file was deleted.

0 comments on commit 130af4a

Please sign in to comment.