使用水豚时路径无法正常工作 [英] path not working properly when using capybara
问题描述
我正在使用带有最新水豚的rails 3.0.5,rspec2。
I'm using rails 3.0.5, rspec2 with latest capybara.
路由设置如下:
scope "(:locale)", :locale => /de|fr|it|en/ do
resources :dossiers
end
在application_controller中,我这样:
In application_controller I have this:
def default_url_options(options={})
options[:locale] = "es"
options
end
在我看来,我可以使用
link_to 'test', dossier_path(1)
没有任何问题。
但是当我在capybara的访问中执行相同操作时,它会尝试将1用于语言环境而不是用于ID。仅当我使用
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)
或
visit dossier_path(:id => 1)
但两者都很丑陋,看起来像是肮脏的骇客。那么为什么我需要使用这个肮脏的技巧,以及我该怎么做,以便可以像在视图中一样使用path方法(这样就不必添加nil或显式传递:id =>了。 ..)? :)
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 => ...)? :)
推荐答案
我遇到了类似的问题。您可以在请求规范中的before块中设置default_url_options:
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
这篇关于使用水豚时路径无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!