From a644d1fefa7794c192168644325c3ff86d6bc23d Mon Sep 17 00:00:00 2001 From: Tam + Dung Date: Thu, 21 Jun 2012 15:38:06 +0700 Subject: [PATCH 1/2] Fix file_create_folder --- lib/dummy_dropbox_sdk.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/dummy_dropbox_sdk.rb b/lib/dummy_dropbox_sdk.rb index 4dc69bf..9e7c3a1 100644 --- a/lib/dummy_dropbox_sdk.rb +++ b/lib/dummy_dropbox_sdk.rb @@ -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 From 7f883fe8d9878c89a6a0d6452e798c080381c5ff Mon Sep 17 00:00:00 2001 From: Tam Vo Date: Sun, 24 Jun 2012 15:05:57 -0400 Subject: [PATCH 2/2] Fix test --- .rvmrc | 4 +++- Gemfile.lock | 11 +++++++---- test/dummy_dropbox_sdk_test.rb | 30 +++++++++++++++++------------- test/fixtures/file.txt | 1 - 4 files changed, 27 insertions(+), 19 deletions(-) delete mode 100644 test/fixtures/file.txt diff --git a/.rvmrc b/.rvmrc index 71c000c..afcfa59 100644 --- a/.rvmrc +++ b/.rvmrc @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 270e641..05bfc94 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,20 +1,23 @@ PATH remote: . specs: - dummy_dropbox_sdk (0.0.11) + dummy_dropbox_sdk (0.0.13) dropbox-sdk (>= 1.1) GEM remote: http://rubygems.org/ specs: - dropbox-sdk (1.1) + ansi (1.4.2) + dropbox-sdk (1.3) json - json (1.6.1) + json (1.7.3) + turn (0.9.5) + ansi PLATFORMS ruby DEPENDENCIES bundler (>= 1.0.0.rc.6) - dropbox-sdk (>= 1.1) dummy_dropbox_sdk! + turn diff --git a/test/dummy_dropbox_sdk_test.rb b/test/dummy_dropbox_sdk_test.rb index 44badef..c0aea57 100644 --- a/test/dummy_dropbox_sdk_test.rb +++ b/test/dummy_dropbox_sdk_test.rb @@ -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 @@ -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 } ) @@ -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 + diff --git a/test/fixtures/file.txt b/test/fixtures/file.txt deleted file mode 100644 index 8773f39..0000000 --- a/test/fixtures/file.txt +++ /dev/null @@ -1 +0,0 @@ -file content \ No newline at end of file