Fixtures just Do Not Work for Me

Hello,

I have been struggling to get fixtures to work here with no success.
They just Do Not Work For Me ™.

I have created a model named Headline with the `generate’ script and
modified the test/fixtumes/headlines.yml as follows


gita:
id: 1
author: raulseixas
title: gita
happened_at: 2005-01-01 00:00:00
description: gita

           This is the CD reissue of the 1974 album and second solo 

release
by Raul Seixas, an important figure of Brazilian rock.
Acid
critic of establishment, he pardodies several figures of
Brazilian showbiz in the rocking “Super-Heróis.”

more fixtures here


My database table has columns named id, author, title, happened_at and
description as expected. My headline_test file is as follows


class HeadlineTest < Test::Unit::TestCase
fixtures :headlines

def test_fixture
    h = @headlines['gita']

    puts h.title
end

end

When I call the test with `ruby test/unit/headline_test’, I get the
following output:


  1. Error:
    test_fixture(HeadlineTest):
    NoMethodError: You have a nil object when you didn’t expect it!
    You might have expected an instance of Array.
    The error occured while evaluating nil.[]
    test/unit/headline_test.rb:25:in `test_fixture’

The call to the `fixtures’ methods is supposed to initalize the
@headlines instance variable, isn’t it? I can’t see where is my
mistake.

Cheers,

Thiago A.

Thiago A. wrote:

The call to the `fixtures’ methods is supposed to initalize the
@headlines instance variable, isn’t it? I can’t see where is my
mistake.
The syntax for getting at fixtures changed between the publication of
AWDWR and Rails 1.0 - I expect that’s what’s bitten you. Try
headlines(‘gita’) instead of @headlines[‘gita’].

On 3/23/06, Alex Y. [email protected] wrote:

The syntax for getting at fixtures changed between the publication of
AWDWR and Rails 1.0 - I expect that’s what’s bitten you. Try
headlines(‘gita’) instead of @headlines[‘gita’].

Thanks, Alex. Works perfectly now.


Thiago A.

Thiago A. wrote:

Is this outdated too? Is there any other place that I can go for docs?

http://api.rubyonrails.org/classes/Fixtures.html

It’s not actually outdated per se - the defaults just changed. You can
actually turn the old behaviour back on. There’s an explanation of what
changed (and why) here:

http://clarkware.com/cgi/blosxom/2005/10/24

On 3/23/06, Alex Y. [email protected] wrote:

The syntax for getting at fixtures changed between the publication of
AWDWR and Rails 1.0 - I expect that’s what’s bitten you. Try
headlines(‘gita’) instead of @headlines[‘gita’].

Is this outdated too? Is there any other place that I can go for docs?

http://api.rubyonrails.org/classes/Fixtures.html

Regards,

Thiago A.

On 3/23/06, Alex Y. [email protected] wrote:

It’s not actually outdated per se - the defaults just changed. You can
actually turn the old behaviour back on. There’s an explanation of what
changed (and why) here:

http://clarkware.com/cgi/blosxom/2005/10/24

I need to know how many fixtures are defined in the fixture file.
Having read this I went like


class MyControllerTest < Test::Unit::TestCase

self.use_instantiated_fixtures  = true
fixtures :headlines

def test_full_loaded
    get :show_all_headlines
    assert_equal @headlines.size, assigns(:headline).size
end

end

Would there be a more recommended way of achieving this? Can I get the
number o fixtures loaded without using instantiated fixtures?

Thanks,

Thiago A.

On 3/23/06, Alex Y. [email protected] wrote:

In this case, I think you could do Headlines.count.

Thanks for this one. I think I had gone into tunnel mode and looking
on the woring place.

Cheers,

Thiago A.

Thiago A. wrote:

Would there be a more recommended way of achieving this? Can I get the
number o fixtures loaded without using instantiated fixtures?

In this case, I think you could do Headlines.count.