I’m having a super strange functional testing issue, and was hoping
someone could provide some insight.
In my controller I have this in the index action:
@things = Thing.find(:all)
My index test looks like this:
get :index
assert_response :success
assert_equal 1, assigns[:things].size
But the second assert causes an error. assigns[:things] is always nil
even though @things is getting assigned in the controller. If I do this
in the same test:
assert_equal 1, Thing.find(:all).size
It works. I have a reference to the things fixture in the test, so the
one record should be in the test db, and the manual find proves that.
I’m not sure why my instance var is always nil though
I’m having a super strange functional testing issue, and was hoping
someone could provide some insight.
In my controller I have this in the index action:
@things = Thing.find(:all)
My index test looks like this:
get :index
assert_response :success
assert_equal 1, assigns[:things].size
But the second assert causes an error. assigns[:things] is always nil
even though @things is getting assigned in the controller. If I do this
in the same test:
Try assigns(:things), with () instead of [].
Due to some oddness with backwards compatibility or something like that
the assigns object does not support the bracketed hash style notation.
Although the brackets still work for params and session.
Thanks for the reply. I actually tried with the parens instead, it does
the same thing. Also, I use the brackets for assigns elsewhere without
an issue.
Hmm…
Alex W. wrote:
Mike wrote:
I’m having a super strange functional testing issue, and was hoping
someone could provide some insight.
In my controller I have this in the index action:
@things = Thing.find(:all)
My index test looks like this:
get :index
assert_response :success
assert_equal 1, assigns[:things].size
But the second assert causes an error. assigns[:things] is always nil
even though @things is getting assigned in the controller. If I do this
in the same test:
Try assigns(:things), with () instead of [].
Due to some oddness with backwards compatibility or something like that
the assigns object does not support the bracketed hash style notation.
Although the brackets still work for params and session.
Thanks for the reply. I actually tried with the parens instead, it does
the same thing. Also, I use the brackets for assigns elsewhere without
an issue.
Hmm…
Apparently my info is out of date!
This won’t fix it, but it should give you some more info.
get :index
raise assigns.inspect
This will create an error and then dump the content of “assigns”. Does
it actually have the data in it?
And just to clarify, it seems [] and () are treated differently after
all. In my tests, running on edge:
Thanks for the reply. I actually tried with the parens instead, it does
the same thing. Also, I use the brackets for assigns elsewhere without
an issue.
Hmm…
Apparently my info is out of date!
This won’t fix it, but it should give you some more info.
get :index
raise assigns.inspect
This will create an error and then dump the content of “assigns”. Does
it actually have the data in it?