views:

122

answers:

1

I have an application_controller spec that is failing since I removed the controller/action route from routes.rb. I get the following error:

No route matches {:controller=>"application", :action=>"index"}

I had many tests fail in the same way, but was able to fix them by including the correct parameters in the get call. So for instance, if I wanted to get the standard show route for posts in my spec, I had to change

get :show to get :show, :id => '1'

Unfortunately, I'm not sure now what to pass along for the application controller specs. I've included my test below.

describe ApplicationController do

  it "should find the latest published posts and assign them for the view" do
    Post.should_receive(:latest).and_return(@posts)
    get :index
    assigns[:posts].should == @posts
  end


  it "should find the latest approved comments and assign them for the view" do
    Comment.should_receive(:latest).and_return(@comments)
    get :index
    assigns[:comments].should == @comments
  end

end
A: 

Consider the ApplicationController as an abstract class not intended to be used for requests. All new controllers generated will inherit from ApplicationController so it is a nice place to put shared behavior.

Karmen Blake