【发布时间】:2011-08-31 19:13:37
【问题描述】:
我有一个 Doc 类,其中包含由脚手架生成器创建的标准路由。在代码中,我使用
docs_path(@doc) # => /docs/7
效果很好。
在我的集成测试中我使用:
get docs_path(@doc) #=> /docs.7
这根本不起作用。
这对于使用 rails 模型的标准路由的其他控制器是相同的。
使用:
get "/docs/7"
在集成测试代码中工作正常,但是当我尝试使用“_path”或“_url”帮助程序处理页面时,它会以类似的方式破坏它们,从而导致错误。
注意:当我在开发环境中打开笔记本电脑上的实际页面时,此代码可以正常工作。
:当我尝试通过编写测试来做正确的事情并且测试引入了正常环境中不存在的错误时,这非常令人沮丧。你是怎么处理的???
使用轨道 3.0.8。
以下是 rake.routes 中的相关行
docs GET /docs(.:format) {:action=>"index", :controller=>"docs"}
POST /docs(.:format) {:action=>"create", :controller=>"docs"}
new_doc GET /docs/new(.:format) {:action=>"new", :controller=>"docs"}
edit_doc GET /docs/:id/edit(.:format) {:action=>"edit", :controller=>"docs"}
doc GET /docs/:id(.:format) {:action=>"show", :controller=>"docs"}
PUT /docs/:id(.:format) {:action=>"update", :controller=>"docs"}
DELETE /docs/:id(.:format) {:action=>"destroy", :controller=>"docs"}
为什么要这样做?我可以修复它吗?
【问题讨论】:
标签: ruby-on-rails-3 routes integration-testing helper