From 63cf09059b0b0712212b8112c3a5076eff812572 Mon Sep 17 00:00:00 2001 From: Alexey Verkhovsky Date: Fri, 28 Jan 2005 03:44:36 +0000 Subject: [PATCH] Merged new_web action into create_web --- app/controllers/admin_controller.rb | 25 +++++++++++-------- .../admin/{new_web.rhtml => create_web.rhtml} | 0 app/views/admin/edit_web.rhtml | 2 +- libraries/url_rewriting_hack.rb | 1 - test/functional/admin_controller_test.rb | 25 +++++++++---------- 5 files changed, 27 insertions(+), 26 deletions(-) rename app/views/admin/{new_web.rhtml => create_web.rhtml} (100%) diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 57736c3b..58b40177 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -5,7 +5,7 @@ class AdminController < ApplicationController layout 'default' def create_system - if wiki.setup? + 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.

@@ -27,11 +27,19 @@ class AdminController < ApplicationController end def create_web - if @wiki.authenticate(@params['system_password']) - @wiki.create_web(@params['name'], @params['address']) - redirect_show('HomePage', @params['address']) - else - redirect_to :action => 'index' + if @params['address'] + # form submitted + if @wiki.authenticate(@params['system_password']) + @wiki.create_web(@params['name'], @params['address']) + redirect_show('HomePage', @params['address']) + else + redirect_to :action => 'index' + end + else + # no form submitted -> render template + if @wiki.system[:password].nil? + redirect_to :controller => 'wiki', :action => 'index' + end end end @@ -39,11 +47,6 @@ class AdminController < ApplicationController # to template end - def new_web - redirect_to :action => 'index' if wiki.system['password'].nil? - # otherwise, to template - end - def update_web if wiki.authenticate(@params['system_password']) wiki.update_web( diff --git a/app/views/admin/new_web.rhtml b/app/views/admin/create_web.rhtml similarity index 100% rename from app/views/admin/new_web.rhtml rename to app/views/admin/create_web.rhtml diff --git a/app/views/admin/edit_web.rhtml b/app/views/admin/edit_web.rhtml index 57cc6f4b..887bf5e9 100644 --- a/app/views/admin/edit_web.rhtml +++ b/app/views/admin/edit_web.rhtml @@ -93,7 +93,7 @@ and

- ...or forget changes and create a new web + ...or forget changes and create a new web

diff --git a/libraries/url_rewriting_hack.rb b/libraries/url_rewriting_hack.rb index b817d530..8f3ba688 100644 --- a/libraries/url_rewriting_hack.rb +++ b/libraries/url_rewriting_hack.rb @@ -67,7 +67,6 @@ class DispatchServlet 'edit_web' => 'admin', 'file' => 'file', 'import' => 'file', - '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 22d52211..97fb6152 100644 --- a/test/functional/admin_controller_test.rb +++ b/test/functional/admin_controller_test.rb @@ -92,6 +92,18 @@ class AdminControllerTest < Test::Unit::TestCase assert_nil @wiki.webs['wiki2'] end + def test_create_web_no_form_submitted + @wiki.system[:password] = 'pswd' + process 'create_web' + assert_success + end + + def test_create_web_no_form_submitted_and_no_password_set + @wiki.system[:password] = nil + process 'create_web' + assert_redirected_to :action => 'index' + end + def test_edit_web process 'edit_web', 'web' => 'wiki1' @@ -100,19 +112,6 @@ class AdminControllerTest < Test::Unit::TestCase end - def test_new_web - @wiki.system['password'] = 'pswd' - process 'new_web' - assert_success - end - - def test_new_web_no_password_set - @wiki.system['password'] = nil - process 'new_web' - assert_redirected_to :action => 'index' - end - - def test_update_web @wiki.system[:password] = 'pswd'