Giuseppe Bertini
2009-Sep-11 20:28 UTC
[rspec-users] controller specs with non-RESTful routes
Hello list, this should be an easy one, but I seem to be stuck. What is the proper way to mimic a POST request for a named, non-RESTful route? here''s the route and the rest of the setup: map.accept_invitation ''/accept_invitation/:id'', :controller => "invitations", :action => "accept", :method => "post" class InvitationsController < ApplicationController def accept end end describe InvitationsController do describe "POST ''accept''" do it "should be successful" do post :accept, :id => 1 response.should be_success end end end When I run this spec, I get: No route matches {:controller=>"invitations", :action=>"accept", :id=>"1"} Can anyone please suggest what I should be writing instead to test this request? Thanks in advance! Giuseppe -- Posted via http://www.ruby-forum.com/.
On 11 Sep 2009, at 21:28, Giuseppe Bertini wrote:> Hello list, > this should be an easy one, but I seem to be stuck. > What is the proper way to mimic a POST request for a named, non- > RESTful > route? > > here''s the route and the rest of the setup: > > map.accept_invitation ''/accept_invitation/:id'', :controller => > "invitations", :action => "accept", :method => "post" > > class InvitationsController < ApplicationController > def accept > end > end > > describe InvitationsController do > describe "POST ''accept''" do > it "should be successful" do > post :accept, :id => 1 > response.should be_success > end > end > end > > When I run this spec, I get: > No route matches {:controller=>"invitations", :action=>"accept", > :id=>"1"} > > Can anyone please suggest what I should be writing instead to test > this > request?Looks about right to me. Must be something silly that you''ve missed, but I''m afraid I can''t see it. cheers, Matt +447974 430184 matt at mattwynne.net http://mattwynne.net
David Chelimsky
2009-Sep-14 09:52 UTC
[rspec-users] controller specs with non-RESTful routes
On Fri, Sep 11, 2009 at 3:28 PM, Giuseppe Bertini <lists at ruby-forum.com> wrote:> Hello list, > this should be an easy one, but I seem to be stuck. > What is the proper way to mimic a POST request for a named, non-RESTful > route? > > here''s the route and the rest of the setup: > > map.accept_invitation ''/accept_invitation/:id'', :controller => > "invitations", :action => "accept", :method => "post" > > class InvitationsController < ApplicationController > ?def accept > ?end > end > > describe InvitationsController do > ?describe "POST ''accept''" do > ? ?it "should be successful" do > ? ? ?post :accept, :id => 1 > ? ? ?response.should be_success > ? ?end > ?end > end > > When I run this spec, I get: > No route matches {:controller=>"invitations", :action=>"accept", > :id=>"1"}I just fired up a brand new rails app and copied the above into config/routes.rb, app/controllers/invitations_controller.rb, and spec/controllers/invitations_controller_spec.rb, ran the spec and it passed with flying color (green). I''m using rails-2.3.4, ruby-1.8.7, rspec-1.2.8 and rspec-rails-1.2.7.1. Which versions are you using? Cheers, David> > Can anyone please suggest what I should be writing instead to test this > request? > > Thanks in advance! > Giuseppe > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Giuseppe Bertini
2009-Sep-26 06:56 UTC
[rspec-users] controller specs with non-RESTful routes
Pretty please? :) -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2009-Sep-26 09:15 UTC
[rspec-users] controller specs with non-RESTful routes
On Sat, Sep 26, 2009 at 1:56 AM, Giuseppe Bertini <lists at ruby-forum.com> wrote:> Pretty please? :)Huh? Pretty please what? Matt and I have both responded. In my case I asked you about the versions you have. You didn''t quote any of the previous posts in this thread, so I have no idea what you''re asking for at this point. Did you receive our responses?
Giuseppe Bertini
2009-Sep-26 13:10 UTC
[rspec-users] controller specs with non-RESTful routes
> Huh? Pretty please what? Matt and I have both responded. In my case I > asked you about the versions you have. You didn''t quote any of the > previous posts in this thread, so I have no idea what you''re asking > for at this point. Did you receive our responses?So sorry, I must be missing something. I am looking right now at this page: http://www.ruby-forum.com/topic/195172 And what I see is my original post, my own "pretty please" and your "Huh?", period. Looking at the index page (http://www.ruby-forum.com/forum/32) does not help. I''m wondering--am I looking at the wrong forum page? But then, why do I see your latest response (and received the email notification I requested), but not the previous? Sorry for the trouble, I would appreciate if you could point me to the proper URL, if this is the problem. Thanks a bunch, Giuseppe -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2009-Sep-26 14:28 UTC
[rspec-users] controller specs with non-RESTful routes
On Sat, Sep 26, 2009 at 8:10 AM, Giuseppe Bertini <lists at ruby-forum.com> wrote:>> Huh? Pretty please what? Matt and I have both responded. In my case I >> asked you about the versions you have. You didn''t quote any of the >> previous posts in this thread, so I have no idea what you''re asking >> for at this point. Did you receive our responses? > > So sorry, I must be missing something. > I am looking right now at this page: > > http://www.ruby-forum.com/topic/195172Well - that _should_ be one of two correct URLs. The forum is mirrored w/ a google group. I see there are posts missing from the forum, but I see all the posts in the google group: http://groups.google.com/group/rspec/browse_thread/thread/8c079724053b5ce7 We don''t offer much help, as Matt doesn''t see a problem and I can''t reproduce it - but at least we tried to play :)> > And what I see is my original post, my own "pretty please" and your > "Huh?", period. > > Looking at the index page (http://www.ruby-forum.com/forum/32) does not > help. > > I''m wondering--am I looking at the wrong forum page? But then, why do I > see your latest response (and received the email notification I > requested), but not the previous? > > Sorry for the trouble, I would appreciate if you could point me to the > proper URL, if this is the problem. > > Thanks a bunch, > Giuseppe > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
> > So sorry, I must be missing something. > > I am looking right now at this page: > > >http://www.ruby-forum.com/topic/195172 > > Well - that _should_ be one of two correct URLs. The forum is mirrored > w/ a google group. I see there are posts missing from the forum, but I > see all the posts in the google groupYes, now I see, thanks. So, back to the original issue, I have rails 2.3.4, rspec 1.2.8, rspec- rails 1.2.7.1, ruby 1.8.6 (universal darwin9.0) I too have created a new app with only the above-mentioned code added to the rails-generated and rspec-generated stuff. I am still getting the "No route matches..." error I have posted the app here: git://github.com/giuseb/spec_named_route.git I am somewhat nervous that this is going to turn out a silly mistake on my part as Matt suggested, but still... Giuseppe
On Sat, Sep 26, 2009 at 10:28 AM, David Chelimsky <dchelimsky at gmail.com> wrote:> > We don''t offer much help, as Matt doesn''t see a problem and I can''t > reproduce it - but at least we tried to play :)I''ll take a turn! Helps me procrastinate on my own stuff. >8-> Giuseppe: have you tried running ''rake routes'' to see what the application thinks you valid routes are? Reconciling that with what''s going on in routes.rb is a good next step. Also, when testing behavior has me stumped, I often remember far too late to open up my Web browser and poke at the pages directly, as a human being. I''ll often see error messages that way that RSpec doesn''t think to show me, or I can view source and see what the links in my form _really_ are. Those aren''t direct answers (I''m with Matt, I don''t see anything wrong here unless something else in routes.rb is conflicting with the line you posted) but they''ve been useful tactics for me in the past. -- Have Fun, ? Steve Eley (sfeley at gmail.com) ? ESCAPE POD - The Science Fiction Podcast Magazine ? http://www.escapepod.org
David Chelimsky
2009-Sep-26 15:00 UTC
[rspec-users] controller specs with non-RESTful routes
On Sat, Sep 26, 2009 at 9:44 AM, giuseb <giuseppe.bertini at gmail.com> wrote:>> > So sorry, I must be missing something. >> > I am looking right now at this page: >> >> >http://www.ruby-forum.com/topic/195172 >> >> Well - that _should_ be one of two correct URLs. The forum is mirrored >> w/ a google group. I see there are posts missing from the forum, but I >> see all the posts in the google group > > Yes, now I see, thanks. > So, back to the original issue, I have rails 2.3.4, rspec 1.2.8, rspec- > rails 1.2.7.1, ruby 1.8.6 (universal darwin9.0) > > I too have created a new app with only the above-mentioned code added > to the rails-generated and rspec-generated stuff. I am still getting > the "No route matches..." error > > I have posted the app here: > git://github.com/giuseb/spec_named_route.git > > I am somewhat nervous that this is going to turn out a silly mistake > on my part as Matt suggested, but still... > > GiuseppeThanks for posting the app - that was very helpful. I''ve got good news and bad news: The good news is that I hadn''t set up my routes as cleanly as yours, and when I did I was able to reproduce the error. The bad news is that this is a deficiency the underlying Rails testing framework that rspec-rails wraps. I tried the same example in a rails functional test and got the same failure: class InvitationsControllerTest < ActionController::TestCase test "the post accept invitation should be successful" do get :accept, :id => "1" assert_response :success end end test_the_post_accept_invitation_should_be_successful(InvitationsControllerTest): ActionController::RoutingError: No route matches {:action=>"accept", :controller=>"invitations", :id=>"1"} /test/functional/invitations_controller_test.rb:6:in `test_the_post_accept_invitation_should_be_successful'' You wanna raise a ticket in the rails lighthouse?
> The bad news is that this is a deficiency the underlying Rails testing > framework that rspec-rails wraps. I tried the same example in a rails > functional test and got the same failure: > > class InvitationsControllerTest < ActionController::TestCase > > ? test "the post accept invitation should be successful" do > ? ? get :accept, :id => "1" > ? ? assert_response :success > ? end > end > > test_the_post_accept_invitation_should_be_successful(InvitationsControllerTest): > ActionController::RoutingError: No route matches {:action=>"accept", > :controller=>"invitations", :id=>"1"} > ? ? /test/functional/invitations_controller_test.rb:6:in > `test_the_post_accept_invitation_should_be_successful'' > > You wanna raise a ticket in the rails lighthouse?I just did--my very first ticket!! Two more things: - I noticed that you tested a get request, while i was doing post. Tried them both again, same outcome. - what did your "unclean" routes look like that did NOT cause the problem? Thanks, Giuseppe
David Chelimsky
2009-Sep-26 17:41 UTC
[rspec-users] controller specs with non-RESTful routes
On Sat, Sep 26, 2009 at 11:49 AM, giuseb <giuseppe.bertini at gmail.com> wrote:>> The bad news is that this is a deficiency the underlying Rails testing >> framework that rspec-rails wraps. I tried the same example in a rails >> functional test and got the same failure: >> >> class InvitationsControllerTest < ActionController::TestCase >> >> ? test "the post accept invitation should be successful" do >> ? ? get :accept, :id => "1" >> ? ? assert_response :success >> ? end >> end >> >> test_the_post_accept_invitation_should_be_successful(InvitationsControllerTest): >> ActionController::RoutingError: No route matches {:action=>"accept", >> :controller=>"invitations", :id=>"1"} >> ? ? /test/functional/invitations_controller_test.rb:6:in >> `test_the_post_accept_invitation_should_be_successful'' >> >> You wanna raise a ticket in the rails lighthouse? > > I just did--my very first ticket!! > > Two more things: > - I noticed that you tested a get request, while i was doing post.Oh yeah - I had tried both and copied the wrong one in the email :)> Tried them both again, same outcome. > - what did your "unclean" routes look like that did NOT cause the > problem?Just the defaults: map.connect '':controller/:action/:id'' HTH> > Thanks, > Giuseppe > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Steve,> Giuseppe: have you tried running ''rake routes'' to see what the > application thinks you valid routes are? ?Reconciling that with what''s > going on in routes.rb is a good next step.The following line is the whole of the ''rake routes'' output: accept_invitation /accept_invitation/:id {:action=>"accept", :method=>"get", :controller=>"invitations"}> Also, when testing behavior has me stumped, I often remember far too > late to open up my Web browser and poke at the pages directly, as a > human being.I did visit: http://localhost:3000/accept_invitation/1 and the request gets properly routed by the app. As David pointed out earlier today, this behavior appears to be related to rails'' testing framework, rather than to rspec. I have raised a ticket in the rails lighthouse: https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/3263-failing-functional-test-of-a-named-route Cheers, Giuseppe