首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >子域失败的ActionDispatch::IntegrationTest

子域失败的ActionDispatch::IntegrationTest
EN

Stack Overflow用户
提问于 2019-07-02 21:31:46
回答 1查看 168关注 0票数 0

我不知道我做错了什么,真的需要一些帮助。我正在尝试写一个简单的IntegrationTest为一个多租户网站,其中每个帐户都有自己的子域。

但是,在运行测试时,我按照here的说明更改了IntegrationTest中的主机

代码语言:javascript
复制
Minitest::Assertion: Expected response to be a redirect to <http://subdomain1.example.com:3000/login> but was a redirect to <http://www.example.com:3000/>.
Expected "http://subdomain1.example.com:3000/login" to be === "http://www.example.com:3000/".
test/integration/feedback_flow_test.rb:8:in `block in <class:FeedbackFlowTest>'
Finished in 0.26594s
1 tests, 2 assertions, 1 failures, 0 errors, 0 skips

我编辑了我的主机文件,以便让subdomain1.example.comwww.example.com指向127.0.0.1。为了让它工作,我还需要做些什么吗?下面是IntegrationTest的代码

代码语言:javascript
复制
require 'test_helper'

class FeedbackFlowTest < ActionDispatch::IntegrationTest

  test "no token should go to the login page" do
    host! 'subdomain1.example.com:3000'
    get feedback_path
    assert_redirected_to login_url
    follow_redirect!
    assert_select '.alert-danger h3', 'You are not authorized '
  end
end
EN

回答 1

Stack Overflow用户

发布于 2019-07-02 22:08:46

抱歉,各位。已通过查看test.log找到问题。似乎我忘了为accounts模型创建一个fixture。因此,当测试运行时没有创建帐户,从而导致错误。我总是在我的test_helper.rb文件中执行fixtures :all,以便它加载所有用于测试的fixture。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56853674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档