开发者

RSpec: testing path to route mapping (but not the other way around)

I need to use the functionality of params_from, which was deprecated. Now route_to combines behavior of params_from and route_for. But I do not want to test that the route generates the path, because it does not and this is intentional (for backward compatability in old emails, I need to "alias" old path to the correct controller/action, but path generated by the new route will be different. I know, confusing ;)

When using params_from and route_to, I get conflicting results (maybe params_for is broken?):

# params_from(:get, 'user/tasks').should == { :controller => 'user', :action => 'tasks' }
No route matches "user/tasks" with {:method=>:get} 

# { :get => 'user/tasks' }.should_not be_routable开发者_JAVA技巧
Expected 'GET user/tasks' to fail, but it routed to {"action"=>"tasks", "controller"=>"user"} instead

The route does exist, I can use the path via UI successfully.

IMO this combination of params_from and route_for is a bad idea, unless the seperate matches are still supported. But maybe I've missed something obvious ;)


This is what I was looking for, and found it while hacking the source code: assert_recognizes({ :controller => 'user', :action => 'tasks'}, 'user/tasks', {}, nil)

I will probably wrap it under params_for matcher.


What's the value of testing your routeset explicitly?

You should probably get this for free if you write even a minimal functional test for your controllers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜