Topic: Basic test that is failing, probably something simple
I have a test that I can't get to pass and since I am new to TDD I really am not sure of my options on how to get it passing. In basic english. I have a project and a todo_item. todo_item belong to projects, projects have many todo_items. When I update a todo_item it should redirect to its project page. Simple enough. Here is the test:
it "update action should redirect when model is valid" do
TodoItem.any_instance.stubs(:valid?).returns(true)
todo = TodoItem.first
put :update, :id => todo
response.should redirect_to(project_url(todo.project))
endThe failure message is:
TodoItemsController update action should redirect when model is valid
Failure/Error: put :update, :id => todo
ActionController::RoutingError:
No route matches {:controller=>"todo_items", :action=>"update", :id=>nil}
# ./spec/controllers/todo_items_controller_spec.rb:61Now when I run through the browser it works just fine, so I am fairly sure its not the app code. No TodoItems are getting created so TodoItem.first never finds I record. I dont think that I have anything overly complicated, but I just cant get it work no matter what I try. Any help and suggestions would be greatly appreciated.