Browse files

Add routing tests from #1945

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2257 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 57e0cf8 commit b9c79f195fccd0a99c7915174a2932c469595bd0 @seckar seckar committed Sep 18, 2005
Showing with 57 additions and 2 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +55 −2 actionpack/test/controller/routing_test.rb
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Add routing tests from #1945 [ben@groovie.org]
+
* Add a routing test case covering #2101 [Nicholas Seckar]
* Cache relative_url_root for all webservers, not just Apache #2193 [skae]
View
57 actionpack/test/controller/routing_test.rb
@@ -148,6 +148,19 @@ def test_basic_dynamic
assert_equal({:controller => ::Controllers::ContentController, :action => 'dude'}, execute('hi/dude'))
end
+ def test_basic_dynamic_backwards
+ c = [Dynamic.new(:action), Static.new("hi")]
+ go c
+
+ assert_nil execute('')
+ assert_nil execute('boo')
+ assert_nil execute('boo/blah')
+ assert_nil execute('hi')
+ assert_equal({:action => 'index'}, execute('index/hi'))
+ assert_equal({:action => 'show'}, execute('show/hi'))
+ assert_nil execute('hi/dude')
+ end
+
def test_dynamic_with_default
c = [Static.new("hi"), Dynamic.new(:action, :default => 'index')]
g.result :controller, "::Controllers::ContentController", true
@@ -165,15 +178,29 @@ def test_dynamic_with_string_condition
c = [Static.new("hi"), Dynamic.new(:action, :condition => 'index')]
g.result :controller, "::Controllers::ContentController", true
go c
-
+
assert_nil execute('boo')
assert_nil execute('boo/blah')
assert_nil execute('hi')
assert_nil execute('hi/dude/what')
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi/index'))
assert_nil execute('hi/dude')
end
-
+
+ def test_dynamic_with_string_condition_backwards
+ c = [Dynamic.new(:action, :condition => 'index'), Static.new("hi")]
+ g.result :controller, "::Controllers::ContentController", true
+ go c
+
+ assert_nil execute('boo')
+ assert_nil execute('boo/blah')
+ assert_nil execute('hi')
+ assert_nil execute('dude/what/hi')
+ assert_nil execute('index/what')
+ assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('index/hi'))
+ assert_nil execute('dude/hi')
+ end
+
def test_dynamic_with_regexp_condition
c = [Static.new("hi"), Dynamic.new(:action, :condition => /^[a-z]+$/)]
g.result :controller, "::Controllers::ContentController", true
@@ -221,6 +248,32 @@ def test_path
assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => ['dude']}, execute('hi/dude'))
assert_equal 'dude/what', execute('hi/dude/what')[:file].to_s
end
+
+ def test_path_with_dynamic
+ c = [Dynamic.new(:action), Path.new(:file)]
+ g.result :controller, "::Controllers::ContentController", true
+
+ go c
+
+ assert_nil execute('')
+ assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => []}, execute('download'))
+ assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => %w(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 'dude/what', execute('hi/dude/what')[:file].to_s
+ end
+
+ def test_path_with_dynamic_and_default
+ c = [Dynamic.new(:action, :default => 'index'), Path.new(:file)]
+
+ go c
+
+ assert_equal({:action => 'index', :file => []}, execute(''))
+ assert_equal({:action => 'index', :file => []}, execute('index'))
+ assert_equal({:action => 'blarg', :file => []}, execute('blarg'))
+ assert_equal({:action => 'index', :file => ['content']}, execute('index/content'))
+ assert_equal({:action => 'show', :file => ['rails_dev.pdf']}, execute('show/rails_dev.pdf'))
+ end
def test_controller
c = [Static.new("hi"), Controller.new(:controller)]

0 comments on commit b9c79f1

Please sign in to comment.