diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 58cfc7a5..e273d9ff 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -5,8 +5,20 @@ class AdminController < ApplicationController layout 'default' def create_system - @wiki.setup(@params['password'], @params['web_name'], @params['web_address']) unless @wiki.setup? - redirect_show('HomePage', @params['web_address']) + if wiki.setup? + flash[:error] = <<-EOL + Wiki has already been created in '#{@wiki.storage_path}'. Shut down Instiki and delete + this directory if you want to recreate it from scratch.
+ (WARNING: this will destroy content of your current wiki). + EOL + redirect_show('HomePage', @wiki.webs.keys.first) + elsif @params['web_name'] + # form submitted -> create a wiki + @wiki.setup(@params['password'], @params['web_name'], @params['web_address']) + redirect_show('HomePage', @params['web_address']) + else + # no form submitted -> go to template + end end def create_web @@ -22,11 +34,6 @@ class AdminController < ApplicationController # to template end - def new_system - redirect_to(:action => 'index') if wiki.setup? - # otherwise, to template - end - def new_web redirect_to :action => 'index' if wiki.system['password'].nil? # otherwise, to template diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index b03829d7..94b1bf1c 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -10,7 +10,7 @@ class WikiController < ApplicationController if @web_name redirect_show 'HomePage' elsif not @wiki.setup? - redirect_to :action => 'new_system' + redirect_to :controller => 'admin', :action => 'create_system' elsif @wiki.webs.length == 1 redirect_show 'HomePage', @wiki.webs.values.first.address else diff --git a/app/views/admin/new_system.rhtml b/app/views/admin/create_system.rhtml similarity index 100% rename from app/views/admin/new_system.rhtml rename to app/views/admin/create_system.rhtml diff --git a/libraries/url_rewriting_hack.rb b/libraries/url_rewriting_hack.rb index 35bab3a7..b817d530 100644 --- a/libraries/url_rewriting_hack.rb +++ b/libraries/url_rewriting_hack.rb @@ -8,7 +8,7 @@ # # 1. Controller is determined by action name (default is 'wiki') # 2. '/name1/' maps to action 'name1', unspecified web -# Example: http://localhost/new_system/ +# Example: http://localhost/create_system/ # 3. Special case of above, URI '/wiki/' maps to action 'index', because Rails sets this address # when default controller name is specified as 'wiki', and an application root # (http://localhost:2500/)is requested. @@ -67,7 +67,6 @@ class DispatchServlet 'edit_web' => 'admin', 'file' => 'file', 'import' => 'file', - 'new_system' => 'admin', 'new_web' => 'admin', 'pic' => 'file', 'update_web' => 'admin' diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb index dde7d10d..ae424716 100644 --- a/test/functional/admin_controller_test.rb +++ b/test/functional/admin_controller_test.rb @@ -18,7 +18,13 @@ class AdminControllerTest < Test::Unit::TestCase end - def test_create_system + def test_create_system_form_displayed + ApplicationController.wiki = WikiServiceWithNoPersistence.new + process('create_system') + assert_success + end + + def test_create_system_form_submitted ApplicationController.wiki = WikiServiceWithNoPersistence.new assert !@controller.wiki.setup? @@ -34,17 +40,25 @@ class AdminControllerTest < Test::Unit::TestCase assert_equal 'my_wiki', new_web.address end - def test_create_system_already_setup + def test_create_system_form_submitted_and_wiki_already_initialized wiki_before = @controller.wiki assert @controller.wiki.setup? process 'create_system', 'password' => 'a_password', 'web_name' => 'My Wiki', 'web_address' => 'my_wiki' - assert_redirected_to :web => 'my_wiki', :action => 'show', :id => 'HomePage' + assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage' assert_equal wiki_before, @controller.wiki - # and no new wikis shuld be created either + # and no new web should be created either assert_equal 1, @controller.wiki.webs.size + assert_flash_has :error + end + + def test_create_system_no_form_and_wiki_already_initialized + assert @wiki.setup? + process('create_system') + assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage' + assert_flash_has :error end @@ -85,19 +99,6 @@ class AdminControllerTest < Test::Unit::TestCase end - def test_new_system - ApplicationController.wiki = WikiServiceWithNoPersistence.new - process('new_system') - assert_success - end - - def test_new_system_system_already_initialized - assert @wiki.setup? - process('new_system') - assert_redirected_to :action => 'index' - end - - def test_new_web @wiki.system['password'] = 'pswd' process 'new_web' diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index ba4e1925..860f69a2 100755 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -172,7 +172,7 @@ class WikiControllerTest < Test::Unit::TestCase def test_index_wiki_not_initialized ApplicationController.wiki = WikiServiceWithNoPersistence.new process('index') - assert_redirected_to :action => 'new_system' + assert_redirected_to :controller => 'admin', :action => 'create_system' end