Stupid problem with named fixture

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

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

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

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.

See
http://manuals.rubyonrails.org/read/chapter/118#page319

Thanks, this is exactly what I was looking for.

Pat

On 11/19/05, Pat M. [email protected] 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://www.realityforge.org