How are fixtures loaded?


#1

I’ve been having a strange issue with some fixtures being loaded that
I don’t think should be. Anyway, I took the entire fixtures directive
out to see what the problem might be. It turns out that the fixtures
are being loaded even if there’s no fixtures directive. Here’s the
entire test file.

require File.dirname(FILE) + ‘/…/test_helper’

class TicketTest < Test::Unit::TestCase

def test_create
t = Ticket.find(1)
assert_kind_of Ticket, t
puts t.inspect
end
end

I would think that I should get some error, because the tickets table
is never populated, thus there should be no record with id=1. However
this runs just fine, and shows the object that’s specified in my
tickets.yml fixtures file.

I thought fixtures don’t get loaded unless you specify them with the
fixtures directive. Obviously I’m wrong about that…but it’s the
behavior I’d like to have, so how can I get that? Rails 0.14.3, Ruby
1.8.2, the test_helper.rb is the default with
use_transactional_fixtures=true and use_instantiated_fixtures=false.

Pat


#2

Is it possible that your data is already in the table BEFORE you run
your
test? That is, the test is not loading the fixture, but the test is
using
data that was in the table at the beginning?

I’ve made this mistake a few times- if you don’t specify that a fixture
should be loaded, then the test framework isn’t going to do anything to
the
table- it’s not going to load any data, but it’s also not going to clear
any
pre-existing data.