Forum: Ruby on Rails Question about testing

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
zero0x (Guest)
on 2009-02-04 17:07
(Received via mailing list)

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?
Brian H. (Guest)
on 2009-02-04 17:27
(Received via mailing list)

Fixtures are fixed.

Do this:

original_homework = homeworks(:one)
xhr :get, :status, :id =>, :status => "done"

changed_homework = assigns(:homework)  # get it from the controller's

# 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


test "it should show an error message when not created successfully" do


zero0x (Guest)
on 2009-02-04 17:30
(Received via mailing list)

OK I see,

I wanted something like

should be done after setting it done

But I see that's enough by checking assigns.
This topic is locked and can not be replied to.