aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2011-03-29 03:01:46 +0700
committerAndrew White <andyw@pixeltrix.co.uk>2011-03-29 10:12:17 +0100
commit84a4ef63a4b890dc29cd62543f52c863fb0f0dd5 (patch)
tree77f3914429de2f8207d72723ed0ba168c0ecdf63 /actionpack/test/dispatch
parent51551a0a5bd6f7e4116bc3759a4d7c15634643dc (diff)
downloadrails-84a4ef63a4b890dc29cd62543f52c863fb0f0dd5.tar.gz
rails-84a4ef63a4b890dc29cd62543f52c863fb0f0dd5.tar.bz2
rails-84a4ef63a4b890dc29cd62543f52c863fb0f0dd5.zip
Move mapper_test to the appropriate location
It seems like in 89c5b9aee7d7db95cec9e5a934c3761872ab107e Aaron actually put the test in action_dispatch folder. However, there's already a `test/dispatch` directory which I think it's more appropriate. Signed-off-by: Andrew White <andyw@pixeltrix.co.uk>
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r--actionpack/test/dispatch/mapper_test.rb88
1 files changed, 88 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb
new file mode 100644
index 0000000000..f90de735b6
--- /dev/null
+++ b/actionpack/test/dispatch/mapper_test.rb
@@ -0,0 +1,88 @@
+require 'abstract_unit'
+
+module ActionDispatch
+ module Routing
+ class MapperTest < ActiveSupport::TestCase
+ class FakeSet
+ attr_reader :routes
+
+ def initialize
+ @routes = []
+ end
+
+ def resources_path_names
+ {}
+ end
+
+ def request_class
+ ActionDispatch::Request
+ end
+
+ def add_route(*args)
+ routes << args
+ end
+
+ def conditions
+ routes.map { |x| x[1] }
+ end
+
+ def requirements
+ routes.map { |x| x[2] }
+ end
+ end
+
+ def test_initialize
+ Mapper.new FakeSet.new
+ end
+
+ def test_map_slash
+ fakeset = FakeSet.new
+ mapper = Mapper.new fakeset
+ mapper.match '/', :to => 'posts#index', :as => :main
+ assert_equal '/', fakeset.conditions.first[:path_info]
+ end
+
+ def test_map_more_slashes
+ fakeset = FakeSet.new
+ mapper = Mapper.new fakeset
+
+ # FIXME: is this a desired behavior?
+ mapper.match '/one/two/', :to => 'posts#index', :as => :main
+ assert_equal '/one/two(.:format)', fakeset.conditions.first[:path_info]
+ end
+
+ def test_map_wildcard
+ fakeset = FakeSet.new
+ mapper = Mapper.new fakeset
+ mapper.match '/*path', :to => 'pages#show'
+ assert_equal '/*path(.:format)', fakeset.conditions.first[:path_info]
+ assert_equal /.+?/, fakeset.requirements.first[:path]
+ end
+
+ def test_map_wildcard_with_other_element
+ fakeset = FakeSet.new
+ mapper = Mapper.new fakeset
+ mapper.match '/*path/foo/:bar', :to => 'pages#show'
+ assert_equal '/*path/foo/:bar(.:format)', fakeset.conditions.first[:path_info]
+ assert_nil fakeset.requirements.first[:path]
+ end
+
+ def test_map_wildcard_with_multiple_wildcard
+ fakeset = FakeSet.new
+ mapper = Mapper.new fakeset
+ mapper.match '/*foo/*bar', :to => 'pages#show'
+ assert_equal '/*foo/*bar(.:format)', fakeset.conditions.first[:path_info]
+ assert_nil fakeset.requirements.first[:foo]
+ assert_equal /.+?/, fakeset.requirements.first[:bar]
+ end
+
+ def test_map_wildcard_with_format_false
+ fakeset = FakeSet.new
+ mapper = Mapper.new fakeset
+ mapper.match '/*path', :to => 'pages#show', :format => false
+ assert_equal '/*path', fakeset.conditions.first[:path_info]
+ assert_nil fakeset.requirements.first[:path]
+ end
+ end
+ end
+end