Rails 3 integration test mangles (model)_path(@ins

2019-08-06 22:24发布

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

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

which works fine.

In my integration test I use:

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

which does not work at all fine.

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

Using:

get "/docs/7" 

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???

Using rails 3.0.8.

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?

1条回答
祖国的老花朵
2楼-- · 2019-08-06 23:09

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.

查看更多
登录 后发表回答