Neil Cauldwell
2008-Jun-25 06:50 UTC
Rspec routing_spec failing on nested singular resource
This should be easy to solve; I''m trying to get an Rspec routing_spec
working with a singular nested resource;
map.resources :users do |user|
user.resource :profile
end
All the tests in the profile_routing_spec seem to be failing because
they can''t match the routes, for example;
# The spec
describe ProfileController do
describe "route generation" do
it "should map { :controller => ''profile'', :action
=> ''show'',
:user_id => ''1'' } to /user/1/profile" do
route_for(:controller => "profile", :action =>
"show", :user_id =>
1).should == "/user/1/profile"
end
# The failed spec message
should map { :controller => ''profile'', :action =>
''show'', :user_id =>
''1'' } to /user/1/profile
expected: "/user/1/profile",
got: "/profile/show?user_id=1" (using ==)
The spec seems to be turning the user_id (in the params) in to a query
on the profile resource, rather than using it to find the parent user
resource.
This is how ''rake routes'' looks:
POST /users/:user_id/profile
{:action=>"create", :controller=>"profiles"}
POST /users/:user_id/profile.:format
{:action=>"create", :controller=>"profiles"}
new_user_profile GET /users/:user_id/profile/new
{:action=>"new", :controller=>"profiles"}
formatted_new_user_profile GET /users/:user_id/profile/new.:format
{:action=>"new", :controller=>"profiles"}
edit_user_profile GET /users/:user_id/profile/edit
{:action=>"edit", :controller=>"profiles"}
formatted_edit_user_profile GET /users/:user_id/profile/edit.:format
{:action=>"edit", :controller=>"profiles"}
user_profile GET /users/:user_id/profile
{:action=>"show", :controller=>"profiles"}
formatted_user_profile GET /users/:user_id/profile.:format
{:action=>"show", :controller=>"profiles"}
PUT /users/:user_id/profile
{:action=>"update", :controller=>"profiles"}
PUT /users/:user_id/profile.:format
{:action=>"update", :controller=>"profiles"}
DELETE /users/:user_id/profile
{:action=>"destroy", :controller=>"profiles"}
DELETE /users/:user_id/profile.:format
{:action=>"destroy", :controller=>"profiles"}
Any ideas?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
