# Rails Noob Question

**URL:** <https://www.ruby-forum.com/t/rails-noob-question/89104>\
**Category:** Rails\
**Created:** [January 3, 2006, 10:47pm UTC](https://www.ruby-forum.com/t/rails-noob-question/89104 "2006-01-03T22:47:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![madscene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@madscene](https://www.ruby-forum.com/u/madscene)\
**Post date:** [January 3, 2006, 10:47pm UTC](https://www.ruby-forum.com/t/rails-noob-question/89104/1 "2006-01-03T22:47:10Z")

</div>

## Apparently the first time I posted this, it was tacked onto the end of another thread. Please pardon my repost. Won’t happen again.

Howdy. I’m just getting into Rails, and really enjoying it! I’m coming  
from the .NET world, so I’ll embarrassedly admit that I’m running it on  
winXP and even using SQLServer (for now, may switch to mysql soon).  
Hopefully someday I’ll feel competent enough on my mac to work there,  
but  
one new thing at a time!

Anyway, I am trying to be a good programmer and use TDD, but am having a  
problem with a simple test, mostly copied from the examples on:  
[http://ar.rubyonrails.org/classes/Fixtures.html](http://ar.rubyonrails.org/classes/Fixtures.html)

I generated my model classes and even got the scaffold working (ooh,  
bad!  
not TDD!!). I was starting out messing with unit tests and fixtures,  
and  
was taking baby steps. Ran into a hitch when it was saying that my  
fixture  
variable was nil:

require File.dirname( **FILE** ) + ‘/…/test\_helper’

class MessageTest \< Test::Unit::TestCase  
fixtures :messages, :tags, :messages\_tags

def setup  
@message = Message.find(1)  
end

def test\_create  
assert\_kind\_of Message, @message  
assert\_not\_nil @messages

# assert\_equal @messages[“peace\_message”].title, @message.title

end  
end

The three fixtures exist (messages, tags, messages\_tags) and have data.  
Brute force tests (assert\_equal “my message title”, @message.title)  
pass.  
But the @messages[“peace\_message”][“title”] returns an error. I added  
the  
assert\_not\_nil call and indeed, that fails. It seems like it should  
automatically exist? What am I doing wrong?

Thanks for any help!

Brian

---

<div class="post-metadata">

**Author:** ![madscene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@madscene](https://www.ruby-forum.com/u/madscene)\
**Post date:** [January 4, 2006, 12:49am UTC](https://www.ruby-forum.com/t/rails-noob-question/89104/2 "2006-01-04T00:49:08Z")

</div>

Hi, first of all you don’t do anything wrong.

The problem is that something changed with Rails 1.0.  
Before, all the fixtures defined were loaded into your memory and one  
can imagine that tests were quite slow if too many fixtures were used.  
That’s why they changed it and from now on you’ll have to load your  
fixtures instances for yourself.

So in setup you have to do something like:

def setup  
@message = Message.find(1)  
@message2 = messages(:message\_label)  
end

I hope that helps…

Markus

Brian D. wrote:

> ## Apparently the first time I posted this, it was tacked onto the end of another thread. Please pardon my repost. Won’t happen again.
> 
> Howdy. I’m just getting into Rails, and really enjoying it! I’m coming  
> from the .NET world, so I’ll embarrassedly admit that I’m running it on  
> winXP and even using SQLServer (for now, may switch to mysql soon).  
> Hopefully someday I’ll feel competent enough on my mac to work there,  
> but  
> one new thing at a time!
> 
> Anyway, I am trying to be a good programmer and use TDD, but am having a  
> problem with a simple test, mostly copied from the examples on:  
> [http://ar.rubyonrails.org/classes/Fixtures.html](http://ar.rubyonrails.org/classes/Fixtures.html)
> 
> I generated my model classes and even got the scaffold working (ooh,  
> bad!  
> not TDD!!). I was starting out messing with unit tests and fixtures,  
> and  
> was taking baby steps. Ran into a hitch when it was saying that my  
> fixture  
> variable was nil:
> 
> require File.dirname( **FILE** ) + ‘/…/test\_helper’
> 
> class MessageTest \< Test::Unit::TestCase  
> fixtures :messages, :tags, :messages\_tags
> 
> def setup  
> @message = Message.find(1)  
> end
> 
> def test\_create  
> assert\_kind\_of Message, @message  
> assert\_not\_nil @messages
> 
> # assert\_equal @messages[“peace\_message”].title, @message.title
> 
> end  
> end
> 
> The three fixtures exist (messages, tags, messages\_tags) and have data.  
> Brute force tests (assert\_equal “my message title”, @message.title)  
> pass.  
> But the @messages[“peace\_message”][“title”] returns an error. I added  
> the  
> assert\_not\_nil call and indeed, that fails. It seems like it should  
> automatically exist? What am I doing wrong?
> 
> Thanks for any help!
> 
> Brian

---

<div class="post-metadata">

**Author:** ![madscene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@madscene](https://www.ruby-forum.com/u/madscene)\
**Post date:** [January 4, 2006, 12:56am UTC](https://www.ruby-forum.com/t/rails-noob-question/89104/3 "2006-01-04T00:56:33Z")

</div>

Markus,

Thanks! That explains it. I was wondering if something had changed in  
1.0. I should review the release notes.

Could you please explain what you are doing in this line:

> @message2 = messages(:message\_label)

Is messages referring to the fixture? Where are you loading the  
fixture? Thanks again, and I’ll try to find some 1.0 docs in the  
meantime.

Scorpion wrote:

> Hi, first of all you don’t do anything wrong.
> 
> The problem is that something changed with Rails 1.0.  
> Before, all the fixtures defined were loaded into your memory and one  
> can imagine that tests were quite slow if too many fixtures were used.  
> That’s why they changed it and from now on you’ll have to load your  
> fixtures instances for yourself.
> 
> So in setup you have to do something like:
> 
> def setup  
> @message = Message.find(1)  
> @message2 = messages(:message\_label)  
> end
> 
> I hope that helps…
> 
> Markus

---

<div class="post-metadata">

**Author:** ![madscene](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@madscene](https://www.ruby-forum.com/u/madscene)\
**Post date:** [January 4, 2006, 1:03am UTC](https://www.ruby-forum.com/t/rails-noob-question/89104/4 "2006-01-04T01:03:45Z")

</div>

I got it! Thanks. I found what I needed to know here:  
[http://manuals.rubyonrails.com/read/chapter/118](http://manuals.rubyonrails.com/read/chapter/118)

Brian D. wrote:

> Markus,
> 
> Thanks! That explains it. I was wondering if something had changed in  
> 1.0. I should review the release notes.
> 
> Could you please explain what you are doing in this line:
> 
> > @message2 = messages(:message\_label)
> 
> Is messages referring to the fixture? Where are you loading the  
> fixture? Thanks again, and I’ll try to find some 1.0 docs in the  
> meantime.
> 
> Scorpion wrote:
> 
> > Hi, first of all you don’t do anything wrong.
> > 
> > The problem is that something changed with Rails 1.0.  
> > Before, all the fixtures defined were loaded into your memory and one  
> > can imagine that tests were quite slow if too many fixtures were used.  
> > That’s why they changed it and from now on you’ll have to load your  
> > fixtures instances for yourself.
> > 
> > So in setup you have to do something like:
> > 
> > def setup  
> > @message = Message.find(1)  
> > @message2 = messages(:message\_label)  
> > end
> > 
> > I hope that helps…
> > 
> > Markus
