I have a functional test and am trying to set a session value ..... def test_should_check_number_of_jobs session[:employee_id] = 1 #@fred.id post :index assert_equal 1, assigns(:jobs).size end .... when I try to run this test I get the following error TypeError: Symbol as array index job_controller_test.rb:29in ''[]='' job_controller_test.rb:29in ''test_should_check_number_of_jobs'' if I hard code the employee_id in the controller and remove the session call in the test, it works perfectly. http://zentest.rubyforge.org/ZenTest/classes/Test/Rails.html seems to be doing the same thing as me about 1/2 way down the page, so it doesn''t seem too unreasonable. Anyone know why this isn''t working? -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2008-Mar-12 19:36 UTC
Re: controller test - setting session values not working
On Mar 12, 2008, at 3:22 PM, Bob Br wrote:> I have a functional test and am trying to set a session value > > ..... > def test_should_check_number_of_jobs > session[:employee_id] = 1 #@fred.id@request.session[:employee_id] = 1> > post :index > assert_equal 1, assigns(:jobs).size > end > .... > > when I try to run this test I get the following error > TypeError: Symbol as array index > job_controller_test.rb:29in ''[]='' > job_controller_test.rb:29in ''test_should_check_number_of_jobs'' > > > if I hard code the employee_id in the controller and remove the > session > call in the test, it works perfectly. > > http://zentest.rubyforge.org/ZenTest/classes/Test/Rails.html > seems to be doing the same thing as me about 1/2 way down the page, so > it doesn''t seem too unreasonable. Anyone know why this isn''t working?The request/controller/response is meant to be a sufficient stand-in for the real things, but remember that you''re not running in the context of the controller where the session method would normally be found. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
You guys rock! Thanks for the help -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Thats what Rob was talking about, you need to add @request, so you wind up with @request.session[:employee_id] = 1 I usually initalize a bunch of this stuff in the setup function, and then later on accessing it is like normal without the @request. Hope this helps, let me know if you need anything else. Bob Vaibhav wrote:> Hey Bob, > > I am a Rails newbie and facing a stupid error. Thought you could help. > > I am testing a functionality and want a value to persist. I open my > application.rb and try to store the value as: session[:business_id] > 1. When I access my application, I get an error: Symbol as array index > > Any idea why? > > Thanks in advance, > --Vaibhav-- 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?hl=en -~----------~----~----~----~------~----~------~--~---