Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMarco Pineyro
5,670 PointsRouting error after adding index to user_friendships_controller_test.rb
Hope someone (Jason?!?) can help me out here. Maybe I've just been staring at the screen too long.
I'm following along in Jason's Programming > Building Social Features in Ruby on Rails > Adding State > Test Factories video tutorial. Everything is hunky dory until 6:32. Jason runs his test right after adding:
context "#index" do
context "when not logged in" do
should "redirect to the login page" do
get :index
assert_response :redirect
end
end
end
He gets an expected error (his error after the ellipsis matches mine):
1) Error:
test: #index when not logged in should redirect to the login page. (UserFriendshipsControllerTest):
AbstractController::ActionNotFound: The action 'index' could not be found for the UserFriendshipsController
...
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.6/lib/action_controller/test_case.rb:469:in process'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/actionpack-3.2.6/lib/action_controller/test_case.rb:49:in
process'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/devise-2.1.2/lib/devise/test_helpers.rb:19:in block in process'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/devise-2.1.2/lib/devise/test_helpers.rb:71:in
catch'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/devise-2.1.2/lib/devise/test_helpers.rb:71:in _catch_warden'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/devise-2.1.2/lib/devise/test_helpers.rb:19:in
process'
/usr/local/rvm/gems/ruby-1.9.3-p193/gems/actionpack-3.2.6/lib/action_controller/test_case.rb:386:in get'
test/functional/user_friendships_controller_test.rb:7:in
block (3 levels) in <class:UserFriendshipsControllerTest>'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shoulda-context-1.0.0/lib/shoulda/context/context.rb:398:in call'
/usr/local/rvm/gems/ruby-1.9.3-p194/gems/shoulda-context-1.0.0/lib/shoulda/context/context.rb:398:in
block in create_test_from_should_hash'
18 tests, 25 assertions, 0 failures, 1 errors, 0 skips
I get:
1) Error:
test: #index when not logged in should redirect to the login page. (UserFriendshipsControllerTest):
ActionController::RoutingError: No route matches {:controller=>"user_friendships"}
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:533:in raise_routing_error'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:529:in
rescue in generate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:521:in generate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:562:in
generate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:558:in generate_extras'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_dispatch/routing/route_set.rb:554:in
extra_keys'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_controller/test_case.rb:151:in assign_parameters'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_controller/test_case.rb:463:in
process'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_controller/test_case.rb:49:in process'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/devise-2.2.4/lib/devise/test_helpers.rb:19:in
block in process'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/devise-2.2.4/lib/devise/test_helpers.rb:72:in catch'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/devise-2.2.4/lib/devise/test_helpers.rb:72:in
_catch_warden'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/devise-2.2.4/lib/devise/test_helpers.rb:19:in process'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_controller/test_case.rb:390:in
get'
test/functional/user_friendships_controller_test.rb:7:in block (3 levels) in <class:UserFriendshipsControllerTest>'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/shoulda-context-1.1.4/lib/shoulda/context/context.rb:400:in
call'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/shoulda-context-1.1.4/lib/shoulda/context/context.rb:400:in `block in create_test_from_should_hash'
18 tests, 25 assertions, 0 failures, 1 errors, 0 skips
Rake routes gives me: ? treebook git:(master) rake routes profiles_show GET /profiles/show(.:format) profiles#show register GET /register(.:format) devise/registrations#new login GET /login(.:format) devise/sessions#new logout GET /logout(.:format) devise/sessions#destroy user_password POST /users/password(.:format) devise/passwords#create new_user_password GET /users/password/new(.:format) devise/passwords#new edit_user_password GET /users/password/edit(.:format) devise/passwords#edit PUT /users/password(.:format) devise/passwords#update cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel user_registration POST /users(.:format) devise/registrations#create new_user_registration GET /users/sign_up(.:format) devise/registrations#new edit_user_registration GET /users/edit(.:format) devise/registrations#edit PUT /users(.:format) devise/registrations#update DELETE /users(.:format) devise/registrations#destroy new_user_session GET /login(.:format) devise/sessions#new user_session POST /login(.:format) devise/sessions#create destroy_user_session DELETE /logout(.:format) devise/sessions#destroy user_friendships POST /user_friendships(.:format) user_friendships#create new_user_friendships GET /user_friendships/new(.:format) user_friendships#new edit_user_friendships GET /user_friendships/edit(.:format) user_friendships#edit GET /user_friendships(.:format) user_friendships#show PUT /user_friendships(.:format) user_friendships#update DELETE /user_friendships(.:format) user_friendships#destroy statuses GET /statuses(.:format) statuses#index POST /statuses(.:format) statuses#create new_status GET /statuses/new(.:format) statuses#new edit_status GET /statuses/:id/edit(.:format) statuses#edit status GET /statuses/:id(.:format) statuses#show PUT /statuses/:id(.:format) statuses#update DELETE /statuses/:id(.:format) statuses#destroy feed GET /feed(.:format) statuses#index root / statuses#index profile GET /:id(.:format) profiles#show
Everything (rake) works JUST prior to the insertion of the #index context to the user_friendships_controller_test.rb. Help me find the likely simple thing I'm over looking.
Here's a link to my git repository: https://github.com/tycho211/treebook
Thanks!
Marco
2 Answers
Marco Pineyro
5,670 PointsI should add, that I continue to get this failure after adding:
def index
end
to the user_friendships_controller AND after creating the index.htm.erb template in app/views/user_friendships
Thoughts?!?
Thanks,
Marco
Marco Pineyro
5,670 PointsTurns out line 18 in routes.rb was:
resource :user_friendships
and it should have been:
resources :user_friendships