test edit changing value

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?

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.

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@AgileConsultingLLC.com