Stupid problem with named fixture


#1

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


#2

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.


#3

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


#4

Thanks, this is exactly what I was looking for.

Pat


#5

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