【问题标题】:No route matches error with application_controller spec没有路由匹配错误与 application_controller 规范
【发布时间】:2009-10-23 05:51:48
【问题描述】:

我有一个 application_controller 规范失败,因为我从 routes.rb 中删除了控制器/操作路由。我收到以下错误:

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

我有许多测试以同样的方式失败,但能够通过在 get 调用中包含正确的参数来修复它们。因此,例如,如果我想获得规范中帖子的标准显示路线,我必须进行更改

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

不幸的是,我现在不确定应该为应用程序控制器规范传递什么。我在下面包含了我的测试。

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

【问题讨论】:

    标签: ruby-on-rails rspec


    【解决方案1】:

    将 ApplicationController 视为不打算用于请求的抽象类。生成的所有新控制器都将继承自 ApplicationController,因此它是放置共享行为的好地方。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-27
      相关资源
      最近更新 更多