Added validations to edit_web (it could overwrite parameters of an existing Wiki before)

This commit is contained in:
Alexey Verkhovsky 2005-02-10 21:03:50 +00:00
parent b888799798
commit 4e6d2cbdf6
3 changed files with 23 additions and 1 deletions

View file

@ -8,6 +8,7 @@ require 'web'
require 'page'
require 'author'
require 'file_yard'
require 'instiki_errors'
module AbstractWikiService
@ -77,7 +78,15 @@ module AbstractWikiService
def edit_web(old_address, new_address, name, markup, color, additional_style, safe_mode = false,
password = nil, published = false, brackets_only = false, count_pages = false,
allow_uploads = true, max_upload_size = nil)
if not @webs.key? old_address
raise Instiki::ValidationError.new("Web with address '#{old_address}' does not exist")
end
if old_address != new_address
if @webs.key? new_address
raise Instiki::ValidationError.new("There is already a web with address '#{new_address}'")
end
@webs[new_address] = @webs[old_address]
@webs.delete(old_address)
@webs[new_address].address = new_address

View file

@ -131,7 +131,7 @@ class WikiControllerTest < Test::Unit::TestCase
end
else
puts 'Warning: tests involving pdflatex are very slow, therefore they are disable by default.'
puts 'Warning: tests involving pdflatex are very slow, therefore they are disabled by default.'
puts ' Set environment variable INSTIKI_TEST_PDFLATEX or global Ruby variable'
puts ' $INSTIKI_TEST_PDFLATEX to enable them.'
end

View file

@ -69,6 +69,19 @@ class WikiServiceTest < Test::Unit::TestCase
assert_equal(@s.storage_path + '/instiki', file_yard.files_path)
end
def test_edit_web_validations
another_web = @s.create_web 'Another', 'another'
# try to rename instiki web to another (which is the name of an already existing one)
assert_raises(Instiki::ValidationError) {
@s.edit_web('instiki', 'another', @web.name, @web.markup, @web.color, @web.additional_style)
}
assert_raises(Instiki::ValidationError) {
@s.edit_web('nonexistant', 'another', @web.name, @web.markup, @web.color, @web.additional_style)
}
end
# Checks that a method call or a block doesn;t change the persisted state of the wiki
# Usage: