Hi all. I’m using the ApplicationController to set a session variable
for all other controllers. It works.
However, when performing functional tests, it appears that calling a
controller doesn’t invoke its parent’s before_filter method.
I’ve tried, in my tests, calling ApplicationController’s methods
directly, but I either get weird errors (e.g. “using a symbol as an
array index session[:cart]”) or the variable assignments (session,
instance, whatever) don’t propagate to children controllers.
I can test my actual ApplicationController for correctness, but unless I
tell it to render(:nothing => true) (a big no-no if you use your
imagination) or put in an actual view for it to render I get an error
during testing saying it couldn’t render anything. I’d rather not have
random views (okay, 1 random view, but still) floating around just to
get a test to work.
It also seems, at least in the testing environment, that a controller
outside the one being tested does not have access to the session method.
A exception is raised stating I’m attempting to issue [] on nil. The
only occurences of [] are attached to session.
However this just gives an error saying that the @request object
wasn’t
initialised and so the call is interpreted as nil.session
Have you got
def setup
@controller = <controller_name>Controller.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
in your functional test? it should be generated by rails.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.