Test Design Question #1

I have an model in rails with an after_create that generates another
object (for the purpose of making an audit trail).

In the unit test - i want to verify this behavior.

This behaviour - in other tests is breaking some exceptions around
(include) - since the creation of the new audit trail
is leaking into this other unit test.

In the controller test this behavior doesn’t matter - in the
integration test i do want this behavior.

What am i doing wrong here?


make haste slowly
festina lente \

mobile +1_415_632_6001
[email protected]
http://robotarmyma.de

What do you mean that it’s “leaking” into the other test? If you have
transactions turned on, then any records inserted into the db will be
removed for the next test.

My guess is that other tests just don’t set up the required data…which
is a problem with ActiveRecord callbacks and observers. In that case,
you’ll want to use a test data builder like fixjour or Factory Girl, so
you only have to set up the data in one place. Another approach is to
move your after_create code into an observer and use my no_peeping_toms
gem which disables observers in tests (and makes you explicitly enable
them, either all of them or individually). This way you can test your
callbacks in the unit tests for that behavior, and disable them
everywhere else.

Cheers brother,
Pat

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs