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

Pretty please? :slight_smile:

On Sat, Sep 26, 2009 at 1:56 AM, Giuseppe B. [email protected]
wrote:

Pretty please? :slight_smile:

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?

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

On Sat, Sep 26, 2009 at 8:10 AM, Giuseppe B. [email protected]
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/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:

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 :slight_smile:

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…

Giuseppe

On Sat, Sep 26, 2009 at 10:28 AM, David C. [email protected]
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 :slight_smile:

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 E. ([email protected])
ESCAPE POD - The Science Fiction Podcast Magazine
http://www.escapepod.org

On Sat, Sep 26, 2009 at 9:44 AM, giuseb [email protected]
wrote:

So, back to the original issue, I have rails 2.3.4, rspec 1.2.8, rspec-
on my part as Matt suggested, but still…

Giuseppe

Thanks 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?

On Sat, Sep 26, 2009 at 11:49 AM, giuseb [email protected]
wrote:

end

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 :slight_smile:

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

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

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