Forum: Ruby on Rails RE: Re: Fixtures and Relationships

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
60e38de043848f82392062088f191213?d=identicon&s=25 Hogan, Brian P. (Guest)
on 2006-02-23 21:39
(Received via mailing list)
Gotcha. That makes total sense. It also makes sense because the yml
probably comes from a hash, and hashes aren't ordered. I think you're in
trouble! :)

May need to take a different approach like the one I suggested, and
maybe make one script that builds your test dataset for you before
dumping it to fixtures.

Interesting though.... never thought about that.
09ff21c336ae126e8b3199f8b64d7796?d=identicon&s=25 D. Taylor Singletary (Guest)
on 2006-02-23 21:57
(Received via mailing list)
Having recently had a solution to this issue presented to me by a
I'm happy to help out and point how to get fixture rows loaded in a
particular order when running tests. This proves useful especially for
data structures. It may not necessarily be the answer to the question
were asking, but it's useful knowledge nonetheless. details how to set up
YAML file to order the database rows you've defined using an Omap. While
documentation for both omap and the fixtures here leaves something to be
desired, essentially you can setup a YAML file thus:

--- !omap
- parent:
    id: 1
   id: 2
   parent_id: 1
  id: 3
  parent_id: 2

This will ensure that the database rows are loaded into the test
database in
exactly this order.

Hope this helps you out.

D. Taylor Singletary,
Reality Technician.
8e44c65ac5b896da534ef2440121c953?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2006-02-24 00:39
(Received via mailing list)
An omap is essentially an ordered hash in yaml if that helps.

C4dc94c893471878a105761a9207f29b?d=identicon&s=25 Zack Chandler (Guest)
on 2006-02-24 01:39
(Received via mailing list)
Taylor, Ezra,
  Thanks for your help.  I feel like I'm really close and must have one
small typo/misunderstanding.  I've tried !omap and this is the error I

rake aborted!
a YAML error occured parsing test/fixtures/users.yml. Please note that
 be consistently indented using spaces. Tabs are not allowed. Please
have a
The exact error was:
  YAML::Error: Invalid !omap: {"-nikki"=>{"salt"=>245481,
065, "username"=>"nikki", "screen_name"=>"nikki", "email_address"=>"
com"}, "-honemaster"=>{"salt"=>24598, "hashed_password"=>814677,
nemaster", "screen_name"=>"honemaster", "email_address"=>""}
, "-hansgouer"=>{"salt"=>631182, "hashed_password"=>328485,
er", "screen_name"=>"hansgouer",
erman"=>{"salt"=>948687, "hashed_password"=>287631,
reen_name"=>"kilterman", "email_address"=>""},
alt"=>194883, "hashed_password"=>736319, "username"=>"zenman",
enman", "email_address"=>""},
"-rawfingers"=>{"salt"=>342450, "h
ashed_password"=>855412, "username"=>"rawfingers",
"email_address"=>""}, "-herro"=>{"salt"=>976814,
sword"=>158429, "username"=>"herro", "screen_name"=>"herro",
"email_address"=>"h"}, "-gymrat"=>{"salt"=>981951, "hashed_password"=>987702,
me"=>"gymrat", "screen_name"=>"gymrat",
roo"=>{"salt"=>878098, "hashed_password"=>843882, "username"=>"roo",
e"=>"roo", "email_address"=>""},
"-dresserlan"=>{"salt"=>832618, "h
ashed_password"=>22106, "username"=>"dresserlan",
"screen_name"=>"dresserlan", "
email_address"=>""}, "-nickta"=>{"salt"=>256946,
sword"=>29039, "username"=>"nickta", "screen_name"=>"nickta",
"email_address"=>""}, "-jason"=>{"salt"=>541275,
ame"=>"jason", "screen_name"=>"jason",
autygirl"=>{"salt"=>554156, "hashed_password"=>57327,
"screen_name"=>"beautygirl", "email_address"=>""}}

Here is my fixture... am I missing something???

  screen_names = [
      'nickta', 'herro', 'hansgouer', 'kilterman', 'zenman',
      'rawfingers', 'gymrat', 'beautygirl', 'nikki', 'jason', 'roo',
--- !omap
<% screen_names.each do |name| %>
-<%= name %>:
  username: <%= name %>
  hashed_password: <%= rand(1000000) %>
  salt: <%= rand(1000000) %>
  screen_name: <%= name %>
  email_address: <%= name %>
<% end %>

09ff21c336ae126e8b3199f8b64d7796?d=identicon&s=25 D. Taylor Singletary (Guest)
on 2006-02-24 02:43
(Received via mailing list)
I'm not sure if this is your problem, but it might be. YAML files are
sensitive to whitespace versus tabs, and it may behoove you to keep the
pretty clean of excess spaces by ending your non-content generating erb
calls with a - character, which stops them from producing a line break
they've been processed. So for the ones that don't start with <%= ... %>
it like: <% screen_names.each do |name| -%>  (notice the "-" prior to
the %>

Also, make sure you are using two spaces rather than a tab character for
your field definitions. Also, make sure there is a space between your
character prior to the "record name" definition.. When I succesfully got
omap to work today, I increased my "soft tab width" to match towards the
extra characters generated by the "-" in the "named record" area... so
if I
were to do what you're doing, I would have done it like this (though I
haven't tested your particular example):

  screen_names = [
      'nickta', 'herro', 'hansgouer', 'kilterman', 'zenman',
      'rawfingers', 'gymrat', 'beautygirl', 'nikki', 'jason', 'roo',
--- !omap
<% screen_names.each do |name| -%>
- <%= name %>:
    username: <%= name %>
    hashed_password: <%= rand(1000000) %>
    salt: <%= rand(1000000) %>
    screen_name: <%= name %>
    email_address: <%= name %>
<% end %->

D. Taylor Singletary,
Reality Technician
C4dc94c893471878a105761a9207f29b?d=identicon&s=25 Zack Chandler (Guest)
on 2006-02-24 17:48
(Received via mailing list)
  I really appreciate your help on this one.  In fact the problem was
width of spaces lining up with the extra space caused by the space
the "-" before the record definition.  I had 2 spaces and I needed 3 to
it work.  What a nightmare!  Thanks again for all your help.

BTW I never could get the -%> terminator that suppresses the newline to
in the fixture.  I use them all the time in my views.  Who knows...

This topic is locked and can not be replied to.