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?

4
  • 1
    Where is current_account_permissions defined? Define global :) I guess it means it is known in all controllers? Commented Sep 28, 2011 at 14:37
  • seconding what @nathanvda said, which means that the global variable is most likely not the correct solution. Commented Sep 28, 2011 at 14:38
  • consider stackoverflow.com/questions/3598785/… Commented Sep 28, 2011 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. Commented Sep 28, 2011 at 14:44

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.