Problem with routes in functional testing

Posted by Wishmaster on Stack Overflow See other posts from Stack Overflow or by Wishmaster
Published on 2011-01-06T13:20:42Z Indexed on 2011/01/06 13:54 UTC
Read the original article Hit count: 165

Hi, I'm making a simple test project to prepare myself for my test. I'm fairly new to nested resources, in my example I have a newsitem and each newsitem has comments.

The routing looks like this:

resources :comments

resources :newsitems do
    resources :comments
end

I'm setting up the functional tests for comments at the moment and I ran into some problems.

This will get the index of the comments of a newsitem. @newsitem is declared in the setup ofc.

test "should get index" do
    get :index,:newsitem_id => @newsitem
    assert_response :success
    assert_not_nil assigns(:newsitem)
end

But the problem lays here, in the "should get new".

 test "should get new" do
    get new_newsitem_comment_path(@newsitem)
    assert_response :success
 end

I'm getting the following error.

ActionController::RoutingError: No route matches {:controller=>"comments", :action=>"/newsitems/1/comments/new"}

But when I look into the routes table, I see this:

new_newsitem_comment GET    /newsitems/:newsitem_id/comments/new(.:format)      {:action=>"new", :controller=>"comments"}

Can't I use the name path or what I'm doing wrong here?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about resources