n.times { code! }

Thursday, October 11, 2007

UnitRecord and rails 2.0 PR

I've been reading about another way of testing, and I thought that I should give it a try.
The problem is that when you setup all the needed steps, UnitRecord complains about ActiveRecord trying to connect to the database:

RuntimeError: ActiveRecord is disconnected; database access is unavailable in unit tests.

This is due to some changes in rails trunk, that added a "reset_cache" method that checks for an ActiveRecord connection.

In order to avoid this, you can change your unit_test_helper.rb from this (as shown in UnitRecord documentation):

require File.dirname(__FILE__) + "/../test_helper"
require "unit_record"

to this:

require File.dirname(__FILE__) + '/../test_helper.rb'
require 'unit_record'

module UnitRecord
module DisconnectedFixtures
def disconnect!
(class << self; self; end).class_eval do
def create_fixtures(*args); end
def reset_cache(*args); end


That will take care of errors.
Happy testing!