Merged new_system action into create_system

This commit is contained in:
Alexey Verkhovsky 2005-01-28 02:35:59 +00:00
parent 88e52ab5a9
commit 83c6eadc0c
6 changed files with 35 additions and 28 deletions

View file

@ -5,8 +5,20 @@ class AdminController < ApplicationController
layout 'default' layout 'default'
def create_system def create_system
@wiki.setup(@params['password'], @params['web_name'], @params['web_address']) unless @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.<br/>
(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']) redirect_show('HomePage', @params['web_address'])
else
# no form submitted -> go to template
end
end end
def create_web def create_web
@ -22,11 +34,6 @@ class AdminController < ApplicationController
# to template # to template
end end
def new_system
redirect_to(:action => 'index') if wiki.setup?
# otherwise, to template
end
def new_web def new_web
redirect_to :action => 'index' if wiki.system['password'].nil? redirect_to :action => 'index' if wiki.system['password'].nil?
# otherwise, to template # otherwise, to template

View file

@ -10,7 +10,7 @@ class WikiController < ApplicationController
if @web_name if @web_name
redirect_show 'HomePage' redirect_show 'HomePage'
elsif not @wiki.setup? elsif not @wiki.setup?
redirect_to :action => 'new_system' redirect_to :controller => 'admin', :action => 'create_system'
elsif @wiki.webs.length == 1 elsif @wiki.webs.length == 1
redirect_show 'HomePage', @wiki.webs.values.first.address redirect_show 'HomePage', @wiki.webs.values.first.address
else else

View file

@ -8,7 +8,7 @@
# #
# 1. Controller is determined by action name (default is 'wiki') # 1. Controller is determined by action name (default is 'wiki')
# 2. '/name1/' maps to action 'name1', unspecified web # 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 # 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 # when default controller name is specified as 'wiki', and an application root
# (http://localhost:2500/)is requested. # (http://localhost:2500/)is requested.
@ -67,7 +67,6 @@ class DispatchServlet
'edit_web' => 'admin', 'edit_web' => 'admin',
'file' => 'file', 'file' => 'file',
'import' => 'file', 'import' => 'file',
'new_system' => 'admin',
'new_web' => 'admin', 'new_web' => 'admin',
'pic' => 'file', 'pic' => 'file',
'update_web' => 'admin' 'update_web' => 'admin'

View file

@ -18,7 +18,13 @@ class AdminControllerTest < Test::Unit::TestCase
end 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 ApplicationController.wiki = WikiServiceWithNoPersistence.new
assert !@controller.wiki.setup? assert !@controller.wiki.setup?
@ -34,17 +40,25 @@ class AdminControllerTest < Test::Unit::TestCase
assert_equal 'my_wiki', new_web.address assert_equal 'my_wiki', new_web.address
end end
def test_create_system_already_setup def test_create_system_form_submitted_and_wiki_already_initialized
wiki_before = @controller.wiki wiki_before = @controller.wiki
assert @controller.wiki.setup? assert @controller.wiki.setup?
process 'create_system', 'password' => 'a_password', 'web_name' => 'My Wiki', process 'create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
'web_address' => '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 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_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 end
@ -85,19 +99,6 @@ class AdminControllerTest < Test::Unit::TestCase
end 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 def test_new_web
@wiki.system['password'] = 'pswd' @wiki.system['password'] = 'pswd'
process 'new_web' process 'new_web'

View file

@ -172,7 +172,7 @@ class WikiControllerTest < Test::Unit::TestCase
def test_index_wiki_not_initialized def test_index_wiki_not_initialized
ApplicationController.wiki = WikiServiceWithNoPersistence.new ApplicationController.wiki = WikiServiceWithNoPersistence.new
process('index') process('index')
assert_redirected_to :action => 'new_system' assert_redirected_to :controller => 'admin', :action => 'create_system'
end end