Forum: Ruby on Rails Question about testing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
79ad5a1770c5cf086735a10ef7db6598?d=identicon&s=25 zero0x (Guest)
on 2009-02-04 16:07
(Received via mailing list)
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?
6ef8cb7cd7cd58077f0b57e4fa49a969?d=identicon&s=25 Brian Hogan (Guest)
on 2009-02-04 16:27
(Received via mailing list)
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
79ad5a1770c5cf086735a10ef7db6598?d=identicon&s=25 zero0x (Guest)
on 2009-02-04 16:30
(Received via mailing list)
Thanks,

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.