Rails Functional Test of Arbitrary or Custom URLs

筅森魡賤 提交于 2019-12-04 03:38:28

Use assert_routing to test routes:

assert_routing("/photos/10/style", :controller => "photos", :action => "show", :id => "10", :style => [])

assert_routing("/photos/10/style/cool", :controller => "photos", :action => "show", :id => "10", :style => ["cool"])

assert_routing("/photos/10/style/cool/and/awesome", :controller => "photos", :action => "show", :id => "10", :style => ["cool", "and", "awesome"])

In your integration test you can then do:

test "get photos" do
   get "/photos/10/style/cool"
   assert_response :success
end

From the Rails API documentation:

Route globbing

Specifying *[string] as part of a rule like:

map.connect '*path' , :controller => 'blog' , :action => 'unrecognized?'

will glob all remaining parts of the route that were not recognized earlier. The globbed values are in params[:path] as an array of path segments.

So it looks like you need to pass the :path arguments, to test the action correctly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!