Skip to content
This repository has been archived by the owner on Apr 5, 2023. It is now read-only.

Commit

Permalink
added tests that checks for * routes and fixed the regexp check to no…
Browse files Browse the repository at this point in the history
…t be greedy because it was messing up on paths such as (:locale)/about(/*anything)
  • Loading branch information
Erik Ogan and Thomas Shafer authored and Erik Ogan committed May 23, 2012
1 parent ca0b88a commit 5a7fc2c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/i18n_routable/rack/mount/localizable_route.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# outoing route helper that injects i18n_ paramsto generate the route
module I18nRoutable
module Rack
module Mount
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n_routable/translation_assistant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/i18n_routable/i18n_routable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions spec/i18n_routable/translation_assistant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/locales/routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 5a7fc2c

Please sign in to comment.