Over a million developers have joined DZone.

DRYing Up YAML Fixtures

DZone's Guide to

DRYing Up YAML Fixtures

· ·
Free Resource
// Rails Recipes explained how to DRY up the database configuration code. I applied the same idea to user fixtures, which worked while we used MySQL. Once on Postgres, "defaults" started throwing an error. The easiest solution was to make quentin's values the 'defaults'

quentin: &defaults
  id: 1
  login: quentin
  email: quentin@example.com
  site_id: 1
  salt: 7e3041ebc2fc05a40c60028e2c4901a81035d3cd
  crypted_password: 00742970dc9e6319f8019fd54864d3ea740f04b1 # test
  created_at: <%= 5.days.ago.to_s :db %>
  activated_at: <%= 5.days.ago.to_s :db %> # only if you're activating new signups
  id: 2
  login: aaron
  email: aaron@example.com
  activation_code: aaronscode
  site_id: 1
  <<: *defaults

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}