aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-03-11 18:06:10 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-03-11 18:06:22 -0800
commit89c5b9aee7d7db95cec9e5a934c3761872ab107e (patch)
tree0eb6c9ea9d2caf43cd4c7eee423284853220e233 /actionpack
parent53794cf7b5a9f66c3173f4ca9a5ee3279965a3a0 (diff)
downloadrails-89c5b9aee7d7db95cec9e5a934c3761872ab107e.tar.gz
rails-89c5b9aee7d7db95cec9e5a934c3761872ab107e.tar.bz2
rails-89c5b9aee7d7db95cec9e5a934c3761872ab107e.zip
do not automatically add format to routes that end in a slash
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb2
-rw-r--r--actionpack/test/action_dispatch/routing/mapper_test.rb51
2 files changed, 52 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 1733c8032a..756a21dcac 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -107,7 +107,7 @@ module ActionDispatch
if @options[:format] == false
@options.delete(:format)
path
- elsif path.include?(":format")
+ elsif path.include?(":format") || path.end_with?('/')
path
else
"#{path}(.:format)"
diff --git a/actionpack/test/action_dispatch/routing/mapper_test.rb b/actionpack/test/action_dispatch/routing/mapper_test.rb
new file mode 100644
index 0000000000..9966234f1b
--- /dev/null
+++ b/actionpack/test/action_dispatch/routing/mapper_test.rb
@@ -0,0 +1,51 @@
+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
+ 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
+ end
+ end
+end