【问题标题】:testing router gets confused in two controllers with same name测试路由器在两个具有相同名称的控制器中混淆
【发布时间】:2020-01-08 16:08:44
【问题描述】:

有两个同名的控制器,一个在根模块中,另一个在文件夹/差异模块中。每个控制器的功能测试都独立运行。但是在一个套件中,他们在路由错误中失败了。 如何解决这个问题?

namespace :plan do
    resources :apps, :controller => 'proposals', :as => 'proposals', :path => 'proposals' do
    member do
        ...
    end
    # /app/controllers/plan/qandas_controller
    resources :qandas do
        collection do
        get 'post_new'
        post 'post'
        post 'reply'
        end
        member do
        get 'reply_new'
        post 'post'
        post 'reply'
        get 'edit'
        patch 'update'
        delete 'destroy'
        end
    end
end
resources :apps do
    member do
        ...
    end
    # /app/controllers/qandas_controller
    resources :qandas do
    collection do
        get 'post_new'
        post 'post'
        post 'reply'
    end
    member do
        get 'reply_new'
        post 'post'
        post 'reply'
        get 'edit'
        put 'update'
        delete 'destroy'
    end
end

【问题讨论】:

  • 能否请您从您的路线文件中发布代码示例?

标签: ruby-on-rails unit-testing routing ruby-on-rails-5


【解决方案1】:

在您的测试单元中创建文件夹根目录和文件夹差异。

【讨论】:

  • 我已经拥有与控制器相同路径模式的测试单元。
猜你喜欢
  • 2014-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-01
  • 1970-01-01
  • 2015-03-12
  • 2022-01-14
相关资源
最近更新 更多