【问题标题】:rails rspec controller test ActionController::RoutingErrorrails rspec 控制器测试 ActionController::RoutingError
【发布时间】:2011-09-24 18:52:26
【问题描述】:

我的路线是这样的

  resources :stores, :except => [:destroy] do
    resources :toys, :member => {:destroy => :delete}
  end

我的对象控制器规范如下所示

require 'spec_helper'

describe ToysController do

    describe "GET index" do
        it "assigns all toys as @toys" do
          toy11 = Factory(:toy, :is_shiny => true)
          toy12 = Factory(:toy,:is_shiny => false)
          get :index
          assigns(:toys).should eq([toy12,toy11 ])
        end
      end
    end
end

我收到以下错误

 Failure/Error: get :index
 ActionController::RoutingError:
 No route matches {:controller=>"toys"}

由于玩具资源嵌套在商店资源下,它无法获取 Toys_path 路径,所以我认为规范失败了。

如何通过规范?

谢谢

【问题讨论】:

    标签: testing rspec controller nested-routes


    【解决方案1】:

    错误是由于未将 store_id 发送到 tyos 索引。 如果我发送了

    :store_id => @store.id in get :index
    

    它会过去的。

    【讨论】:

      猜你喜欢
      • 2023-03-16
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多