[BREAK BUILD] Upgrade URL rewriting to Routes (there is one test case in routes_test.rb that fails, and it depends on some refactoring that I agreed upon with Ulysses)

This commit is contained in:
Alexey Verkhovsky 2005-02-15 22:41:58 +00:00
parent 9c04ed3461
commit 5e25a94e51
10 changed files with 93 additions and 234 deletions

View file

@ -26,32 +26,32 @@ class AdminControllerTest < Test::Unit::TestCase
def test_create_system_form_submitted
ApplicationController.wiki = WikiServiceWithNoPersistence.new
assert !@controller.wiki.setup?
assert !ApplicationController.wiki.setup?
process('create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
'web_address' => 'my_wiki')
assert_redirected_to :web => 'my_wiki', :controller => 'wiki', :action => 'new',
:id => 'HomePage'
assert @controller.wiki.setup?
assert_equal 'a_password', @controller.wiki.system[:password]
assert_equal 1, @controller.wiki.webs.size
new_web = @controller.wiki.webs['my_wiki']
assert ApplicationController.wiki.setup?
assert_equal 'a_password', ApplicationController.wiki.system[:password]
assert_equal 1, ApplicationController.wiki.webs.size
new_web = ApplicationController.wiki.webs['my_wiki']
assert_equal 'My Wiki', new_web.name
assert_equal 'my_wiki', new_web.address
end
def test_create_system_form_submitted_and_wiki_already_initialized
wiki_before = @controller.wiki
assert @controller.wiki.setup?
wiki_before = ApplicationController.wiki
assert ApplicationController.wiki.setup?
process 'create_system', 'password' => 'a_password', 'web_name' => 'My Wiki',
'web_address' => 'my_wiki'
assert_redirected_to :web => 'wiki1', :action => 'show', :id => 'HomePage'
assert_equal wiki_before, @controller.wiki
assert_equal wiki_before, ApplicationController.wiki
# and no new web should be created either
assert_equal 1, @controller.wiki.webs.size
assert_equal 1, ApplicationController.wiki.webs.size
assert_flash_has :error
end
@ -200,19 +200,19 @@ class AdminControllerTest < Test::Unit::TestCase
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
assert_redirected_to :action => 'list'
assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list'
assert_equal [@home, @oak], @web.select.sort,
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
# Oak is now orphan, second pass should remove it
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password' => 'pswd')
assert_redirected_to :action => 'list'
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
assert_redirected_to :controller => 'wiki', :web => 'wiki1', :action => 'list'
assert_equal [@home], @web.select.sort,
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"
# third pass does not destroy HomePage
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password' => 'pswd')
r = process('remove_orphaned_pages', 'web' => 'wiki1', 'system_password_orphaned' => 'pswd')
assert_redirected_to :action => 'list'
assert_equal [@home], @web.select.sort,
"Pages are not as expected: #{@web.select.sort.map {|p| p.name}.inspect}"

View file

@ -0,0 +1,53 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'action_controller/routing'
class RoutesTest < Test::Unit::TestCase
def test_parse_uri
assert_routing('', :controller => 'wiki', :action => 'index')
assert_routing('x', :controller => 'wiki', :action => 'index', :web => 'x')
assert_routing('x/y', :controller => 'wiki', :web => 'x', :action => 'y')
assert_routing('x/y/z', :controller => 'wiki', :web => 'x', :action => 'y', :id => 'z')
assert_recognizes({:web => 'x', :controller => 'wiki', :action => 'y'}, 'x/y/')
assert_recognizes({:web => 'x', :controller => 'wiki', :action => 'y', :id => 'z'}, 'x/y/z/')
end
def test_parse_uri_interestng_cases
assert_routing('_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery-long_web_/an_action/HomePage',
:web => '_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery-long_web_',
:controller => 'wiki',
:action => 'an_action', :id => 'HomePage'
)
assert_recognizes({:controller => 'wiki', :action => 'index'}, '///')
end
def test_parse_uri_liberal_with_pagenames
assert_routing('web/show/$HOME_PAGE',
:controller => 'wiki', :web => 'web', :action => 'show', :id => '$HOME_PAGE')
assert_routing('web/show/HomePage?arg1=value1&arg2=value2',
:controller => 'wiki', :web => 'web', :action => 'show',
:id => 'HomePage?arg1=value1&arg2=value2')
assert_routing('web/file/abc.zip',
:web => 'web', :controller => 'file', :action => 'file', :id => 'abc.zip')
assert_routing('web/pic/abc.jpg',
:web => 'web', :controller => 'file', :action => 'pic', :id => 'abc.jpg')
assert_routing('web/import', :web => 'web', :controller => 'file', :action => 'import')
# default option is wiki
assert_recognizes({:controller => 'wiki', :web => 'unknown_path', :action => 'index', },
'unknown_path')
end
def test_cases_broken_by_routes
assert_routing('web/show/HomePage/something_else',
:controller => 'wiki', :web => 'web', :action => 'show', :id => 'HomePage/something_else')
assert_routing('web/show/Page+With+Spaces',
:controller => 'wiki', :web => 'web', :action => 'show', :id => 'Page+With+Spaces')
end
end

View file

@ -14,9 +14,9 @@ class Test::Unit::TestCase
def setup_controller_test(controller_class = nil, host = nil)
if controller_class
@controller = controller_class
@controller = controller_class.new
elsif self.class.to_s =~ /^(\w+Controller)Test$/
@controller = Object::const_get($1)
@controller = Object::const_get($1).new
else
raise "Cannot derive the name of controller under test from class name #{self.class}"
end

View file

@ -1,94 +0,0 @@
#!/bin/env ruby -w
require File.dirname(__FILE__) + '/../test_helper'
require 'url_rewriting_hack'
class UrlRewritingHackTest < Test::Unit::TestCase
def test_parse_uri
assert_equal({:controller => 'wiki', :action => 'x', :web => nil},
DispatchServlet.parse_uri('/x/'))
assert_equal({:web => 'x', :controller => 'wiki', :action => 'y'},
DispatchServlet.parse_uri('/x/y'))
assert_equal({:web => 'x', :controller => 'wiki', :action => 'y'},
DispatchServlet.parse_uri('/x/y/'))
assert_equal({:web => 'x', :controller => 'wiki', :action => 'y', :id => 'z'},
DispatchServlet.parse_uri('/x/y/z'))
assert_equal({:web => 'x', :controller => 'wiki', :action => 'y', :id => 'z'},
DispatchServlet.parse_uri('/x/y/z/'))
end
def test_parse_uri_approot
assert_equal({:controller => 'wiki', :action => 'index', :web => nil},
DispatchServlet.parse_uri('/wiki/'))
end
def test_parse_uri_interestng_cases
assert_equal({:web => '_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery-long_web_',
:controller => 'wiki',
:action => 'an_action', :id => 'HomePage'
},
DispatchServlet.parse_uri(
'/_veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery-long_web_/an_action/HomePage')
)
assert_equal false, DispatchServlet.parse_uri('')
assert_equal false, DispatchServlet.parse_uri('//')
assert_equal false, DispatchServlet.parse_uri('web')
end
def test_parse_uri_liberal_with_pagenames
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show', :id => '$HOME_PAGE'},
DispatchServlet.parse_uri('/web/show/$HOME_PAGE'))
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show',
:id => 'HomePage/something_else'},
DispatchServlet.parse_uri('/web/show/HomePage/something_else'))
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show',
:id => 'HomePage?arg1=value1&arg2=value2'},
DispatchServlet.parse_uri('/web/show/HomePage?arg1=value1&arg2=value2'))
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show',
:id => 'Page+With+Spaces'},
DispatchServlet.parse_uri('/web/show/Page+With+Spaces'))
end
def test_url_rewriting
request = ActionController::TestRequest.new
ur = ActionController::UrlRewriter.new(request, 'wiki', 'show')
assert_equal 'http://test.host/myweb/myaction',
ur.rewrite(:web => 'myweb', :controller => 'wiki', :action => 'myaction')
assert_equal 'http://test.host/myOtherWeb/',
ur.rewrite(:web => 'myOtherWeb', :controller => 'wiki')
assert_equal 'http://test.host/myaction',
ur.rewrite(:controller => 'wiki', :action => 'myaction')
assert_equal 'http://test.host/',
ur.rewrite(:controller => 'wiki')
end
def test_controller_mapping
request = ActionController::TestRequest.new
ur = ActionController::UrlRewriter.new(request, 'wiki', 'show')
assert_equal 'http://test.host/file',
ur.rewrite(:controller => 'file', :action => 'file')
assert_equal 'http://test.host/pic/abc.jpg',
ur.rewrite(:controller => 'file', :action => 'pic', :id => 'abc.jpg')
assert_equal 'http://test.host/web/pic/abc.jpg',
ur.rewrite(:web => 'web', :controller => 'file', :action => 'pic', :id => 'abc.jpg')
assert_equal 'http://test.host/web/import',
ur.rewrite(:web => 'web', :controller => 'file', :action => 'import')
# default option is wiki
assert_equal 'http://test.host/unknown_action',
ur.rewrite(:controller => 'wiki', :action => 'unknown_action')
end
end