Forum: Ruby on Rails My first test - named fixture not autoloading instance varia

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.
25bbc96d9c53647354cb724e744b2222?d=identicon&s=25 Greg Freemyer (Guest)
on 2006-01-16 20:50
(Received via mailing list)
I'm trying to write a test like the one at the bottom of page 148 in
Agile Rails.

I'm using rails 1.0

I've created the fixture correctly I'm pretty sure because the test
database table is being populated per the fixture.

I have what I think is a simple unit test:
=========
require File.dirname(__FILE__) + '/../test_helper'

class CaseTest < Test::Unit::TestCase
  fixtures :cases

  def setup
    @case = Case.find(1)
  end

# Replace this with your real tests.
  def test_verify_schema_has_correct_fields
    assert_kind_of Case, @case
    assert_equal 1, @case.id
    assert_equal "F-06-101", @case.case_number
    assert_equal @first.case_number, @case.case_number
 end
=====

The first 2 assert_equal statements are working fine and demonstrate
the basic table logic is fine and that my fixture is working.

The third one is failing because @first is nil.

Per the book @first should be automatically created because it is the
name of my fixture.  (ie. the scaffold named the first fixture "first"
and I should be able to reference it as @first.)

Any idea what is wrong?

Greg
--
Greg Freemyer
The Norcross Group
Forensics for the 21st Century
2f46d76f0e5db4dc318b03be07ebaac4?d=identicon&s=25 Tom Ward (Guest)
on 2006-01-17 01:24
(Received via mailing list)
If in test_helper.rb you have use_instantiated_fixtures = false, then
your fixtures will not be pre-instantiated into instance variables.
You can still access the fixture you want using cases(:first)

Tom Ward
25bbc96d9c53647354cb724e744b2222?d=identicon&s=25 Greg Freemyer (Guest)
on 2006-01-17 01:27
(Received via mailing list)
That worked.  Thanks Tom

On 1/16/06, Tom Ward <tom@popdog.net> wrote:
> > I'm using rails 1.0
> >
> >  end
> >
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>


--
Greg Freemyer
The Norcross Group
Forensics for the 21st Century
This topic is locked and can not be replied to.