Blank Pad Development

A photo of Jon

Hello There

I’m Jon, a web developer working for Hubbub to make it easier for people to buy great food from their local shops.

This is where I occassionally write about what I'm doing, and make a note of anything I'm likely to want to Google in the future!

No route matches

I keep getting the error “No route matches { :controller => "whatever”, :action => “whatever” }“ when testing Rails applications with RSpec. Everytime I do, I spend a while tracking it down. This time I decided to document what I did, so I can get on with life.

Turns out it’s because it was a nested resource, and I hadn’t passed the parent ID. Instead of this:

describe ContactUserController do
  context "when not logged in" do
    before(:each) { get :show }
    it_should_behave_like "an unauthenticated action"
  end
end

I needed:

describe ContactUserController do
  context "when not logged in" do
    before(:each) { get :show, :user_id => "ExampleUser" }
    it_should_behave_like "an unauthenticated action"
  end
end

And now it works. Slightly embarrasing, but hopefully it’ll help someone. Maybe even me when my short term memory causes me to forget it again.

blog comments powered by Disqus