Extracted storage of files functionality from controller to an object called FileYard.

There is one file yard per web.
This commit is contained in:
Alexey Verkhovsky 2005-01-23 01:36:51 +00:00
parent 0d81292168
commit 1d82582c3b
7 changed files with 112 additions and 54 deletions

View file

@ -9,7 +9,7 @@ class FileController; def rescue_action(e) logger.error(e); raise e end; end
class FileControllerTest < Test::Unit::TestCase
FILE_AREA = RAILS_ROOT + '/storage/test/wiki'
FILE_AREA = RAILS_ROOT + '/storage/test/wiki1'
FileUtils.mkdir_p(FILE_AREA) unless File.directory?(FILE_AREA)
def setup
@ -22,7 +22,7 @@ class FileControllerTest < Test::Unit::TestCase
end
def test_file
process 'file', 'web' => 'wiki', 'id' => 'foo.tgz'
process 'file', 'web' => 'wiki1', 'id' => 'foo.tgz'
assert_success
assert_rendered_file 'file/file'
@ -31,7 +31,7 @@ class FileControllerTest < Test::Unit::TestCase
def test_file_download_text_file
File.open(FILE_AREA + '/foo.txt', 'wb') { |f| f.write "aaa\nbbb\n" }
r = process 'file', 'web' => 'wiki', 'id' => 'foo.txt'
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.txt'
assert_success
assert_equal "aaa\nbbb\n", r.binary_content
@ -41,7 +41,7 @@ class FileControllerTest < Test::Unit::TestCase
def test_file_download_pdf_file
File.open(FILE_AREA + '/foo.pdf', 'wb') { |f| f.write "aaa\nbbb\n" }
r = process 'file', 'web' => 'wiki', 'id' => 'foo.pdf'
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.pdf'
assert_success
assert_equal "aaa\nbbb\n", r.binary_content

View file

@ -0,0 +1,35 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'fileutils'
require 'file_yard'
require 'stringio'
class FileYardTest < Test::Unit::TestCase
def setup
FileUtils.mkdir_p(file_path)
FileUtils.rm(Dir["#{file_path}/*"])
@yard = FileYard.new(file_path)
end
def test_files
assert_equal [], @yard.files
# FileYard gets the list of files from directory in the constructor
@yard.upload_file('aaa', StringIO.new('file contents'))
assert_equal ["#{file_path}/aaa"], Dir["#{file_path}/*"]
assert_equal ['aaa'], @yard.files
assert @yard.has_file?('aaa')
assert_equal 'file contents', File.read(@yard.file_path('aaa'))
end
def test_file_path
assert_equal "#{file_path}/abcd", @yard.file_path('abcd')
end
def file_path
"#{RAILS_ROOT}/storage/test/instiki"
end
end

View file

@ -8,11 +8,12 @@ class WikiServiceTest < Test::Unit::TestCase
# Clean the test storage directory before the run
unless defined? @@storage_cleaned
FileUtils.rm(Dir[RAILS_ROOT + 'storage/test/*.command_log'])
FileUtils.rm(Dir[RAILS_ROOT + 'storage/test/*.snapshot'])
FileUtils.rm(Dir[RAILS_ROOT + 'storage/test/*.tex'])
FileUtils.rm(Dir[RAILS_ROOT + 'storage/test/*.zip'])
FileUtils.rm(Dir[RAILS_ROOT + 'storage/test/*.pdf'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.command_log'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.snapshot'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.tex'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.zip'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/*.pdf'])
FileUtils.rm(Dir[RAILS_ROOT + '/storage/test/instiki/*'])
@@cleaned_storage = true
WikiService.instance.setup('pswd', 'Wiki', 'wiki')
end
@ -20,6 +21,7 @@ class WikiServiceTest < Test::Unit::TestCase
def setup
@s = WikiService.instance
@s.create_web 'Instiki', 'instiki'
@web = @s.webs['instiki']
end
def teardown
@ -61,6 +63,12 @@ class WikiServiceTest < Test::Unit::TestCase
}
end
def test_file_yard
file_yard = @s.file_yard(@web)
assert_equal FileYard, file_yard.class
assert_equal(@s.storage_path + '/instiki', file_yard.files_path)
end
# Checks that a method call or a block doesn;t change the persisted state of the wiki
# Usage: