Permalink
Browse files

added tests that checks for * routes and fixed the regexp check to no…

…t be greedy because it was messing up on paths such as (:locale)/about(/*anything)
  • Loading branch information...
1 parent ca0b88a commit 5a7fc2cd1f9f25135469a844b19eff50a18ec71a Erik Ogan and Thomas Shafer committed with erikogan May 22, 2012
@@ -1,3 +1,4 @@
+# outoing route helper that injects i18n_ paramsto generate the route
module I18nRoutable
module Rack
module Mount
@@ -14,7 +14,7 @@ def convert_path_to_localized_regexp path
new_path, segments = '', []
- new_path << path.split(/(\(.+\))/).map do |component|
+ new_path << path.split(/(\(.+?\))/).map do |component|
if component.starts_with?("(") || component == '//'
component
else
@@ -110,6 +110,11 @@ def resolve(path, http_verb=:get)
resolve('/es/todos-los-puestos').should eql :display=>"all", :controller=>"posts", :action=>"index", :locale=>"es", :i18n_all__the__posts=>"todos-los-puestos"
end
+ it 'should recognize * routes' do
+ resolve('/es/sobre').should eql :controller => "cms", :action => 'show', :locale => 'es', :i18n_about => 'sobre'
+ resolve('/es/sobre/another-page').should eql :controller => "cms", :action => 'show', :locale => 'es', :i18n_about => 'sobre', :anything => 'another-page'
+ end
+
end
@@ -169,6 +174,11 @@ def resolve(path, http_verb=:get)
all_posts_path.should eql '/all-the-posts'
end
+ it 'should work for *parameters' do
+ about_path(:locale => 'es').should eql '/es/sobre'
+ about_path(:locale => 'es', :anything => 'extra-page').should eql '/es/sobre/extra-page'
+ end
+
it "should accept :locale param as an option" do
posts_path(:locale => :es).should eql "/es/puestos"
# Thread.current[:WTF] = true
@@ -18,6 +18,11 @@ def convert path
convert("/posts").should eql ["/:i18n_posts", ["posts"]]
end
+ it "should translate the components of a glob url" do
+ convert("/about").should eql ["/:i18n_about", ["about"]]
+ convert("/about(/*anything)").should eql ["/:i18n_about(/*anything)", ["about"]]
+ end
+
it 'should preserve order' do
convert("/posts/new").should eql ["/:i18n_posts/:i18n_new", ["posts", "new"]]
end
View
@@ -11,7 +11,7 @@ es:
bypass_action_controller: derivacion_controlador_de_accion
test: prueba
testing_url_for: "url-para-probar"
-
+ about: sobre
fr:
routes:
new: nouvelles
View
@@ -42,6 +42,8 @@ def draw!
match "/bypass_action_controller", :to => proc {|env| [200, {}, ["Hello world"]] }
+ match 'about(/*anything)' => 'cms#show', :as => :about
+
# TestController
get 'test' => "test#foo", :as => :test
get 'testing_url_for' => 'test#use_url_for_with_implicit_params'

0 comments on commit 5a7fc2c

Please sign in to comment.