Added validations to edit_web (it could overwrite parameters of an existing Wiki before)
This commit is contained in:
parent
b888799798
commit
4e6d2cbdf6
|
@ -8,6 +8,7 @@ require 'web'
|
||||||
require 'page'
|
require 'page'
|
||||||
require 'author'
|
require 'author'
|
||||||
require 'file_yard'
|
require 'file_yard'
|
||||||
|
require 'instiki_errors'
|
||||||
|
|
||||||
module AbstractWikiService
|
module AbstractWikiService
|
||||||
|
|
||||||
|
@ -77,7 +78,15 @@ module AbstractWikiService
|
||||||
def edit_web(old_address, new_address, name, markup, color, additional_style, safe_mode = false,
|
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,
|
password = nil, published = false, brackets_only = false, count_pages = false,
|
||||||
allow_uploads = true, max_upload_size = nil)
|
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 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[new_address] = @webs[old_address]
|
||||||
@webs.delete(old_address)
|
@webs.delete(old_address)
|
||||||
@webs[new_address].address = new_address
|
@webs[new_address].address = new_address
|
||||||
|
|
|
@ -131,7 +131,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
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 ' Set environment variable INSTIKI_TEST_PDFLATEX or global Ruby variable'
|
||||||
puts ' $INSTIKI_TEST_PDFLATEX to enable them.'
|
puts ' $INSTIKI_TEST_PDFLATEX to enable them.'
|
||||||
end
|
end
|
||||||
|
|
|
@ -69,6 +69,19 @@ class WikiServiceTest < Test::Unit::TestCase
|
||||||
assert_equal(@s.storage_path + '/instiki', file_yard.files_path)
|
assert_equal(@s.storage_path + '/instiki', file_yard.files_path)
|
||||||
end
|
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
|
# Checks that a method call or a block doesn;t change the persisted state of the wiki
|
||||||
# Usage:
|
# Usage:
|
||||||
|
|
Loading…
Reference in a new issue