diff --git a/app/models/wiki_service.rb b/app/models/wiki_service.rb index c68fd0ff..bec013e7 100644 --- a/app/models/wiki_service.rb +++ b/app/models/wiki_service.rb @@ -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 diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 84c7532a..810dbe2b 100755 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -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 diff --git a/test/unit/wiki_service_test.rb b/test/unit/wiki_service_test.rb index d5f16246..c02c61ff 100755 --- a/test/unit/wiki_service_test.rb +++ b/test/unit/wiki_service_test.rb @@ -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: