Hi, I have a question about testing ... It's controller test ... First I do something like this: xhr :get, :status, :id => homeworks(:one).id, :status => "done" The :status action sets homework's length_done to length. So I do this: assert = homeworks(:one).length == homeworks(:one).length_done But this test doesn't pass, while this one: assert assigns(:homework).length == assigns(:homework).length_done Passes. Why? If I do request - doesn't the object from fixtures get updated?
on 2009-02-04 17:07
on 2009-02-04 17:27
No. Fixtures are fixed. Do this: original_homework = homeworks(:one) xhr :get, :status, :id => original_homework.id, :status => "done" changed_homework = assigns(:homework) # get it from the controller's instance # now compare original_homework and changed_homework. I don't know what you're really trying to test here, but this sounds like business logic. The controller should pass parameters to a fully-tested model so your controller tests really should be testing for how the controller handles "it worked" vs "it didn't work". The details of what gets set should be covered in a unit test. test "it should show a success message when created successfully do end test "it should show an error message when not created successfully" do end HTH -Brian
on 2009-02-04 17:30
Thanks, OK I see, I wanted something like should be done after setting it done But I see that's enough by checking assigns.