Transactional fixtures in Rails: a head-banger

Posted by max on June 26, 2007

Amy and I were banging our heads today over some model unit tests we were running in Rails. Why on earth did the following updates not show up in the database after the test suite ran? The assertions all behaved as expected.

    item.postal_code = "02138"
    assert item.valid?
    assert item.save

I mean, consarn it, we saved the record! Shouldn’t it be in the database?

Well, the answer turned out to be fairly simple. ActiveRecord’s fixtures, will, by default, rollback everything that was done on the database during the method in question, unless you set

    self.use_transactional_fixtures = false

in your test class. I had strongly been under the impression that the fixtures were loaded once at the beginning of each method within a test class.

Now that we know that the logic is actually behaving as expected, we are back to the default behavior (i.e., using transactional fixtures.)

Reference here.

Theoretically Related Posts
  • Testing in Rails: Way More Trouble Than Flossing
  • Testing Rails: the learning curve
  • 12 Steps to Testing in Rails
  • “Release It!” and corporate computing fun
  • Trackbacks

    Use this link to trackback from your own site.

    Comments

    Leave a response

    Comments