Rails 3 - 如何摆脱“test.host”?

发布于 2024-11-16 07:52:30 字数 419 浏览 3 评论 0原文

我最近安装了一个名为 Gretel 的插件来为我处理面包屑。它似乎工作得很好,除了它似乎违反了我的一些规范并出现以下错误:

 Failure/Error: response.should redirect_to @course
 Expected response to be a redirect to </courses/904> but was a redirect to
 <http://test.host/courses/904>

我能做什么来摆脱这个错误?路径似乎完全正确,但有例外那个讨厌的 test.host 的事情。

I recently installed a plugin called Gretel to take care of breadcrumbs for me. It seems to be working great, except that it appears to be breaking some of my specs with the following error:

 Failure/Error: response.should redirect_to @course
 Expected response to be a redirect to </courses/904> but was a redirect to
 <http://test.host/courses/904>

What can I do to get rid of this error? The path seems totally correct, with the exception of that pesky test.host thing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千柳 2024-11-23 07:52:30

您可能正在针对 my_model_url 而不是 my_model_path 进行测试。

前者执行完整的 URI - 包括主机。后者是没有宿主的相对路径。

去检查你的控制器,看看它是否使用 _path 或 _url - 并在你的测试用例中使用相同的。

You are probably testing against my_model_url instead of my_model_path

The former does a full URI - including the host. The latter is a relative path without the host.

Go have a check in your controller and see if it uses _path or _url - and use the same one in your test-cases.

情归归情 2024-11-23 07:52:30

您需要明确定义您的请求主体..这里我有使用rails 3.0的应用程序...我正在使用Devise进行身份验证..并且我得到了用户指定的自定义域。

#get user from fixtures OR create them

  @user = users(:user1)

  #used devise "sign_in for testing"

    sign_in :user, @user  
  #defined my request

   request.host = 'myblog.free-blog.com'

  #get 'show_blog"

  get 'show'

You need to expliclty define your request body..Here i have Application that uses rails 3.0...i am using Devise for authentication..and i get a customised domain that user specifies.

#get user from fixtures OR create them

  @user = users(:user1)

  #used devise "sign_in for testing"

    sign_in :user, @user  
  #defined my request

   request.host = 'myblog.free-blog.com'

  #get 'show_blog"

  get 'show'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文