Patrick J. Collins
2012-Feb-07 01:45 UTC
[rspec-users] nested route not receiving :id parameter within controller spec
I''ve got a share method in my controller, and I have the following spec: describe PostsController do describe "#share" do it "doesn''t blow up" do post :share, :id => @post.id end # ... etc And... It blows up! Failures: 1) PostsController#share shares Failure/Error: post :share ActionController::RoutingError: No route matches {:controller=>"posts", :action=>"share"} # ./spec/controllers/posts_controller_spec.rb:7 My routes has: resources :posts do post :share, :on => :member end rake routes shows: share_post POST /posts/:id/share(.:format) {:action=>"share", :controller=>"posts"} ... Why is it ignoring the :id parameter in my test and therefore blowing up? Thanks. Patrick J. Collins http://collinatorstudios.com
Andrew Timberlake
2012-Feb-07 03:39 UTC
[rspec-users] nested route not receiving :id parameter within controller spec
The id belongs to post so your test line should be: post :share, :post_id => @post.id Andrew On Tuesday 07 February 2012 at 3:45 AM, Patrick J. Collins wrote:> I''ve got a share method in my controller, and I have the following spec: > > describe PostsController do > > describe "#share" do > > it "doesn''t blow up" do > post :share, :id => @post.id > end > > # ... etc > > And... It blows up! > > Failures: > > 1) PostsController#share shares > Failure/Error: post :share > ActionController::RoutingError: > No route matches {:controller=>"posts", :action=>"share"} > # ./spec/controllers/posts_controller_spec.rb:7 > > My routes has: > > resources :posts do > post :share, :on => :member > end > > rake routes shows: > > share_post POST /posts/:id/share(.:format) {:action=>"share", :controller=>"posts"} > > ... > > Why is it ignoring the :id parameter in my test and therefore blowing up? > > Thanks. > > Patrick J. Collins > http://collinatorstudios.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org (mailto:rspec-users at rubyforge.org) > http://rubyforge.org/mailman/listinfo/rspec-users > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120207/fa136115/attachment.html>
Patrick J. Collins
2012-Feb-07 05:05 UTC
[rspec-users] nested route not receiving :id parameter within controller spec
I tried that and got the same result, plus rake routes says: share_post POST /posts/:id/share(.:format) {:action=>"share", :controller=>"posts"} NOT share_post POST /posts/:post_id/share(.:format) {:action=>"share", :controller=>"posts"} So I don''t see how that can be the case... Patrick J. Collins http://collinatorstudios.com
Justin Ko
2012-Feb-07 06:52 UTC
[rspec-users] nested route not receiving :id parameter within controller spec
On Feb 6, 2012, at 6:45 PM, Patrick J. Collins wrote:> I''ve got a share method in my controller, and I have the following spec: > > describe PostsController do > > describe "#share" do > > it "doesn''t blow up" do > post :share, :id => @post.idDoes @post actually have an id? I believe the :id key will not be present if the value is nil.> end > > # ... etc > > And... It blows up! > > Failures: > > 1) PostsController#share shares > Failure/Error: post :share > ActionController::RoutingError: > No route matches {:controller=>"posts", :action=>"share"} > # ./spec/controllers/posts_controller_spec.rb:7 > > My routes has: > > resources :posts do > post :share, :on => :member > end > > rake routes shows: > > share_post POST /posts/:id/share(.:format) {:action=>"share", :controller=>"posts"} > > ... > > Why is it ignoring the :id parameter in my test and therefore blowing up? > > Thanks. > > Patrick J. Collins > http://collinatorstudios.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Andrew Timberlake
2012-Feb-07 07:06 UTC
[rspec-users] nested route not receiving :id parameter within controller spec
Sorry, too quick to answer. Next clue is the fact that the RSpec error is ignoring your id attribute. try: post :share, :id => 42 and see if that gets you past the current error Andrew On Tuesday 07 February 2012 at 7:05 AM, Patrick J. Collins wrote:> I tried that and got the same result, plus rake routes says: > > share_post POST /posts/:id/share(.:format) {:action=>"share", :controller=>"posts"} > > NOT > > share_post POST /posts/:post_id/share(.:format) {:action=>"share", :controller=>"posts"} > > So I don''t see how that can be the case... > > Patrick J. Collins > http://collinatorstudios.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org (mailto:rspec-users at rubyforge.org) > http://rubyforge.org/mailman/listinfo/rspec-users > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120207/49c4de08/attachment.html>
Patrick J. Collins
2012-Feb-07 10:11 UTC
[rspec-users] nested route not receiving :id parameter within controller spec
> Sorry, too quick to answer. > Next clue is the fact that the RSpec error is ignoring your id attribute. > try: > post :share, :id => 42 > and see if that gets you past the current errorYeah-- Unfortunatley I also had tried this and got the same result... Patrick J. Collins http://collinatorstudios.com
David Chelimsky
2012-Feb-07 12:31 UTC
[rspec-users] nested route not receiving :id parameter within controller spec
On Tue, Feb 7, 2012 at 4:11 AM, Patrick J. Collins <patrick at collinatorstudios.com> wrote:>> Sorry, too quick to answer. >> Next clue is the fact that the RSpec error is ignoring your id attribute. >> try: >> post :share, :id => 42 >> and see if that gets you past the current error > > Yeah-- Unfortunatley I also had tried this and got the same result...Do you see any different behavior using a Rails functional test?
Reasonably Related Threads
- undefined method `route_for' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:
- received unexpected message :id= with (20)
- problem setting expectation for test with delayed::job
- Could anyone please help with rspec/nested resource behavior checking?
- writing to many_to_many table