开发者

No route matches error with application_controller spec

I have an applicati开发者_运维技巧on_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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜