Forum: Ruby on Rails Stupid problem with named fixture

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.
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 pergesu (Guest)
on 2005-11-19 05:23
(Received via mailing list)
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
Eea3feaacbe44706164289d068d94828?d=identicon&s=25 petermichaux (Guest)
on 2005-11-19 05:33
(Received via mailing list)
> 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.
67b6389be42524fbd776e44fd35c3d7e?d=identicon&s=25 peter.j.donald (Guest)
on 2005-11-19 05:33
(Received via mailing list)
On 11/19/05, Pat Maddox <pergesu@gmail.com> 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 Donald
RealityForge.org: http://www.realityforge.org
Accad816054fc1b2fa7dae2a2fce5266?d=identicon&s=25 cuong.tran (Guest)
on 2005-11-19 05:33
(Received via mailing list)
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 pergesu (Guest)
on 2005-11-19 08:43
(Received via mailing list)
Thanks, this is exactly what I was looking for.

Pat
This topic is locked and can not be replied to.