Forum: Ruby on Rails error w/dynamic fixtures

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.
Roy P. (Guest)
on 2008-11-27 00:49
(Received via mailing list)
Hey All,

I'm trying to do the basic test/unit stuff & having trouble w/a dynamic
fixture error.  I'm running rails 2.0.2 on windows.

I have statuses & projects.  Projects belong_to status and so forth.

# statuses.yml ===================
active:
  name: Active
  description: MyString

# projects.yml ===================
one:
  name: Center for Health Communications Research
  abbreviation: CHCR
  description: A collection of 3 projects.
  grant_number: 8
  status_id: <%= statuses(:active).id %>
  start_date: 2008-03-20
  end_date: 2008-03-20

==========================================

But when I run tests I get this for output:

==========================================

  1) Error: test_truth(DomainTest): Fixture::FormatError: a YAML error
occurred parsing C:/railsapps/collabtrac/test/fixtures/projects.yml.
Please note that YAML must be consistently indented using spaces. Tabs
are not allowed. Please have a look at http://www.yaml.org/faq.html The
exact error was:   NoMethodError: undefined method `statuses' for
main:Object

==========================================

Can someone tell me what I'm doing wrong here?  Is the problem that
projects.yml is getting read in before statuses.yml?  If so, how do I
control that load order?

Thanks!

-Roy

Roy P.
Research Analyst/Programmer
Group Health Center For Health Studies (Cancer Research Network)
(206) 287-2078
Google Talk: rpardee
Frederick C. (Guest)
on 2008-11-27 15:00
(Received via mailing list)
On Nov 26, 10:49 pm, "Pardee, Roy" <removed_email_address@domain.invalid> wrote:
> Hey All,

> Can someone tell me what I'm doing wrong here?  Is the problem that projects.yml is 
getting read in before statuses.yml?  If so, how do I control that load order?

That is correct and the statuses method probably isn't even defined in
the context you are using this in. The write way to do this is to put

status: active

in that fixture. As long as you have the status belongs_to
association, rails will figure out that this means that you want the
status_id column to have the value of the id of the status fixture
with label 'active'. This won't work if your fixture for statuses
explicitly sets an id.

Fred
Roy P. (Guest)
on 2008-12-02 00:45
(Received via mailing list)
Sweetness--thanks!

-Roy
This topic is locked and can not be replied to.