1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix Routing tests. Fix routing where failing to match a controller would prevent the rest of routes from being attempted.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3539 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Nicholas Seckar 2006-02-04 23:09:26 +00:00
parent 28cee08fa4
commit b381d8511d
4 changed files with 77 additions and 86 deletions

View file

@ -1,5 +1,7 @@
*SVN* *SVN*
* Fix Routing tests. Fix routing where failing to match a controller would prevent the rest of routes from being attempted. [Nicholas Seckar]
* Add :builder => option to form_for and friends. [Nicholas Seckar, Rick Olson] * Add :builder => option to form_for and friends. [Nicholas Seckar, Rick Olson]
* Fix controller resolution to avoid accidentally inheriting a controller from a parent module. [Nicholas Seckar] * Fix controller resolution to avoid accidentally inheriting a controller from a parent module. [Nicholas Seckar]

View file

@ -224,7 +224,7 @@ module ActionController
length = segments.length length = segments.length
index = start_at index = start_at
mod_name = controller_name = segment = nil mod_name = controller_name = segment = nil
while index < length while index < length
return nil unless /^[A-Za-z][A-Za-z\d_]*$/ =~ (segment = segments[index]) return nil unless /^[A-Za-z][A-Za-z\d_]*$/ =~ (segment = segments[index])
index += 1 index += 1
@ -247,7 +247,7 @@ module ActionController
(mod == Object || next_mod.name == "#{mod.name}::#{mod_name}") ? next_mod : nil (mod == Object || next_mod.name == "#{mod.name}::#{mod_name}") ? next_mod : nil
end end
raise RoutingError, "Cannot find controller: Dropped out at #{segments[start_at..index] * '/'}" unless mod return nil unless mod
end end
end end
end end
@ -456,7 +456,6 @@ module ActionController
@generation_methods[controller.to_sym] = method_name @generation_methods[controller.to_sym] = method_name
end end
code = generation_code_for('routes', 'generate_default_path').to_s code = generation_code_for('routes', 'generate_default_path').to_s
eval(code, nil, 'generated_code/routing/generation.rb') eval(code, nil, 'generated_code/routing/generation.rb')
@ -493,7 +492,7 @@ module ActionController
route.write_recognition(g) route.write_recognition(g)
end end
end end
eval g.to_s, nil, 'generated/routing/recognition.rb' eval g.to_s, nil, 'generated/routing/recognition.rb'
return g.to_s return g.to_s
end end

View file

@ -1,21 +1,11 @@
module Object::Controllers class << Object; alias_method :const_available?, :const_defined?; end
def self.const_available?(*args)
const_defined?(*args)
end
class ContentController < ActionController::Base class ContentController < Class.new(ActionController::Base)
end end
module Admin
module Admin class << self; alias_method :const_available?, :const_defined?; end
def self.const_available?(*args) class UserController < Class.new(ActionController::Base); end
const_defined?(*args) class NewsFeedController < Class.new(ActionController::Base); end
end
class UserController < ActionController::Base
end
class NewsFeedController < ActionController::Base
end
end
end end
ActionController::Routing::Routes.draw do |map| ActionController::Routing::Routes.draw do |map|

View file

@ -1,5 +1,4 @@
require File.dirname(__FILE__) + '/../abstract_unit' require File.dirname(__FILE__) + '/../abstract_unit'
require File.dirname(__FILE__) + '/fake_controllers'
require 'test/unit' require 'test/unit'
require 'stringio' require 'stringio'
@ -12,7 +11,7 @@ class SourceTests < Test::Unit::TestCase
def setup def setup
@source = Source.new @source = Source.new
end end
def test_initial_state def test_initial_state
assert_equal [], source.lines assert_equal [], source.lines
assert_equal 0, source.indentation_level assert_equal 0, source.indentation_level
@ -54,7 +53,7 @@ class CodeGeneratorTests < Test::Unit::TestCase
def setup def setup
@generator = CodeGenerator.new @generator = CodeGenerator.new
end end
def test_initial_state def test_initial_state
assert_equal [], generator.source.lines assert_equal [], generator.source.lines
assert_equal [], generator.locals assert_equal [], generator.locals
@ -124,7 +123,7 @@ class RecognitionTests < Test::Unit::TestCase
def test_all_static def test_all_static
c = %w(hello world how are you).collect {|str| Static.new(str)} c = %w(hello world how are you).collect {|str| Static.new(str)}
g.result :controller, "::Controllers::ContentController", true g.result :controller, "::ContentController", true
g.constant_result :action, 'index' g.constant_result :action, 'index'
go c go c
@ -133,19 +132,19 @@ class RecognitionTests < Test::Unit::TestCase
assert_nil execute('hello/world/how') assert_nil execute('hello/world/how')
assert_nil execute('hello/world/how/are') assert_nil execute('hello/world/how/are')
assert_nil execute('hello/world/how/are/you/today') assert_nil execute('hello/world/how/are/you/today')
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hello/world/how/are/you')) assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hello/world/how/are/you'))
end end
def test_basic_dynamic def test_basic_dynamic
c = [Static.new("hi"), Dynamic.new(:action)] c = [Static.new("hi"), Dynamic.new(:action)]
g.result :controller, "::Controllers::ContentController", true g.result :controller, "::ContentController", true
go c go c
assert_nil execute('boo') assert_nil execute('boo')
assert_nil execute('boo/blah') assert_nil execute('boo/blah')
assert_nil execute('hi') assert_nil execute('hi')
assert_nil execute('hi/dude/what') assert_nil execute('hi/dude/what')
assert_equal({:controller => ::Controllers::ContentController, :action => 'dude'}, execute('hi/dude')) assert_equal({:controller => ::ContentController, :action => 'dude'}, execute('hi/dude'))
end end
def test_basic_dynamic_backwards def test_basic_dynamic_backwards
@ -163,33 +162,33 @@ class RecognitionTests < Test::Unit::TestCase
def test_dynamic_with_default def test_dynamic_with_default
c = [Static.new("hi"), Dynamic.new(:action, :default => 'index')] c = [Static.new("hi"), Dynamic.new(:action, :default => 'index')]
g.result :controller, "::Controllers::ContentController", true g.result :controller, "::ContentController", true
go c go c
assert_nil execute('boo') assert_nil execute('boo')
assert_nil execute('boo/blah') assert_nil execute('boo/blah')
assert_nil execute('hi/dude/what') assert_nil execute('hi/dude/what')
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi')) assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hi'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi/index')) assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hi/index'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'dude'}, execute('hi/dude')) assert_equal({:controller => ::ContentController, :action => 'dude'}, execute('hi/dude'))
end end
def test_dynamic_with_string_condition def test_dynamic_with_string_condition
c = [Static.new("hi"), Dynamic.new(:action, :condition => 'index')] c = [Static.new("hi"), Dynamic.new(:action, :condition => 'index')]
g.result :controller, "::Controllers::ContentController", true g.result :controller, "::ContentController", true
go c go c
assert_nil execute('boo') assert_nil execute('boo')
assert_nil execute('boo/blah') assert_nil execute('boo/blah')
assert_nil execute('hi') assert_nil execute('hi')
assert_nil execute('hi/dude/what') assert_nil execute('hi/dude/what')
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi/index')) assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hi/index'))
assert_nil execute('hi/dude') assert_nil execute('hi/dude')
end end
def test_dynamic_with_string_condition_backwards def test_dynamic_with_string_condition_backwards
c = [Dynamic.new(:action, :condition => 'index'), Static.new("hi")] c = [Dynamic.new(:action, :condition => 'index'), Static.new("hi")]
g.result :controller, "::Controllers::ContentController", true g.result :controller, "::ContentController", true
go c go c
assert_nil execute('boo') assert_nil execute('boo')
@ -197,13 +196,13 @@ class RecognitionTests < Test::Unit::TestCase
assert_nil execute('hi') assert_nil execute('hi')
assert_nil execute('dude/what/hi') assert_nil execute('dude/what/hi')
assert_nil execute('index/what') assert_nil execute('index/what')
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('index/hi')) assert_equal({:controller => ::ContentController, :action => 'index'}, execute('index/hi'))
assert_nil execute('dude/hi') assert_nil execute('dude/hi')
end end
def test_dynamic_with_regexp_condition def test_dynamic_with_regexp_condition
c = [Static.new("hi"), Dynamic.new(:action, :condition => /^[a-z]+$/)] c = [Static.new("hi"), Dynamic.new(:action, :condition => /^[a-z]+$/)]
g.result :controller, "::Controllers::ContentController", true g.result :controller, "::ContentController", true
go c go c
assert_nil execute('boo') assert_nil execute('boo')
@ -213,13 +212,13 @@ class RecognitionTests < Test::Unit::TestCase
assert_nil execute('hi/138708jkhdf') assert_nil execute('hi/138708jkhdf')
assert_nil execute('hi/dkjfl8792343dfsf') assert_nil execute('hi/dkjfl8792343dfsf')
assert_nil execute('hi/dude/what') assert_nil execute('hi/dude/what')
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi/index')) assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hi/index'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'dude'}, execute('hi/dude')) assert_equal({:controller => ::ContentController, :action => 'dude'}, execute('hi/dude'))
end end
def test_dynamic_with_regexp_and_default def test_dynamic_with_regexp_and_default
c = [Static.new("hi"), Dynamic.new(:action, :condition => /^[a-z]+$/, :default => 'index')] c = [Static.new("hi"), Dynamic.new(:action, :condition => /^[a-z]+$/, :default => 'index')]
g.result :controller, "::Controllers::ContentController", true g.result :controller, "::ContentController", true
go c go c
assert_nil execute('boo') assert_nil execute('boo')
@ -227,39 +226,39 @@ class RecognitionTests < Test::Unit::TestCase
assert_nil execute('hi/FOXY') assert_nil execute('hi/FOXY')
assert_nil execute('hi/138708jkhdf') assert_nil execute('hi/138708jkhdf')
assert_nil execute('hi/dkjfl8792343dfsf') assert_nil execute('hi/dkjfl8792343dfsf')
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi')) assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hi'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi/index')) assert_equal({:controller => ::ContentController, :action => 'index'}, execute('hi/index'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'dude'}, execute('hi/dude')) assert_equal({:controller => ::ContentController, :action => 'dude'}, execute('hi/dude'))
assert_nil execute('hi/dude/what') assert_nil execute('hi/dude/what')
end end
def test_path def test_path
c = [Static.new("hi"), Path.new(:file)] c = [Static.new("hi"), Path.new(:file)]
g.result :controller, "::Controllers::ContentController", true g.result :controller, "::ContentController", true
g.constant_result :action, "download" g.constant_result :action, "download"
go c go c
assert_nil execute('boo') assert_nil execute('boo')
assert_nil execute('boo/blah') assert_nil execute('boo/blah')
assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => []}, execute('hi')) assert_equal({:controller => ::ContentController, :action => 'download', :file => []}, execute('hi'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => %w(books agile_rails_dev.pdf)}, assert_equal({:controller => ::ContentController, :action => 'download', :file => %w(books agile_rails_dev.pdf)},
execute('hi/books/agile_rails_dev.pdf')) execute('hi/books/agile_rails_dev.pdf'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => ['dude']}, execute('hi/dude')) assert_equal({:controller => ::ContentController, :action => 'download', :file => ['dude']}, execute('hi/dude'))
assert_equal 'dude/what', execute('hi/dude/what')[:file].to_s assert_equal 'dude/what', execute('hi/dude/what')[:file].to_s
end end
def test_path_with_dynamic def test_path_with_dynamic
c = [Dynamic.new(:action), Path.new(:file)] c = [Dynamic.new(:action), Path.new(:file)]
g.result :controller, "::Controllers::ContentController", true g.result :controller, "::ContentController", true
go c go c
assert_nil execute('') assert_nil execute('')
assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => []}, execute('download')) assert_equal({:controller => ::ContentController, :action => 'download', :file => []}, execute('download'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => %w(books agile_rails_dev.pdf)}, assert_equal({:controller => ::ContentController, :action => 'download', :file => %w(books agile_rails_dev.pdf)},
execute('download/books/agile_rails_dev.pdf')) execute('download/books/agile_rails_dev.pdf'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => ['dude']}, execute('download/dude')) assert_equal({:controller => ::ContentController, :action => 'download', :file => ['dude']}, execute('download/dude'))
assert_equal 'dude/what', execute('hi/dude/what')[:file].to_s assert_equal 'dude/what', execute('hi/dude/what')[:file].to_s
end end
@ -287,8 +286,8 @@ class RecognitionTests < Test::Unit::TestCase
assert_nil execute('hi/13870948') assert_nil execute('hi/13870948')
assert_nil execute('hi/content/dog') assert_nil execute('hi/content/dog')
assert_nil execute('hi/admin/user/foo') assert_nil execute('hi/admin/user/foo')
assert_equal({:controller => ::Controllers::ContentController, :action => 'hi'}, execute('hi/content')) assert_equal({:controller => ::ContentController, :action => 'hi'}, execute('hi/content'))
assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'hi'}, execute('hi/admin/user')) assert_equal({:controller => ::Admin::UserController, :action => 'hi'}, execute('hi/admin/user'))
end end
def test_controller_with_regexp def test_controller_with_regexp
@ -300,8 +299,8 @@ class RecognitionTests < Test::Unit::TestCase
assert_nil execute('hi') assert_nil execute('hi')
assert_nil execute('hi/x') assert_nil execute('hi/x')
assert_nil execute('hi/content') assert_nil execute('hi/content')
assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'hi'}, execute('hi/admin/user')) assert_equal({:controller => ::Admin::UserController, :action => 'hi'}, execute('hi/admin/user'))
assert_equal({:controller => ::Controllers::Admin::NewsFeedController, :action => 'hi'}, execute('hi/admin/news_feed')) assert_equal({:controller => ::Admin::NewsFeedController, :action => 'hi'}, execute('hi/admin/news_feed'))
assert_nil execute('hi/admin/user/foo') assert_nil execute('hi/admin/user/foo')
end end
@ -310,13 +309,13 @@ class RecognitionTests < Test::Unit::TestCase
go c go c
# Make sure we get the right answers # Make sure we get the right answers
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('content')) assert_equal({:controller => ::ContentController, :action => 'index'}, execute('content'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'list'}, execute('content/list')) assert_equal({:controller => ::ContentController, :action => 'list'}, execute('content/list'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'show', :id => '10'}, execute('content/show/10')) assert_equal({:controller => ::ContentController, :action => 'show', :id => '10'}, execute('content/show/10'))
assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'index'}, execute('admin/user')) assert_equal({:controller => ::Admin::UserController, :action => 'index'}, execute('admin/user'))
assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'list'}, execute('admin/user/list')) assert_equal({:controller => ::Admin::UserController, :action => 'list'}, execute('admin/user/list'))
assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'show', :id => 'nseckar'}, execute('admin/user/show/nseckar')) assert_equal({:controller => ::Admin::UserController, :action => 'show', :id => 'nseckar'}, execute('admin/user/show/nseckar'))
assert_nil execute('content/show/10/20') assert_nil execute('content/show/10/20')
assert_nil execute('food') assert_nil execute('food')
@ -357,7 +356,7 @@ class RecognitionTests < Test::Unit::TestCase
end end
def test_default_route def test_default_route
g.result :controller, "::Controllers::ContentController", true g.result :controller, "::ContentController", true
g.constant_result :action, 'index' g.constant_result :action, 'index'
go [] go []
@ -366,7 +365,7 @@ class RecognitionTests < Test::Unit::TestCase
assert_nil execute('hello/world/how') assert_nil execute('hello/world/how')
assert_nil execute('hello/world/how/are') assert_nil execute('hello/world/how/are')
assert_nil execute('hello/world/how/are/you/today') assert_nil execute('hello/world/how/are/you/today')
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute([])) assert_equal({:controller => ::ContentController, :action => 'index'}, execute([]))
end end
end end
@ -534,6 +533,8 @@ not_expired = true
end end
class RouteTests < Test::Unit::TestCase class RouteTests < Test::Unit::TestCase
def route(*args) def route(*args)
@route = ::ActionController::Routing::Route.new(*args) unless args.empty? @route = ::ActionController::Routing::Route.new(*args) unless args.empty?
return @route return @route
@ -566,7 +567,7 @@ class RouteTests < Test::Unit::TestCase
assert_nil rec('hello/turn') assert_nil rec('hello/turn')
assert_nil rec('turn/world') assert_nil rec('turn/world')
assert_equal( assert_equal(
{:known => 'known_value', :controller => ::Controllers::ContentController, :action => 'index'}, {:known => 'known_value', :controller => ::ContentController, :action => 'index'},
rec('hello/world') rec('hello/world')
) )
@ -582,8 +583,8 @@ class RouteTests < Test::Unit::TestCase
assert_nil rec('hello') assert_nil rec('hello')
assert_nil rec('foo/bar') assert_nil rec('foo/bar')
assert_equal({:controller => ::Controllers::ContentController, :action => 'show_person', :name => 'rails'}, rec('hello/rails')) assert_equal({:controller => ::ContentController, :action => 'show_person', :name => 'rails'}, rec('hello/rails'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'show_person', :name => 'Nicholas Seckar'}, rec('hello/Nicholas+Seckar')) assert_equal({:controller => ::ContentController, :action => 'show_person', :name => 'Nicholas Seckar'}, rec('hello/Nicholas+Seckar'))
assert_nil gen(:controller => 'content', :action => 'show_dude', :name => 'rails') assert_nil gen(:controller => 'content', :action => 'show_dude', :name => 'rails')
assert_nil gen(:controller => 'content', :action => 'show_person') assert_nil gen(:controller => 'content', :action => 'show_person')
@ -596,15 +597,15 @@ class RouteTests < Test::Unit::TestCase
route ':controller/:action/:id', :action => 'index', :id => nil route ':controller/:action/:id', :action => 'index', :id => nil
assert_nil rec('hello') assert_nil rec('hello')
assert_nil rec('foo bar') assert_nil rec('foo bar')
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, rec('content')) assert_equal({:controller => ::ContentController, :action => 'index'}, rec('content'))
assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'index'}, rec('admin/user')) assert_equal({:controller => ::Admin::UserController, :action => 'index'}, rec('admin/user'))
assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'index'}, rec('admin/user/index')) assert_equal({:controller => ::Admin::UserController, :action => 'index'}, rec('admin/user/index'))
assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'list'}, rec('admin/user/list')) assert_equal({:controller => ::Admin::UserController, :action => 'list'}, rec('admin/user/list'))
assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'show', :id => '10'}, rec('admin/user/show/10')) assert_equal({:controller => ::Admin::UserController, :action => 'show', :id => '10'}, rec('admin/user/show/10'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'list'}, rec('content/list')) assert_equal({:controller => ::ContentController, :action => 'list'}, rec('content/list'))
assert_equal({:controller => ::Controllers::ContentController, :action => 'show', :id => '10'}, rec('content/show/10')) assert_equal({:controller => ::ContentController, :action => 'show', :id => '10'}, rec('content/show/10'))
assert_equal '/content', gen(:controller => 'content', :action => 'index') assert_equal '/content', gen(:controller => 'content', :action => 'index')
@ -627,11 +628,11 @@ class RouteSetTests < Test::Unit::TestCase
end end
def test_default_setup def test_default_setup
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}.stringify_keys, rs.recognize_path(%w(content))) assert_equal({:controller => ::ContentController, :action => 'index'}.stringify_keys, rs.recognize_path(%w(content)))
assert_equal({:controller => ::Controllers::ContentController, :action => 'list'}.stringify_keys, rs.recognize_path(%w(content list))) assert_equal({:controller => ::ContentController, :action => 'list'}.stringify_keys, rs.recognize_path(%w(content list)))
assert_equal({:controller => ::Controllers::ContentController, :action => 'show', :id => '10'}.stringify_keys, rs.recognize_path(%w(content show 10))) assert_equal({:controller => ::ContentController, :action => 'show', :id => '10'}.stringify_keys, rs.recognize_path(%w(content show 10)))
assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'show', :id => '10'}.stringify_keys, rs.recognize_path(%w(admin user show 10))) assert_equal({:controller => ::Admin::UserController, :action => 'show', :id => '10'}.stringify_keys, rs.recognize_path(%w(admin user show 10)))
assert_equal ['/admin/user/show/10', []], rs.generate({:controller => 'admin/user', :action => 'show', :id => 10}) assert_equal ['/admin/user/show/10', []], rs.generate({:controller => 'admin/user', :action => 'show', :id => 10})
@ -718,9 +719,9 @@ class RouteSetTests < Test::Unit::TestCase
map.connect ':controller/:admintoken/:action/:id', :controller => /admin\/.+/ map.connect ':controller/:admintoken/:action/:id', :controller => /admin\/.+/
map.connect ':controller/:action/:id' map.connect ':controller/:action/:id'
end end
assert_equal({:controller => ::Controllers::Admin::UserController, :admintoken => "foo", :action => "index"}.stringify_keys, assert_equal({:controller => ::Admin::UserController, :admintoken => "foo", :action => "index"}.stringify_keys,
rs.recognize_path(%w(admin user foo))) rs.recognize_path(%w(admin user foo)))
assert_equal({:controller => ::Controllers::ContentController, :action => "foo"}.stringify_keys, assert_equal({:controller => ::ContentController, :action => "foo"}.stringify_keys,
rs.recognize_path(%w(content foo))) rs.recognize_path(%w(content foo)))
assert_equal ['/admin/user/foo', []], rs.generate(:controller => "admin/user", :admintoken => "foo", :action => "index") assert_equal ['/admin/user/foo', []], rs.generate(:controller => "admin/user", :admintoken => "foo", :action => "index")
assert_equal ['/content/foo',[]], rs.generate(:controller => "content", :action => "foo") assert_equal ['/content/foo',[]], rs.generate(:controller => "content", :action => "foo")
@ -792,7 +793,6 @@ class RouteSetTests < Test::Unit::TestCase
rs.path 'file/*path', :controller => 'content', :action => 'show_file' rs.path 'file/*path', :controller => 'content', :action => 'show_file'
rs.connect ':controller/:action/:id' rs.connect ':controller/:action/:id'
end end
results = rs.recognize_path %w(file hello+world how+are+you%3F) results = rs.recognize_path %w(file hello+world how+are+you%3F)
assert results, "Recognition should have succeeded" assert results, "Recognition should have succeeded"
assert_equal ['hello world', 'how are you?'], results['path'] assert_equal ['hello world', 'how are you?'], results['path']
@ -838,7 +838,7 @@ class RouteSetTests < Test::Unit::TestCase
assert_equal ['/page', []], rs.generate(:controller => 'content', :action => 'show_page', :id => '1') assert_equal ['/page', []], rs.generate(:controller => 'content', :action => 'show_page', :id => '1')
assert_equal ['/page/10', []], rs.generate(:controller => 'content', :action => 'show_page', :id => 10) assert_equal ['/page/10', []], rs.generate(:controller => 'content', :action => 'show_page', :id => 10)
ctrl = ::Controllers::ContentController ctrl = ::ContentController
assert_equal({'controller' => ctrl, 'action' => 'show_page', 'id' => 1}, rs.recognize_path(%w(page))) assert_equal({'controller' => ctrl, 'action' => 'show_page', 'id' => 1}, rs.recognize_path(%w(page)))
assert_equal({'controller' => ctrl, 'action' => 'show_page', 'id' => '1'}, rs.recognize_path(%w(page 1))) assert_equal({'controller' => ctrl, 'action' => 'show_page', 'id' => '1'}, rs.recognize_path(%w(page 1)))
@ -850,12 +850,12 @@ class RouteSetTests < Test::Unit::TestCase
end end
def test_recognition_with_uppercase_controller_name def test_recognition_with_uppercase_controller_name
assert_equal({'controller' => ::Controllers::ContentController, 'action' => 'index'}, rs.recognize_path(%w(Content))) assert_equal({'controller' => ::ContentController, 'action' => 'index'}, rs.recognize_path(%w(Content)))
assert_equal({'controller' => ::Controllers::ContentController, 'action' => 'list'}, rs.recognize_path(%w(Content list))) assert_equal({'controller' => ::ContentController, 'action' => 'list'}, rs.recognize_path(%w(Content list)))
assert_equal({'controller' => ::Controllers::ContentController, 'action' => 'show', 'id' => '10'}, rs.recognize_path(%w(Content show 10))) assert_equal({'controller' => ::ContentController, 'action' => 'show', 'id' => '10'}, rs.recognize_path(%w(Content show 10)))
assert_equal({'controller' => ::Controllers::Admin::NewsFeedController, 'action' => 'index'}, rs.recognize_path(%w(Admin NewsFeed))) assert_equal({'controller' => ::Admin::NewsFeedController, 'action' => 'index'}, rs.recognize_path(%w(Admin NewsFeed)))
assert_equal({'controller' => ::Controllers::Admin::NewsFeedController, 'action' => 'index'}, rs.recognize_path(%w(Admin News_Feed))) assert_equal({'controller' => ::Admin::NewsFeedController, 'action' => 'index'}, rs.recognize_path(%w(Admin News_Feed)))
end end
def test_both_requirement_and_optional def test_both_requirement_and_optional