Rails:如何使用作用域定义的路径测试控制器?

问题描述 投票:2回答:2

鉴于路线:

  scope :path => 'shipping_reports', :controller => 'ShippingReports', :as => 'shipping_reports' do
    get 'index'
  end

以及以下测试:

class ShippingReportsControllerTest < ActionController::TestCase
 test "routing" do
    assert_routing '/shipping_reports/index', { :controller => "ShippingReports", :action => "index" }
  end

  test 'index' do
    get :index
    assert_response :success
 end
end

第一次测试通过,第二次测试通过:

ActionController::RoutingError: No route matches {:controller=>"shipping_reports"}

有人知道如何让测试通过吗?

ruby-on-rails routes functional-testing
2个回答
0
投票

我设法完成这项工作的唯一方法是将我的路线更改为:

controller 'shipping_reports', :path => '/shipping_reports', :as => 'shipping_reports'

它看起来更好,测试通过但我仍然想知道如何测试问题路线......


0
投票

有一个非常相似的问题。

鉴于路线:

  scope ":client" do
    resources :categories, as: :client_categories
  end

我必须做以下事情:

test '#update' do
  put :update, { params: { id: cat.id, client: client } } # => error
  put :update, { params: { id: cat.id, } }, { client: client } # => OK
end
© www.soinside.com 2019 - 2024. All rights reserved.