Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

path not working properly when using capybara

I'm using rails 3.0.5, rspec2 with latest capybara.

Routes setup like:

scope "(:locale)", :locale => /de|fr|it|en/ do
  resources :dossiers
end

In application_controller I have this:

def default_url_options(options={})
  options[:locale] = "es"
  options
end

So in my views I can use

link_to 'test', dossier_path(1)

without any problems.

But when I do the same in capybara's visit it tries to use the 1 for the locale and not for the id. It only works when I use

visit dossier_path(nil, 1)

or

visit dossier_path(:id => 1)

But both are ugly and looks like a dirty hack. So why do I need to use this dirty hack and what do I jave to do, so that I can use the path methods just like in the views (so without the dirty hack of having to add nil or explicitly pass :id => ...)? :)

like image 866
gucki Avatar asked Mar 22 '11 19:03

gucki


1 Answers

I ran into a similar issue. You can set the default_url_options in a before block like this in request specs:

 before :each do
   app.default_url_options = { :locale => :es }
 end
like image 169
effkay Avatar answered Nov 05 '22 22:11

effkay