1

So, I'm trying to do some unit tests, and my current_account_permissions variable is undefined when running the tests. (works 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?

Benoit Garret
  • 14,027
  • 4
  • 59
  • 64
NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352
  • 1
    Where is `current_account_permissions` defined? Define `global` :) I guess it means it is known in all controllers? – nathanvda Sep 28 '11 at 14:37
  • seconding what @nathanvda said, which means that the global variable is most likely **not** the correct solution. – Benoit Garret Sep 28 '11 at 14:38
  • consider http://stackoverflow.com/questions/3598785/where-to-put-global-variables-in-rails-3 – jaydel Sep 28 '11 at 14:40
  • @nathanvda yeah, it's availabel in all the controllers / helpers / views. I'ts defined in lib somewhere where current_user and current_account are defined. – NullVoxPopuli Sep 28 '11 at 14:44

1 Answers1

1

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.

nathanvda
  • 49,707
  • 13
  • 117
  • 139