【发布时间】:2021-07-09 03:17:37
【问题描述】:
我正在将 RoR 应用程序从 4.0 升级到 4.2。 在 4.0 中,我们有 url_helpers,它添加了额外的 url_helpers,如下所示:
module UrlHelper
def subscribe_url (tenant)
url_options = {
:controller => "users/subscription",
:action => "new",
:only_path => false,
:subdomain => tenant.sitename
}
url_for url_options
end
end
那么我们的 base_controller 将只包含它们:
class BaseController < ActionController::Base
# Gives us access to custom resource paths and overrides url_for
# to provide support for multitenancy.
include UrlHelper
但是,在更新到 Rails 4.2.11.3 后,它停止了工作。 我们的测试似乎无法再访问 subscribe_url,即使它包含在 base_controller 中。
expect(response).to redirect_to subscribe_url(tenant: tenant)
失败:
undefined method `login_url' for #<RSpec::ExampleGroups::UsersRegistrationsController
有没有其他方法可以将 url_helpers 添加到 rspec 测试?
很遗憾,不能使用 direct 路由,因为它还不是 Rails 5。
【问题讨论】:
-
附带说明 - 切勿在 ruby 中的方法名称和父项之间添加空格。由于父母是可选的,它被视为
def subscribe_url((tenant)),添加任何额外的参数都会导致语法错误,因为它实际上不是一个列表。
标签: ruby-on-rails ruby ruby-on-rails-4