Here’s the method:
def run_in_transaction?
use_transactional_fixtures &&
!self.class.uses_transaction?(method_name)
end
``
I’m super confused. What is method_name? And where does it come from? It’s not a local variable. I can find two instances of def method_name in the repo and neither seem to be related. If I try to call the method directly and use_transactional_fixtures is false I get NameError: undefined local variable or method method_name’`. How is this working normally?
Argh, I meant if use_transactional_fixtures is true I get the error.
ActiveRecord::TestFixtures is mixed into the test case class itself. method_name is an alias for the Test::Unit::TestCase#name method, which the test harness sets up every time an individual test is started up.
The data maintained by uses_transaction? and friends is used to tell the fixture system that a particular test uses transactions internally (after_commit hooks, etc) and therefore shouldn’t be wrapped with a transaction. You’d specify this by saying uses_transaction :name_of_test_that_uses_transactions in your test case.
—Matt Jones
Aha! I hadn’t thought to look on TestCase. Thanks!