问题描述
我在我的项目中添加了公寓宝石,并且在我的开发中一切正常,而且我没有任何问题。
现在,我想用租户子域更新RSpec测试。
我补充说:
Apartment::Elevators::Subdomain.excluded_subdomains = ['www']
另外,对于RSpec,我添加了:
RSpec.configure do |config|
config.before(:suite) do
# Clean all tables to start
DatabaseCleaner.clean_with :truncation
# Use transactions for tests
DatabaseCleaner.strategy = :transaction
# Truncating doesn't drop schemas,ensure we're clean here,app *may not* exist
Apartment::Tenant.drop('test_app') rescue nil
# Create the default tenant for our tests
Apartment::Tenant.create('test_app')
end
config.before(:each) do
# Start transaction for this test
DatabaseCleaner.start
# Switch into the default tenant
Apartment::Tenant.switch! 'test_app'
end
config.after(:each) do
# Reset tentant back to `public`
Apartment::Tenant.reset
# Rollback transaction
DatabaseCleaner.clean
end
end
我的测试是:
RSpec.describe Api::V1::AccountsController,type: :request do
describe '.create' do
context 'valid requests' do
it 'creates accounts' do
# Require data
user = create(:user)
project = create(:project,user: user)
attributes = {
account: FactoryBot.attributes_for(:account_params),}
# Request
sign_in(user)
post "/en/api/v1/projects/#{project.id}/accounts",headers: auth_header,params: attributes
# Expects
# MY TESTS ARE HERE
end
end
end
end
现在,我没有默认的任何子域,因此,如果我像这样host! "test_app.example.com"
更新主机并按以下方式调用我的API:
post "/en/api/v1/projects/#{project.id}/accounts"
我收到此错误*** URI::InvalidURIError Exception: the scheme http does not accept registry part: test_app.example.com (or bad hostname?)
并且如果我这样发送请求:post "en/api/v1/projects/#{project.id}/accounts"
,我将收到此错误:*** URI::InvalidURIError Exception: bad URI(is not URI?): "http://test_app.example.com:80en/api/v1/projects/1/accounts"
有人知道我如何解决此问题并将请求发送到正确的子域吗? (此API在我的开发中效果很好)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)