开发者

How do you add a variable to the global scope? (ruby on rails)

So, I'm trying to do some unit tests, and my current_account_permissions variable is undefined when running the tests. (work开发者_StackOverflows fine when the server is running).

It's similar to current_user in that it's available everywhere, except tests apparently.

Is there a way I can add the variable to the global scope?

Maybe something like ENV["current_account_permissions"] = whatever but not having to use the ENV[] notation to retrieve the variable?


I am assuming here, but without any code it is hard to tell, that somehow the current_account_permissions is mixed in into the ApplicationController.

I would also assume that the current_account_permissions is a method, which should do something like

def current_account_permissions
  @current_account_permissions ||= current_user.get_current_account_permissions
end

So if that is the case, all your controller tests would run fine as dandy. In your view tests however, you will have to stub the current_account_permissions because when testing there is no controller context.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜