Prev | Current Page 316 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"


YAML
According to http://www.yaml.org, YAML is a ???machine parsable data serialization format
designed for human readability and interaction with scripting languages.??? It??™s the preferred
default for fixtures with frameworks like Ruby on Rails and is also the format that most Active
Record developers use.
YAML fixtures are all stored in one file per model (or rather, one file per database table).
Each file should be located in the directory set by the TestCase.fixture_path method (or in
the create_fixtures method, as we described previously). Each file should also have the .yml
extension. Within the file, each record you want in your data should have a unique name, and
each field you for which want to represent data should be indented and represented in the
key: value format.
Our previous example fixture files were all in YAML format, but we??™ll show one more in the
next example, with two records this time, to be thorough:
# Test data set in YAML format saved as account.yml
Kevin:
id: 1
username: Kevin
Catherine:
id: 2
username: Catherine
The important thing to note with this format is that the records are really unordered (though
the use of IDs in the preceding example helps to make this irrelevant in our examples).


Pages:
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328