如何在test :: unit中指定控制器名称

时间:2014-01-24 12:26:06

标签: ruby-on-rails testunit

我的品牌控制器位于app/controllers/merchant/brands_controller.rb

我正在尝试为它编写功能测试。我已将测试类定义为

require 'test_helper'

class Merchant::BrandsControllerTest < ActionController::TestCase
include Devise::TestHelpers

setup do
    @user = users(:one)
    sign_in @user
    @brand= brands(:one)
end

test "should get index" do
    get :index
    assert_response :success
end
end

但是测试会抛出错误

ActionController::RoutingError: No route matches {:controller=>"merchant/brands", :action=>"new"}

为什么使用'商家/品牌'作为控制器名称? 或者我可以指定自定义路由来请求“新”方法吗?

我的路线看起来像这样

namespace :merchant do
  resources :accounts do
    resources :brands
  end
end  

1 个答案:

答案 0 :(得分:0)

您似乎忘记了路线的帐户部分。

尝试

class Merchant::Accounts::BrandsControllerTest
相关问题