On Feb 14, 2007, at 10:44 AM, Larry Kelly wrote:> My question today is:
>
> How do I write function test to simulate the user changing a value  
> in an edit form?  Say, I have a form with a lookup to tech_id.   
> When the user selects a different tech_id, I want to verify that  
> other fields have also changed ie( tech_name, tech_pay_rate, etc).   
> This is what I have so far:
>
>
> def test_changing_technician_id
>     get :edit, :id => 1
>     assert_response :success
>     assert_template ''edit''
>     assert_not_nil assigns(:work_order_labor)
>     assert assigns(:work_order_labor).valid?  # but how do I access  
> the :work_order_labor object?
Actually, you just did!  If you want to keep it around, try changing  
the line above to:
     assert (work_order_labor = assigns(:work_order_labor)).valid?
(note the space after assert is important unless you put in the  
parentheses for the assert((wor...).valid?)
>    # verify that we have the correct name the technician id
>    # this line doesn''t work
>     assert_equal ''Alfred'',
work_order_labor.technician_name
>
>     # change technician id to 2
>
>    post  :update,
>
>     work_order_labor = WorkOrderLabor.find_by_id(1)
>
>     # verify that the technician_name is now '' Betty''
>     assert_equal ''Betty'',  
work_order_labor.technician_name
> end
>
> Any help would be greatly appreciated.
> -- 
> Best Regards,
> -Larry
> "Work, work, work...there is no satisfactory alternative."
>             --- E.Taft Benson
I''d suggest that you test what the UI actually presents.  Does the  
user select a technician id or a name?  You say to change the id, but  
then you check for a name change.
-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
-~----------~----~----~----~------~----~------~--~---