【问题标题】:ActionController::UrlGenerationError in rspecrspec 中的 ActionController::UrlGenerationError
【发布时间】:2019-11-29 06:29:07
【问题描述】:

在测试我的控制器操作时,我收到此路由错误。我无法弄清楚我做错了什么

路线

 get ':user_type', to: 'user_posts#index', param: :user_type, constraints: lambda { |req| ['abc', 'def'].include?(req.params["user_type"]) }, as: :custom_posts


规格:

  describe "GET #index: enabled" do
    it "returns http success" do
      get :index, params: {user_type: 'abc'}
      expect(response).to have_http_status(:success)
    end
  end

错误:

ActionController::UrlGenerationError:
       No route matches {:action=>"index", :controller=>"user_posts"}

另外,我通过更改路线在github 上尝试了一种解决方案,但它对我不起作用

get ':user_type', to: 'user_posts#index', param: :user_type, constraints: {user_type: lambda { |req| ['abc', 'def'].include?(req.params["user_type"]) } }, as: :custom_posts

【问题讨论】:

    标签: ruby-on-rails ruby rspec routing ruby-on-rails-5.2


    【解决方案1】:

    终于,我得到了答案。这是详细信息discussion

    describe "GET #index: enabled" do
        it "returns http success" do
          get :index, params: { user_type: 'abc', param: :user_type }     
          expect(response).to have_http_status(:success)
        end
      end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-25
      • 1970-01-01
      相关资源
      最近更新 更多