Behaviour on ActiveRecord in unit-tests


sadly I’ve some trouble understanding the behaviour of AR in a unit
test, in
which an object is destroyed, but not destroyed within the database

Test is here:

The background is easy to explain:
We’ve contacts and contact_combies within our application.
A contact is a human contact (business contact, etc.), a contact_combi
represent a relationship between contacts (usually two, but can be
Thus a contact has many contact_combies, and a contact_combi has many
contacts. (classic habtm-relation). contact_combies are edited embedded
within the contact-form (as explained in episodes 73-75)

contact model is here

contact_combi model here:

test log is here

Side note: all models include a simple helper setting some

Btw. test is run with:
use_transactional_fixtures = false
, but setting it to true doesn’t solve the issue.

I observed:

  • Within the application (using it by browser) (dev-env), the code
  • The assertion in line 20 fails: two objects exist, one is expected
    Parked at Loopia
  • Deleting the combi is “tried”, since the contact_combi’s before_detroy
    callback is called (see test log)
  • No delete is executed in the database
  • Its getting quite absurd, if I execute a second in my
    (enable line 21 - see test)

TypeError: can’t modify frozen hash







This implies:

  • destroy is exectued on the contact_combi object and the hash is frozen
    active record.
  • But why doesn’t these changes appear in the database - is there
    anything I
    can do to make 'em appear?

Happy 2008!
Keep smilöing