# Stupid problem with named fixture

**URL:** <https://www.ruby-forum.com/t/stupid-problem-with-named-fixture/48345>\
**Category:** Rails\
**Created:** [November 19, 2005, 5:23am UTC](https://www.ruby-forum.com/t/stupid-problem-with-named-fixture/48345 "2005-11-19T05:23:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [November 19, 2005, 5:23am UTC](https://www.ruby-forum.com/t/stupid-problem-with-named-fixture/48345/1 "2005-11-19T05:23:59Z")

</div>

I’m missing something here. The settings table just has a couple  
fields, id, name, value, and group. name, value and group are all  
strings, and id and name are the only ones with not null constraints.  
When I run this, it says @appname is nil. What am I missing?

settings\_test.rb:

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

class SettingTest \< Test::Unit::TestCase  
fixtures :settings

# Replace this with your real tests.

def test\_truth  
assert\_kind\_of Setting, @appname  
end  
end

settings.yml:

appname:  
id: 1001  
name: appname  
value: TestApp

appurl:  
id: 1002  
name: appurl  
value: [http://localhost:3000](http://localhost:3000)

logintitle:  
id: 2001  
name: logintitle  
value: Login  
group: user

loginwelcome:  
id: 2002  
name: loginwelcome  
value: Welcome to the login area  
group: user

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [November 19, 2005, 5:33am UTC](https://www.ruby-forum.com/t/stupid-problem-with-named-fixture/48345/2 "2005-11-19T05:33:02Z")

</div>

> settings\_test.rb:
> 
> require File.dirname( **FILE** ) + ‘/…/test\_helper’
> 
> class SettingTest \< Test::Unit::TestCase  
> fixtures :settings

def setup  
@appname = Setting.find\_by\_name(‘appname’)

# or

# @appname = Setting.find\_by\_value(‘TestApp’)

# or

#@appname = Setting.find(1001)  
end

# Replace this with your real tests.

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [November 19, 2005, 5:33am UTC](https://www.ruby-forum.com/t/stupid-problem-with-named-fixture/48345/3 "2005-11-19T05:33:02Z")

</div>

See  
[http://manuals.rubyonrails.org/read/chapter/118#page319](http://manuals.rubyonrails.org/read/chapter/118#page319)

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [November 19, 2005, 8:43am UTC](https://www.ruby-forum.com/t/stupid-problem-with-named-fixture/48345/4 "2005-11-19T08:43:21Z")

</div>

Thanks, this is exactly what I was looking for.

Pat

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [November 19, 2005, 5:33am UTC](https://www.ruby-forum.com/t/stupid-problem-with-named-fixture/48345/5 "2005-11-19T05:33:02Z")

</div>

On 11/19/05, Pat M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m missing something here. The settings table just has a couple  
> fields, id, name, value, and group. name, value and group are all  
> strings, and id and name are the only ones with not null constraints.  
> When I run this, it says @appname is nil. What am I missing?  
> …  
> appname:  
> id: 1001  
> name: appname  
> value: TestApp

It is looking for the variable ‘appname’ and the constant ‘TestApp’.  
This should be

appname:  
id: 1001  
name: “appname”  
value: “TestApp”

Hope that helps

–  
Cheers,

Peter D.  
[RealityForge.org](http://RealityForge.org): [http://www.realityforge.org](http://www.realityforge.org)
