2005-01-22 02:35:00 +01:00
|
|
|
#!/bin/env ruby -w
|
|
|
|
|
|
|
|
require File.dirname(__FILE__) + '/../test_helper'
|
|
|
|
require 'file_controller'
|
2005-01-22 15:58:43 +01:00
|
|
|
require 'fileutils'
|
2005-01-22 02:35:00 +01:00
|
|
|
|
|
|
|
# Raise errors beyond the default web-based presentation
|
|
|
|
class FileController; def rescue_action(e) logger.error(e); raise e end; end
|
|
|
|
|
|
|
|
class FileControllerTest < Test::Unit::TestCase
|
|
|
|
|
2005-01-23 02:36:51 +01:00
|
|
|
FILE_AREA = RAILS_ROOT + '/storage/test/wiki1'
|
2005-01-22 15:58:43 +01:00
|
|
|
FileUtils.mkdir_p(FILE_AREA) unless File.directory?(FILE_AREA)
|
|
|
|
|
2005-01-22 02:35:00 +01:00
|
|
|
def setup
|
|
|
|
setup_test_wiki
|
|
|
|
setup_controller_test
|
|
|
|
end
|
|
|
|
|
|
|
|
def tear_down
|
|
|
|
tear_down_wiki
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_file
|
2005-01-23 02:36:51 +01:00
|
|
|
process 'file', 'web' => 'wiki1', 'id' => 'foo.tgz'
|
2005-01-22 15:58:43 +01:00
|
|
|
|
|
|
|
assert_success
|
|
|
|
assert_rendered_file 'file/file'
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_file_download_text_file
|
2005-01-23 04:52:07 +01:00
|
|
|
File.open("#{FILE_AREA}/foo.txt", 'wb') { |f| f.write "aaa\nbbb\n" }
|
2005-01-22 15:58:43 +01:00
|
|
|
|
2005-01-23 02:36:51 +01:00
|
|
|
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.txt'
|
2005-01-22 15:58:43 +01:00
|
|
|
|
|
|
|
assert_success
|
|
|
|
assert_equal "aaa\nbbb\n", r.binary_content
|
|
|
|
assert_equal 'text/plain', r.headers['Content-Type']
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_file_download_pdf_file
|
2005-01-23 04:52:07 +01:00
|
|
|
File.open("#{FILE_AREA}/foo.pdf", 'wb') { |f| f.write "aaa\nbbb\n" }
|
2005-01-22 15:58:43 +01:00
|
|
|
|
2005-01-23 02:36:51 +01:00
|
|
|
r = process 'file', 'web' => 'wiki1', 'id' => 'foo.pdf'
|
2005-01-22 15:58:43 +01:00
|
|
|
|
|
|
|
assert_success
|
|
|
|
assert_equal "aaa\nbbb\n", r.binary_content
|
|
|
|
assert_equal 'application/pdf', r.headers['Content-Type']
|
2005-01-22 02:35:00 +01:00
|
|
|
end
|
|
|
|
|
2005-01-23 04:52:07 +01:00
|
|
|
def test_pic_download_gif
|
|
|
|
FileUtils.cp("#{RAILS_ROOT}/test/fixtures/rails.gif", FILE_AREA)
|
|
|
|
|
|
|
|
r = process 'pic', 'web' => 'wiki1', 'id' => 'rails.gif'
|
|
|
|
|
|
|
|
assert_success
|
|
|
|
assert_equal File.size("#{FILE_AREA}/rails.gif"), r.binary_content.size
|
|
|
|
end
|
|
|
|
|
2005-01-22 02:35:00 +01:00
|
|
|
end
|