Rails rspec 设置子域 [英] Rails rspec set subdomain

查看:51
本文介绍了Rails rspec 设置子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 rSpec 来测试我的应用程序.在我的应用程序控制器中,我有一个像这样的方法:

I am using rSpec for testing my application. In my application controller I have a method like so:

def set_current_account
  @current_account ||= Account.find_by_subdomain(request.subdomains.first)
end

是否可以在我的规范中设置 request.subdomain?也许在前块?我是 rSpec 的新手,因此非常感谢您就此提出任何建议.

Is it possible to set the request.subdomain in my spec? Maybe in the before block? I am new to rSpec so any advice on this would be great thanks.

伊夫

推荐答案

我想出了如何解决这个问题.

I figured out how to sort this issue.

在我的规范中的 before 块中,我简单地添加了:

In my before block in my specs I simply added:

before(:each) do
  @request.host = "#{mock_subdomain}.example.com"
end

这会将 request.subdomains.first 设置为 mock_subdomain 的值.

This setups up the request.subdomains.first to be the value of the mock_subdomain.

希望有人觉得这很有用,因为它在网络上的其他任何地方都没有得到很好的解释.

Hope someone finds this useful as its not explained very well anywhere else on the net.

这篇关于Rails rspec 设置子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆