多租户和rspec
我仍然很熟悉w/RSpec,在为我的多租户应用程序设置测试时遇到了一些问题 该应用程序在以下位置工作: client1.example.com client2.example.com 等等 在我的RSpec中,我做了以下工作:多租户和rspec,rspec,factory-bot,multi-tenant,Rspec,Factory Bot,Multi Tenant,我仍然很熟悉w/RSpec,在为我的多租户应用程序设置测试时遇到了一些问题 该应用程序在以下位置工作: client1.example.com client2.example.com 等等 在我的RSpec中,我做了以下工作: let(:tenant) { FactoryGirl.create(:tenant, subdomain: "client1") } let(:root_path) { "http://client1.example.dev:3000" } before { ten
let(:tenant) { FactoryGirl.create(:tenant, subdomain: "client1") }
let(:root_path) { "http://client1.example.dev:3000" }
before {
tenant.save
visit root_path
}
describe "header" do
it "should have the right title" do
page.should have_selector('title', :text => tenant.name)
end
end
我在这里做了一些感觉不对的事情,但不确定最好的方法是什么
visit'/'
这样的操作不起作用,因为测试不知道正确的子域是什么。这样行吗找不到subdomain=client1的租户的错误。我以为FactoryGirl.create真的保存到数据库了
谢谢你的帮助 1:似乎这是必要的,我认为没有办法只指定子域 2:是,
create
保存到数据库中(而build
不保存)。然而,RSpec的let
是惰性的——它只在第一次调用时进行计算
这意味着如果没有tenant.save
,则在page.should\u selector('title',:text=>tenant.name)
发生之前不会创建租户-在visit
调用之后,为时已晚
幸运的是,RSpec还提供了let
是一个急切版本的let
,因此如果您使用它,您将不需要租户。请在之前的块中保存