diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 75b2c31c..969de977 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -48,19 +48,25 @@ class AdminController < ApplicationController if system_password # form submitted if wiki.authenticate(system_password) - wiki.edit_web( - @web.address, @params['address'], @params['name'], - @params['markup'].intern, - @params['color'], @params['additional_style'], - @params['safe_mode'] ? true : false, - @params['password'].empty? ? nil : @params['password'], - @params['published'] ? true : false, - @params['brackets_only'] ? true : false, - @params['count_pages'] ? true : false, - @params['allow_uploads'] ? true : false, - @params['max_upload_size'] - ) - redirect_show('HomePage', @params['address']) + begin + wiki.edit_web( + @web.address, @params['address'], @params['name'], + @params['markup'].intern, + @params['color'], @params['additional_style'], + @params['safe_mode'] ? true : false, + @params['password'].empty? ? nil : @params['password'], + @params['published'] ? true : false, + @params['brackets_only'] ? true : false, + @params['count_pages'] ? true : false, + @params['allow_uploads'] ? true : false, + @params['max_upload_size'] + ) + flash[:info] = "Web '#{@params['address']}' was successfully updated" + redirect_show('HomePage', @params['address']) + rescue Instiki::ValidationError => e + flash[:error] = e.message + # and re-render the same template again + end else flash[:error] = password_error(system_password) # and re-render the same template again diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb index a829ca5b..3ca5ef85 100644 --- a/test/functional/admin_controller_test.rb +++ b/test/functional/admin_controller_test.rb @@ -164,6 +164,20 @@ class AdminControllerTest < Test::Unit::TestCase assert_flash_has :error end + def test_edit_web_rename_to_already_existing_web_name + @wiki.system[:password] = 'pswd' + + @wiki.create_web('Another', 'another') + process('edit_web', 'system_password' => 'pswd', + 'web' => 'wiki1', 'address' => 'another', 'name' => 'Renamed Wiki1', + 'markup' => 'markdown', 'color' => 'blue', 'additional_style' => 'whatever', + 'password' => 'new_password') + + #returns to the same form + assert_success + assert_flash_has :error + end + def test_edit_web_empty_password process('edit_web', 'system_password' => '', 'web' => 'wiki1', 'address' => 'renamed_wiki1', 'name' => 'Renamed Wiki1',