gpt4 book ai didi

ruby-on-rails - 未定义的方法 relative_url_root 为 nil :NilClass when running rspec on namespaced controller

转载 作者:行者123 更新时间:2023-11-28 20:04:53 26 4
gpt4 key购买 nike

我正在将 Rails 2.3.18 升级到 3.2.x,我在这组 Controller 测试中遇到了问题:

错误:

/actionpack-3.2.12/lib/action_controller/test_case.rb:514:in `build_request_uri'
/actionpack-3.2.12/lib/action_controller/test_case.rb:470:in `process'
/actionpack-3.2.12/lib/action_controller/test_case.rb:49:in `process'
/actionpack-3.2.12/lib/action_controller/test_case.rb:390:in `get'
# ./spec/controllers/integrations/formstack_controller_spec.rb:104:in `block (3 levels) in <top (required)>'

代码触发错误:

it "should handle a failed access_token retreival" do
FormStack::Oauth2Connection.any_instance.stub(:identify).and_return(nil)
get "oauth_token" # this line <---------------------------------------------------------------- 104
response.should redirect_to(:controller => "/integrations/", :action => :index)
flash[:error].should include("error")
end

这个 Controller 的路由:

namespace :integrations, path: "/integrations" do
match "formstack/oauth_token", :to => "formstack#oauth_token"
resources :formstack
end

我的 Controller 没什么特别的:

class Integrations::FormstackController < ApplicationController
def oauth_token
...
end
end

这是关于什么的

get "any_action_in_this_controller"

导致此 relative_url_root 错误?针对此 Controller 的每个操作的每个测试都会引发错误。

我还能提供哪些其他信息来帮助你们帮助我调试它?

最佳答案

如@marcario 所述,如果您有:

    def config
end

在 Controller 中,你会得到这个(晦涩的)错误。只需将配置重命名为其他名称和匹配的路由映射即可。

关于ruby-on-rails - 未定义的方法 relative_url_root 为 nil :NilClass when running rspec on namespaced controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16444392/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com