[BUILD STILL BROKEN] File uploads roughly speaking work (to about same extent as in 0.10)

This commit is contained in:
Alexey Verkhovsky 2005-11-14 08:38:37 +00:00
parent ac72f9b807
commit 0b1a80a852
13 changed files with 172 additions and 297 deletions

View file

@ -38,8 +38,6 @@ class ApplicationController < ActionController::Base
return false return false
end end
end end
@page_name = @file_name = @params['id']
@page = @wiki.read_page(@web_name, @page_name) unless @page_name.nil?
@author = cookies['author'] || 'AnonymousCoward' @author = cookies['author'] || 'AnonymousCoward'
end end

View file

@ -9,23 +9,26 @@ class FileController < ApplicationController
def file def file
if @params['file'] if @params['file']
# form supplied # form supplied
new_file = upload_file(@file_name, @params['file']) new_file = @web.wiki_files.create(@params['file'])
if new_file.valid? if new_file.valid?
flash[:info] = "File '#{@file_name}' successfully uploaded" flash[:info] = "File '#{@file_name}' successfully uploaded"
return_to_last_remembered return_to_last_remembered
else else
# FIXME handle validation errors more gracefully # pass the file with errors back into the form
flash[:errors] = new_file.errors.to_s @file = new_file
render
end end
else else
(render(:status => 404, :text => 'Unspecified file name') and return) unless @file_name
# no form supplied, this is a request to download the file # no form supplied, this is a request to download the file
file = WikiFile.find_by_file_name(@file_name) file = WikiFile.find_by_file_name(@file_name)
if file if file
send_data(file.content, :filename => @file_name, :type => content_type_header(@file_name)) send_data(file.content, :filename => @file_name, :type => content_type_header(@file_name))
else
@file = WikiFile.new(:file_name => @file_name)
render
end end
end end
# if it's neither a supplied form for upload, nor a request for a known file,
# display the file/file.rhtml template (which happens to be an upload form)
end end
def cancel_upload def cancel_upload
@ -41,7 +44,7 @@ class FileController < ApplicationController
if @problems.empty? if @problems.empty?
flash[:info] = 'Import successfully finished' flash[:info] = 'Import successfully finished'
else else
flash[:error] = "Import finished, but some pages were not imported:<li>" + flash[:error] = 'Import finished, but some pages were not imported:<li>' +
@problems.join('</li><li>') + '</li>' @problems.join('</li><li>') + '</li>'
end end
return_to_last_remembered return_to_last_remembered
@ -60,6 +63,11 @@ class FileController < ApplicationController
return false return false
end end
end end
def connect_to_model
super
@file_name = @params['id']
end
private private

View file

@ -272,9 +272,16 @@ class WikiController < ApplicationController
@tex_content = RedClothForTex.new(@page.content).to_tex @tex_content = RedClothForTex.new(@page.content).to_tex
end end
protected
def connect_to_model
super
@page_name = @params['id']
@page = @wiki.read_page(@web_name, @page_name) if @page_name
end
private private
def convert_tex_to_pdf(tex_path) def convert_tex_to_pdf(tex_path)
# TODO remove earlier PDF files with the same prefix # TODO remove earlier PDF files with the same prefix
# TODO handle gracefully situation where pdflatex is not available # TODO handle gracefully situation where pdflatex is not available

View file

@ -6,10 +6,6 @@ class Web < ActiveRecord::Base
Wiki.new Wiki.new
end end
def file_yard
@file_yard ||= FileYard.new("#{Wiki.storage_path}/#{address}", max_upload_size)
end
def settings_changed?(markup, safe_mode, brackets_only) def settings_changed?(markup, safe_mode, brackets_only)
self.markup != markup || self.markup != markup ||
self.safe_mode != safe_mode || self.safe_mode != safe_mode ||
@ -84,6 +80,23 @@ class Web < ActiveRecord::Base
address address
end end
def create_files_directory
return unless allow_uploads == 1
dummy_file = self.wiki_files.build(:file_name => '0', :description => '0', :content => '0')
dir = File.dirname(dummy_file.content_path)
begin
require 'fileutils'
FileUtils.mkdir_p dir
dummy_file.save
dummy_file.destroy
rescue => e
logger.error("Failed create files directory for #{self.address}: #{e}")
raise "Instiki could not create directory to store uploaded files. " +
"Please make sure that Instiki is allowed to create directory " +
"#{File.expand_path(dir)} and add files to it."
end
end
private private
# Returns an array of all the wiki words in any current revision # Returns an array of all the wiki words in any current revision
@ -114,32 +127,15 @@ class Web < ActiveRecord::Base
end end
end end
def create_files_directory
return unless allow_uploads == 1
dummy_file = self.wiki_files.build(:file_name => '0', :description => '0', :content => '0')
dir = File.dirname(dummy_file.content_path)
begin
require 'fileutils'
FileUtils.mkdir_p dir
dummy_file.save
dummy_file.destroy
rescue => e
logger.error("Failed create files directory for #{self.address}: #{e}")
raise "Instiki could not create directory to store uploaded files. " +
"Please make sure that Instiki is allowed to create directory " +
"#{File.expand_path(dir)} and add files to it."
end
end
def default_web? def default_web?
defined? DEFAULT_WEB and self.address == DEFAULT_WEB defined? DEFAULT_WEB and self.address == DEFAULT_WEB
end end
def files_path def files_path
if default_web? if default_web?
"#{RAILS_ROOT}/public/#{self.address}/files"
else
"#{RAILS_ROOT}/public/files" "#{RAILS_ROOT}/public/files"
else
"#{RAILS_ROOT}/public/#{self.address}/files"
end end
end end
end end

View file

@ -4,9 +4,9 @@ class WikiFile < ActiveRecord::Base
before_save :write_content_to_file before_save :write_content_to_file
before_destroy :delete_content_file before_destroy :delete_content_file
validates_presence_of %w( web file_name description ) validates_presence_of %w( web file_name )
validates_length_of :file_name, :within=>1..50 validates_length_of :file_name, :within=>1..50
validates_length_of :description, :within=>1..255 validates_length_of :description, :maximum=>255
def self.find_by_file_name(file_name) def self.find_by_file_name(file_name)
find(:first, :conditions => ['file_name = ?', file_name]) find(:first, :conditions => ['file_name = ?', file_name])
@ -34,7 +34,11 @@ class WikiFile < ActiveRecord::Base
end end
def content=(content) def content=(content)
@content = content if content.respond_to? :read
@content = content.read
else
@content = content
end
end end
def content def content
@ -46,6 +50,7 @@ class WikiFile < ActiveRecord::Base
end end
def write_content_to_file def write_content_to_file
web.create_files_directory unless File.exists?(web.files_path)
File.open(self.content_path, 'wb') { |f| f.write(@content) } File.open(self.content_path, 'wb') { |f| f.write(@content) }
end end
@ -54,4 +59,6 @@ class WikiFile < ActiveRecord::Base
FileUtils.rm_f(content_path) if File.exists?(content_path) FileUtils.rm_f(content_path) if File.exists?(content_path)
end end
end end

View file

@ -48,9 +48,6 @@
<input type="checkbox" name="count_pages" <%= 'checked="on"' if @web.count_pages %> /> <input type="checkbox" name="count_pages" <%= 'checked="on"' if @web.count_pages %> />
Count pages Count pages
<br/> <br/>
<!--
File uploads are not ready for gfeneral use, and therefore are disabled in release 0.10
TODO Enable these input elements again after release 0.10
<input type="checkbox" name="allow_uploads" <%= 'checked="on"' if @web.allow_uploads %> /> <input type="checkbox" name="allow_uploads" <%= 'checked="on"' if @web.allow_uploads %> />
Allow uploads of no more than Allow uploads of no more than
@ -61,7 +58,6 @@ TODO Enable these input elements again after release 0.10
allow users to upload pictures and other files and include them on wiki pages allow users to upload pictures and other files and include them on wiki pages
</em> </em>
<br/> <br/>
-->
</small> </small>
</p> </p>

View file

@ -1,19 +1,32 @@
<% <%
@title = "Upload #{@file_name}" @title = "Upload #{h @file_name}"
@hide_navigation = false @hide_navigation = false
%> %>
<p> <%= error_messages_for 'file' %>
<%= form_tag({:controller => 'file', :web => @web_name, :action => 'file'}, {:multipart => true}) %> <%= form_tag({:controller => 'file', :web => @web_name, :action => 'file'}, {:multipart => true}) %>
<p> <%= hidden_field 'file', 'file_name' %>
File to upload: <div class="inputFieldWithPrompt">
<b>Content of <%= h @file_name %> to upload <small>(required)</small>:</b>
<br/> <br/>
<input type="file" name="file" size="40" /> <input type="file" name="file[content]" size="40" />
</p> <br/>
<p> <small>
<input type="submit" value="Update" /> as Please note that the file you are uploadng will be named <%= h @file_name %> on the wiki -
<input type="text" name="author" id="authorName" value="<%= @author %>" regardless of how it is named on your computer. To change the wiki name of the file, please go
onClick="this.value == 'AnonymousCoward' ? this.value = '' : true" /> <%= link_to :back %> and edit the wiki page that refers to the file.
</p> </small>
<%= end_form_tag %> </div>
</p> <div class="inputFieldWithPrompt">
<b>Description <small>(optional)</small>:</b>
<br/>
<%= text_field "file", "description", "size" => 40 %>
</div>
<div>
<input type="submit" value="Upload" /> as
<%= text_field_tag :author, @author,
:onfocus => "this.value == 'AnonymousCoward' ? this.value = '' : true;",
:onblur => "this.value == '' ? this.value = 'AnonymousCoward' : true" %>
</div>
<%= end_form_tag %>

View file

@ -55,15 +55,16 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<% end %> <% end %>
</h1> </h1>
<% if @error or @flash[:error] %> <div id="error">
<hr/><p><%= escape_preserving_linefeeds(@error || @flash[:error]) %></p><hr/></div>
<% end %>
<% if @flash[:info] %> <div id="info"> <% if @flash[:info] %> <div id="info">
<hr/><p><%= escape_preserving_linefeeds @flash[:info] %></p><hr/></div> <hr/><p><%= escape_preserving_linefeeds @flash[:info] %></p><hr/></div>
<% end %> <% end %>
<%= render 'navigation' unless @web.nil? || @hide_navigation %> <%= render 'navigation' unless @web.nil? || @hide_navigation %>
<% if @error or @flash[:error] %>
<div class="errorExplanation"><%= escape_preserving_linefeeds(@error || @flash[:error]) %></div>
<% end %>
<%= @content_for_layout %> <%= @content_for_layout %>
<% if @show_footer %> <% if @show_footer %>

View file

@ -47,14 +47,14 @@ class UrlGenerator < AbstractUrlGenerator
end end
when :publish when :publish
if known_file if known_file
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'published', href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
:id => name :id => name
%{<a class="existingWikiWord" href="#{href}">#{text}</a>} %{<a class="existingWikiWord" href="#{href}">#{text}</a>}
else else
%{<span class="newWikiWord">#{text}</span>} %{<span class="newWikiWord">#{text}</span>}
end end
else else
href = @controller.url_for :controller => 'wiki', :web => web_address, :action => 'file', href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
:id => name :id => name
if known_file if known_file
%{<a class="existingWikiWord" href="#{href}">#{text}</a>} %{<a class="existingWikiWord" href="#{href}">#{text}</a>}
@ -108,7 +108,7 @@ class UrlGenerator < AbstractUrlGenerator
%{<span class="newWikiWord">#{text}</span>} %{<span class="newWikiWord">#{text}</span>}
end end
else else
href = @controller.url_for @controller => 'file', :web => web_address, :action => 'pic', href = @controller.url_for :controller => 'file', :web => web_address, :action => 'file',
:id => name :id => name
if known_pic if known_pic
%{<img alt="#{text}" src="#{href}" />} %{<img alt="#{text}" src="#{href}" />}

View file

@ -1,31 +1,12 @@
#Container {
float: none;
margin: 0 auto;
text-align: center;
}
#Content {
margin: 0;
padding: 5px;
text-align: left;
border-top: none;
float: left;
}
body { background-color: #fff; color: #333; } body { background-color: #fff; color: #333; }
body, p, ol, ul, td { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px; }
body, p, ol, ul, td { #Container { float: none; margin: 0 auto; text-align: center; }
font-family: verdana, arial, helvetica, sans-serif; #Content { margin: 0; padding: 5px; text-align: left; border-top: none; float: left; }
font-size: 13px;
line-height: 18px;
}
a { color: #000; } a { color: #000; }
a:visited { color: #666; } a:visited { color: #666; }
a:hover { a:hover { color: #fff; background-color:#000; }
color: #fff;
background-color:#000;
}
.newWikiWord { background-color: #eee; } .newWikiWord { background-color: #eee; }
.newWikiWord a:hover { background-color: white; } .newWikiWord a:hover { background-color: white; }
@ -35,208 +16,72 @@ h1 { font-size: 28px }
h2 { font-size: 19px } h2 { font-size: 19px }
h3 { font-size: 16px } h3 { font-size: 16px }
h1#pageName { h1#pageName { margin: 5px 0 0; padding: 0; line-height: 28px; }
margin: 5px 0 0; h1#pageName small { color: #444; line-height: 10px; font-size: 10px; padding: 0; }
padding: 0;
line-height: 28px;
}
h1#pageName small {
color: #444;
line-height: 10px;
font-size: 10px;
padding: 0;
}
a.nav, a.nav:link, a.nav:visited { color: #000; } a.nav, a.nav:link, a.nav:visited { color: #000; }
a.nav:hover { color: #fff; background-color:#000; } a.nav:hover { color: #fff; background-color:#000; }
li { margin-bottom: 7px } li { margin-bottom: 7px }
.navigation { .navigation { margin-top: 5px; font-size : 12px; color: #999; }
margin-top: 5px;
font-size : 12px;
color: #999;
}
.navigation a:hover { color: #fff; background-color:#000; } .navigation a:hover { color: #fff; background-color:#000; }
.navigation a { font-size: 11px; color: black; font-weight: bold; }
.navigation a { .navigation small a { font-weight: normal; font-size: 11px; }
font-size: 11px;
color: black;
font-weight: bold;
}
.navigation small a {
font-weight: normal;
font-size: 11px;
}
.navOn{ .navOn{ font-size: 11px; color: #444; font-weight: bold; text-decoration: none; }
font-size: 11px;
color: #444;
font-weight: bold;
text-decoration: none;
}
.help { .help { font-family: verdana, arial, helvetica, sans-serif; font-size: 11px; }
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px;
}
.inputBox { .inputBox { font-family: verdana, arial, helvetica, sans-serif; font-size: 11px; background-color: #eee; padding: 5px; margin-bottom: 20px; }
font-family: verdana, arial, helvetica, sans-serif;
font-size: 11px;
background-color: #eee;
padding: 5px;
margin-bottom: 20px;
}
blockquote { blockquote { display: block; margin: 0px 0px 20px 0px; padding: 0px 30px; font-size:11px; line-height:17px; font-style: italic; }
display: block;
margin: 0px 0px 20px 0px;
padding: 0px 30px;
font-size:11px;
line-height:17px;
font-style: italic;
}
pre { pre { background-color: #eee; padding: 10px; font-size: 11px; overflow: auto; }
background-color: #eee;
padding: 10px;
font-size: 11px;
overflow: auto;
}
ol.setup { ol.setup { font-size: 19px; font-family: georgia, verdana, sans-serif; padding-left: 25px; }
font-size: 19px; ol.setup li { margin-bottom: 20px }
font-family: georgia, verdana, sans-serif;
padding-left: 25px;
}
ol.setup li { .byline { font-size: 10px; font-style: italic; margin-bottom: 10px; color: #999; }
margin-bottom: 20px
}
.byline { .references { font-size: 10px; }
font-size: 10px;
font-style: italic;
margin-bottom: 10px;
color: #999;
}
.references { .diffdel, del.diffmod { background: pink; }
font-size: 10px; .diffins, ins.diffmod { background: lightgreen; }
}
.diffdel, del.diffmod { #footer { height: 14px; padding: .25em 0; }
background: pink; #footer p { font-size: 10px; color: gray; font-style: italic; margin: 0; float: right; text-align: right; }
}
.diffins, ins.diffmod { div.inputFieldWithPrompt { margin: 0.75em 0; }
background: lightgreen;
}
#footer {
height: 14px;
padding: .25em 0;
}
#footer p { div.errorExplanation { color: #900; font-style: italic; font-weight: bold; margin: 1.5em 0; padding: 1em; background: #FFA; }
font-size: 10px; div.errorExplanation h2 { display: none; }
color: gray; div.errorExplanation p { padding: 0; margin: 0; border: none; }
font-style: italic; div.errorExplanation ul { padding: 0; margin: 0.5em 0 0 2em; border: none; }
margin: 0; div.errorExplanation li { padding 0; margin: 0; border: none; }
float: right; div.fieldWithErrors input { border: 1px solid #900; }
text-align: right;
}
#error {
color: #900;
font-style: italic;
font-weight: bold;
width: 600px;
}
#info {
color: #060;
font-style: italic;
width: 600px;
}
#TextileHelp table { #info { color: #060; font-style: italic; width: 600px; }
margin-bottom: 0; #TextileHelp table { margin-bottom: 0; }
} #TextileHelp table+h3 { margin-top: 11px; }
#TextileHelp table td { font-size: 11px; padding: 3px; vertical-align: top; border-top: 1px dotted #ccc; }
#TextileHelp table td.arrow { padding-right: 5px; padding-left: 10px; color: #999; }
#TextileHelp table td.label { font-weight: bold; white-space: nowrap; font-size: 10px; padding-right: 15px; color: #000; }
#TextileHelp h3 { font-size: 11px; font-weight: bold; font-weight: normal; margin: 0 0 5px 0; padding: 5px 0 0 0; }
#TextileHelp p { font-size: 10px; }
#TextileHelp table+h3 { .rightHandSide { float: right; width: 147px; margin-left: 10px; padding-left: 20px; border-left: 1px dotted #ccc; }
margin-top: 11px; .rightHandSide p { font-size: 10px; }
}
#TextileHelp table td { .newsList { margin-top: 20px; }
font-size: 11px; .newsList p { margin-bottom:30px; }
padding: 3px;
vertical-align: top;
border-top: 1px dotted #ccc;
}
#TextileHelp table td.arrow { table { border: double black; border-collapse: collapse; }
padding-right: 5px; td { border:thin solid grey; }
padding-left: 10px; .byline { padding-top: 15px; }
color: #999;
}
#TextileHelp table td.label {
font-weight: bold;
white-space: nowrap;
font-size: 10px;
padding-right: 15px;
color: #000;
}
#TextileHelp h3 {
font-size: 11px;
font-weight: bold;
font-weight: normal;
margin: 0 0 5px 0;
padding: 5px 0 0 0;
}
#TextileHelp p {
font-size: 10px;
}
.rightHandSide {
float: right;
width: 147px;
margin-left: 10px;
padding-left: 20px;
border-left: 1px dotted #ccc;
}
.rightHandSide p {
font-size: 10px;
}
.newsList {
margin-top: 20px;
}
.newsList p {
margin-bottom:30px
}
td {border:thin solid grey;}
table {
border: double black;
border-collapse: collapse;
}
.byline {
padding-top: 15px;
}
/* Affects the display of "category: ..." */ /* Affects the display of "category: ..." */
.property { .property { color: grey; font-size: 10px; }
color: grey;
font-size: 10px;
}

View file

@ -16,6 +16,7 @@ class FileControllerTest < Test::Unit::TestCase
@request = ActionController::TestRequest.new @request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new @response = ActionController::TestResponse.new
@web = webs(:test_wiki) @web = webs(:test_wiki)
@wiki = Wiki.new
WikiFile.delete_all WikiFile.delete_all
require 'fileutils' require 'fileutils'
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*") FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*")
@ -61,37 +62,40 @@ class FileControllerTest < Test::Unit::TestCase
assert_equal pic, r.body assert_equal pic, r.body
end end
# def test_pic_unknown_pic def test_pic_unknown_pic
# r = process 'pic', 'web' => 'wiki1', 'id' => 'non-existant.gif' r = get :file, :web => 'wiki1', :id => 'non-existant.gif'
#
# assert_success assert_success
# assert_rendered_file 'file/file' assert_rendered_file 'file/file'
# end end
#
# def test_pic_upload_end_to_end def test_pic_upload_end_to_end
# # edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif' # edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif'
# @wiki.revise_page('wiki1', 'HomePage', '[[rails-e2e.gif:pic]]', Time.now, 'AnonymousBrave') PageRenderer.setup_url_generator(StubUrlGenerator.new)
# assert_equal "<p><span class=\"newWikiWord\">rails-e2e.gif<a href=\"../pic/rails-e2e.gif\">" + renderer = PageRenderer.new
# "?</a></span></p>", @wiki.revise_page('wiki1', 'HomePage', '[[rails-e2e.gif:pic]]',
# @home.display_content Time.now, 'AnonymousBrave', renderer)
# assert_equal "<p><span class=\"newWikiWord\">rails-e2e.gif<a href=\"../file/rails-e2e.gif\">" +
# # rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form "?</a></span></p>",
# r = process 'pic', 'web' => 'wiki1', 'id' => 'rails-e2e.gif' renderer.display_content
# assert_success
# assert_rendered_file 'file/file' # rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form
# r = get :file, :web => 'wiki1', :id => 'rails-e2e.gif'
# # User uploads the picture assert_success
# picture = File.read("#{RAILS_ROOT}/test/fixtures/rails.gif") assert_rendered_file 'file/file'
# r = process 'pic', 'web' => 'wiki1', 'id' => 'rails-e2e.gif', 'file' => StringIO.new(picture)
# assert_redirect_url '/' # User uploads the picture
# assert @wiki.file_yard(@web).has_file?('rails-e2e.gif') picture = File.read("#{RAILS_ROOT}/test/fixtures/rails.gif")
# assert_equal(picture, File.read("#{RAILS_ROOT}/storage/test/wiki1/rails-e2e.gif")) r = get :file, :web => 'wiki1', :id => 'rails-e2e.gif', :file => StringIO.new(picture)
# assert_redirect_url '/'
# # this should refresh the page display content (cached) assert @web.has_file?('rails-e2e.gif')
# assert_equal "<p><img alt=\"rails-e2e.gif\" src=\"../pic/rails-e2e.gif\" /></p>", assert_equal(picture, File.read("#{RAILS_ROOT}/public/file/rails-e2e.gif"))
# @home.display_content
# end # this should refresh the page display content (cached)
# assert_equal "<p><img alt=\"rails-e2e.gif\" src=\"../pic/rails-e2e.gif\" /></p>",
@home.display_content
end
# def test_pic_upload_end_to_end # def test_pic_upload_end_to_end
# # edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif' # # edit and re-render home page so that it has an "unknown file" link to 'rails-e2e.gif'
# @wiki.revise_page('wiki1', 'HomePage', '[[instiki-e2e.txt:file]]', Time.now, 'AnonymousBrave', # @wiki.revise_page('wiki1', 'HomePage', '[[instiki-e2e.txt:file]]', Time.now, 'AnonymousBrave',

View file

@ -150,8 +150,8 @@ class StubUrlGenerator < AbstractUrlGenerator
if known_pic then %{<img alt="#{text}" src="#{link}" />} if known_pic then %{<img alt="#{text}" src="#{link}" />}
else %{<span class="newWikiWord">#{text}</span>} end else %{<span class="newWikiWord">#{text}</span>} end
else else
if known_pic then %{<img alt="#{text}" src="../pic/#{link}" />} if known_pic then %{<img alt="#{text}" src="../file/#{link}" />}
else %{<span class="newWikiWord">#{text}<a href="../pic/#{link}">?</a></span>} end else %{<span class="newWikiWord">#{text}<a href="../file/#{link}">?</a></span>} end
end end
end end
end end

View file

@ -282,20 +282,20 @@ class PageRendererTest < Test::Unit::TestCase
FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*") FileUtils.rm_rf("#{RAILS_ROOT}/public/wiki1/files/*")
@web.wiki_files.create(:file_name => 'square.jpg', :description => 'Square', :content => 'never mind') @web.wiki_files.create(:file_name => 'square.jpg', :description => 'Square', :content => 'never mind')
assert_markup_parsed_as( assert_markup_parsed_as(
'<p><img alt="Square" src="../pic/square.jpg" /></p>', '<p><img alt="Square" src="../file/square.jpg" /></p>',
'[[square.jpg|Square:pic]]') '[[square.jpg|Square:pic]]')
assert_markup_parsed_as( assert_markup_parsed_as(
'<p><img alt="square.jpg" src="../pic/square.jpg" /></p>', '<p><img alt="square.jpg" src="../file/square.jpg" /></p>',
'[[square.jpg:pic]]') '[[square.jpg:pic]]')
end end
def test_link_to_non_existant_pic def test_link_to_non_existant_pic
assert_markup_parsed_as( assert_markup_parsed_as(
'<p><span class="newWikiWord">NonExistant<a href="../pic/NonExistant.jpg">?</a>' + '<p><span class="newWikiWord">NonExistant<a href="../file/NonExistant.jpg">?</a>' +
'</span></p>', '</span></p>',
'[[NonExistant.jpg|NonExistant:pic]]') '[[NonExistant.jpg|NonExistant:pic]]')
assert_markup_parsed_as( assert_markup_parsed_as(
'<p><span class="newWikiWord">NonExistant.jpg<a href="../pic/NonExistant.jpg">?</a>' + '<p><span class="newWikiWord">NonExistant.jpg<a href="../file/NonExistant.jpg">?</a>' +
'</span></p>', '</span></p>',
'[[NonExistant.jpg:pic]]') '[[NonExistant.jpg:pic]]')
end end