rtacconi
2010-Aug-04 11:53 UTC
How to inject a value in params when testing a helper method
I what to try this method in a helper class: def moderator_buttons? return true if params[:question_status] == ''HOST_INBOX'' return true if params[:question_status] == ''HOST_INBOX_READ'' return true if params[:question_status] == ''DELETED'' return true if params[:question_status] == ''LATER'' return true if params[:question_status] == ''MODERATOR_TO_APPROVE'' false end How can I assign ''HOST_INBOX'' string to params[:question_status] before assert true, moderator_buttons? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Aug-04 15:09 UTC
Re: How to inject a value in params when testing a helper method
Riccardo Tacconi wrote:> I what to try this method in a helper class: > > def moderator_buttons? > return true if params[:question_status] == ''HOST_INBOX'' > return true if params[:question_status] == ''HOST_INBOX_READ'' > return true if params[:question_status] == ''DELETED'' > return true if params[:question_status] == ''LATER'' > return true if params[:question_status] == ''MODERATOR_TO_APPROVE'' > > false > endNo you don''t. Your helpers don''t have access to params, since they live in the view layer. You''ll need to pass params[:question_status] in as an @instance variable. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Aug-04 15:27 UTC
Re: How to inject a value in params when testing a helper method
On Aug 4, 4:09 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> No you don''t. Your helpers don''t have access to params, since they live > in the view layer. You''ll need to pass params[:question_status] in as > an @instance variable.They do - ActionView::Base delegates the params method (among others) to the controller Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Aug-04 16:07 UTC
Re: How to inject a value in params when testing a helper method
Frederick Cheung wrote:> On Aug 4, 4:09�pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> No you don''t. �Your helpers don''t have access to params, since they live >> in the view layer. �You''ll need to pass params[:question_status] in as >> an @instance variable. > > They do - ActionView::Base delegates the params method (among others) > to the controllerOK, then I''m sorry for the error. I still can''t see why it''s ever a good idea to touch the params array in the view... ...though I suppose you could make the argument that the controller shouldn''t have to know it needs to set @question_status.> > FredBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.