Rails 3集成测试工具(模型)_path(@instance)帮助器 [英] Rails 3 integration test mangles (model)_path(@instance) helper

查看:77
本文介绍了Rails 3集成测试工具(模型)_path(@instance)帮助器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Doc类,其中包含由脚手架生成器创建的标准路由.在代码中,我使用

I have a Doc class with the standard routes created by the scaffold generator. In the code, I use

docs_path(@doc)  # => /docs/7

效果很好.

在集成测试中,我使用:

In my integration test I use:

get  docs_path(@doc) #=> /docs.7

这根本无法正常工作.

这与使用标准导轨模型的其他控制器相同.

This is the same for other controllers that are using the standard routes for rails models.

使用:

get "/docs/7" 

集成测试代码中的

工作正常,但是当我尝试使用'_path'或'_url'帮助器处理页面时,它会以类似的方式处理这些页面,从而导致错误.

in the integration test code works fine, but when I it tries to process a page using a '_path' or '_url' helper, then it mangles those in a similar way, which causes errors.

注意:当我在开发环境中在笔记本电脑上打开实际页面时,此代码可以正常工作.

Note: This code works fine when I open the actual page on my laptop in the development environment.

:当我尝试通过编写测试来做正确的事情并且测试引入了正常环境中不存在的错误时,这非常令人沮丧.您如何处理??

: It is very frustrating when I try to do the right thing by writing tests and the tests introduce bugs that aren't there in the normal environment. How do you deal with that???

使用滑轨3.0.8.

这是来自rake.routes的相关行

Here are the relevant lines from 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"}

为什么要这样做?我可以解决吗?

Why is it doing this? Can I fix it?

推荐答案

标准"路由将是单数命名路由:doc_path.您正在使用docs_path.要链接到特定文档时,请使用单数名称;在要获取这些文档的列表时,请使用复数.

The "standard" route would be that it is a singular named route: doc_path. You are using docs_path. Use the singular name when you want to link to a specific doc and use the plural when you want to get a list of those.

这篇关于Rails 3集成测试工具(模型)_path(@instance)帮助器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆