gpt4 book ai didi

ruby-on-rails - 使用 rspec 测试具有子域约束的​​路由

转载 作者:数据小太阳 更新时间:2023-10-29 06:47:41 24 4
gpt4 key购买 nike

我在使用子域约束进行 rspec 路由测试时遇到问题。

特别是我有一条路线

constraints :subdomain => "api" do
resources :sign_ups, :only => [:create]
end

和(除其他外)测试

it "does allow creation of sign ups" do
{:post => "/sign_ups"}.should route_to(
:controller => "sign_ups",
:action => "create",
)
end

如果我删除子域约束,则此测试通过,但它会失败。我必须告诉 rspec 使用子域,但我不知道如何使用

TIA

安迪

最佳答案

我通常这样做:

let(:url)     { "http://api.domain.com"     }
let(:bad_url) { "http://bad_url.domain.com" }

it "does allow creation of sign ups" do
{:post => "#{url}/sign_ups"}.should route_to(
:controller => "sign_ups",
:action => "create",
)
end

it "should not route" do
{:post => "#{bad_url}/sign_ups"}.should_not route_to(
:controller => "sign_ups",
:action => "create",
)
end

关于ruby-on-rails - 使用 rspec 测试具有子域约束的​​路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9329669/

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