Skip to content
Browse files

Allow a route to have :format => true

When format is true, it is mandatory (as opposed to :format => false).
This is currently not possible with resource routes, which automatically
make format optional by default.
  • Loading branch information...
1 parent 8e00611 commit b9c91426032e110aa60fca563ab513621096289a @sferik sferik committed Jul 25, 2011
Showing with 9 additions and 0 deletions.
  1. +2 −0 actionpack/lib/action_dispatch/routing/mapper.rb
  2. +7 −0 actionpack/test/dispatch/mapper_test.rb
View
2 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -119,6 +119,8 @@ def normalize_path(path)
path
elsif path.include?(":format") || path.end_with?('/')
path
+ elsif @options[:format] == true
+ "#{path}.:format"
else
"#{path}(.:format)"
end
View
7 actionpack/test/dispatch/mapper_test.rb
@@ -83,6 +83,13 @@ def test_map_wildcard_with_format_false
assert_equal '/*path', fakeset.conditions.first[:path_info]
assert_nil fakeset.requirements.first[:path]
end
+
+ def test_map_wildcard_with_format_true
+ fakeset = FakeSet.new
+ mapper = Mapper.new fakeset
+ mapper.match '/*path', :to => 'pages#show', :format => true
+ assert_equal '/*path.:format', fakeset.conditions.first[:path_info]
+ end
end
end
end

0 comments on commit b9c9142

Please sign in to comment.
Something went wrong with that request. Please try again.