Forum: Ruby on Rails How are fixtures loaded?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2005-11-30 20:41
(Received via mailing list)
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
3ec705c5dd3480c6268b72c5617e8dae?d=identicon&s=25 smedberg (Guest)
on 2005-12-01 00:00
(Received via mailing list)
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.
This topic is locked and can not be replied to.