aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/mapper_test.rb
diff options
context:
space:
mode:
authorRyan Bigg <radarlistener@gmail.com>2011-04-05 21:22:38 +1000
committerRyan Bigg <radarlistener@gmail.com>2011-04-05 21:22:38 +1000
commit92e6255b58ce445d23580b669dac67d80e64d411 (patch)
treede3a01091787b30f1bafd462eedcb6210342493a /actionpack/test/dispatch/mapper_test.rb
parent357578256fb55e32ae87c6fbf22a1c19f59ce264 (diff)
parentac07da8fc72b7a57fd4a60c0dcb5b777d85f9eb7 (diff)
downloadrails-92e6255b58ce445d23580b669dac67d80e64d411.tar.gz
rails-92e6255b58ce445d23580b669dac67d80e64d411.tar.bz2
rails-92e6255b58ce445d23580b669dac67d80e64d411.zip
Merge branch 'master' of github.com:lifo/docrails
* 'master' of github.com:lifo/docrails: (57 commits) Made the defaults section a little more readable and more to the point, giving a overview of the possibilities. Added information about default values added .'s to headings in the initialization textile page s/ERb/ERB/g (part II) s/ERb/ERB/g Bump up erubis to 2.7.0 Implicit actions named not_implemented can be rendered Gem::Specification#has_rdoc= is deprecated since rubygems 1.7.0 default_executable is deprecated since rubygems 1.7.0 Trivial fix to HTTP Digest auth MD5 example Moved Turn activation/dependency to railties fix typo Direct logging of Active Record to STDOUT so it's shown inline with the results in the console [DHH] Add using Turn with natural language test case names if the library is available (which it will be in Rails 3.1) [DHH] require turn only for minitest Use Turn to format all Rails tests and enable the natural language case names Improve docs. pass respond_with options to controller render when using a template for api navigation only try to display an api template in responders if the request is a get or there are no errors when using respond_with with an invalid resource and custom options, the default response status and error messages should be returned ...
Diffstat (limited to 'actionpack/test/dispatch/mapper_test.rb')
-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..b6c08ffc33
--- /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