Forum: Ruby on Rails hash fixture access broken in functional test

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.
1f1bd7de8337317975b0475be56392d2?d=identicon&s=25 Dan Tenenbaum (dandante)
on 2006-01-19 21:16
I have a functional test class that uses the "topics" fixture. I
verified that the fixture is loaded into the database by doing this:
     assert_equal 2, Topic.find_all.size

So I should have an instance variable called @topics and instance
variables for each of the rows in the fixture, in this case, @first and
@another. But all those variables are nil inside my test method.

Is that convenience only available in unit tests? It is equally useful
in functional tests. Or is there some other problem? Thanks...
1f1bd7de8337317975b0475be56392d2?d=identicon&s=25 Dan Tenenbaum (dandante)
on 2006-01-20 20:42
Dan Tenenbaum wrote:
> I have a functional test class that uses the "topics" fixture. I
> verified that the fixture is loaded into the database by doing this:
>      assert_equal 2, Topic.find_all.size
>
> So I should have an instance variable called @topics and instance
> variables for each of the rows in the fixture, in this case, @first and
> @another. But all those variables are nil inside my test method.
>
> Is that convenience only available in unit tests? It is equally useful
> in functional tests. Or is there some other problem? Thanks...

Looks like this doesn't work in unit tests either. What gives? The rails
book says I should be able to do this, and I definitely have a more
recent version of rails and ruby than they did when writing that
book..........
D4e51fd9554030ab55c379fdc1a34826?d=identicon&s=25 Keith Lancaster (klancaster)
on 2006-01-20 21:46
Dan Tenenbaum wrote:
> Dan Tenenbaum wrote:
>> I have a functional test class that uses the "topics" fixture. I
>> verified that the fixture is loaded into the database by doing this:
>>      assert_equal 2, Topic.find_all.size
>>
>> So I should have an instance variable called @topics and instance
>> variables for each of the rows in the fixture, in this case, @first and
>> @another. But all those variables are nil inside my test method.
>>
>> Is that convenience only available in unit tests? It is equally useful
>> in functional tests. Or is there some other problem? Thanks...
>
> Looks like this doesn't work in unit tests either. What gives? The rails
> book says I should be able to do this, and I definitely have a more
> recent version of rails and ruby than they did when writing that
> book..........

Things changed just slightly since the book: here is a quote from
http://www.ruby-forum.com/topic/50061#17690

> The book is awesome, but beware that the section on accessing  > fixture data in unit 
tests is broken since 1.0 came around. Found > that out the hard way the other night. > > 
You used to be able to access fixture data like @my_product, but > now it's like 
products(:my_product)

HTH,
Keith
D4e51fd9554030ab55c379fdc1a34826?d=identicon&s=25 Keith Lancaster (klancaster)
on 2006-01-20 21:47
Keith Lancaster wrote:
> Dan Tenenbaum wrote:
>> Dan Tenenbaum wrote:
>>> I have a functional test class that uses the "topics" fixture. I
>>> verified that the fixture is loaded into the database by doing this:
>>>      assert_equal 2, Topic.find_all.size
>>>
>>> So I should have an instance variable called @topics and instance
>>> variables for each of the rows in the fixture, in this case, @first and
>>> @another. But all those variables are nil inside my test method.
>>>
>>> Is that convenience only available in unit tests? It is equally useful
>>> in functional tests. Or is there some other problem? Thanks...
>>
>> Looks like this doesn't work in unit tests either. What gives? The rails
>> book says I should be able to do this, and I definitely have a more
>> recent version of rails and ruby than they did when writing that
>> book..........
>
> Things changed just slightly since the book: here is a quote from
> http://www.ruby-forum.com/topic/50061#17690
>
>> The book is awesome, but beware that the section on accessing  > fixture data in unit 
tests is broken since 1.0 came around. Found > that out the hard way the other night. > > 
You used to be able to access fixture data like @my_product, but > now it's like 
products(:my_product)
>
> HTH,
> Keith

From the same post:
This is simply an option which was on by default and was turned off by
default but it is still a valid way to access fixture data, all you
have to do is change test_helper.rb (if you want it for all tests, or
add the following line at the beginning of the testcase where you want
it :

  self.use_instantiated_fixtures  = true

Keith (again...)
1f1bd7de8337317975b0475be56392d2?d=identicon&s=25 Dan Tenenbaum (dandante)
on 2006-01-20 21:51
Keith Lancaster wrote:
> Things changed just slightly since the book: here is a quote from
> http://www.ruby-forum.com/topic/50061#17690

Thanks. That works. Hope they come out with that PDF of
revisions.........
This topic is locked and can not be replied to.