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 Any thoughts? Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/11/06, Mike <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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].sizePerhaps... assigns(:things).size -- James --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hey Alex. 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 Wayne 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.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Mike wrote:> > Hey Alex. > > 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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Alex Wayne wrote:> Mike wrote: >> >> Hey Alex. >> >> 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: assert_not_nil assigns(''products'') #works assert_not_nil assigns(:products) #works assert_not_nil assigns[''products''] #works assert_not_nil assigns[:products] #fails so as long you dont do assigns[:things] you should be fine. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Oct 11, 2006, at 11:19 AM, Alex Wayne wrote:> Alex Wayne wrote: >> Mike wrote: >>> 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. >> 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: > > assert_not_nil assigns(''products'') #works > assert_not_nil assigns(:products) #works > assert_not_nil assigns[''products''] #works > > assert_not_nil assigns[:products] #fails > > so as long you dont do assigns[:things] you should be fine.Test::Rails in ZenTest fixes this. You also get an extra method you can drop in #teardown to verify you''ve asserted all of your assigns. -- Eric Hodel - drbrain-48TerJ1FxhPk1uMJSBkQmQ@public.gmane.org - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---