Skip to content

Instantly share code, notes, and snippets.

@yono
Created June 3, 2014 18:23
Show Gist options
  • Save yono/4aa490fc25f2ab63d1ef to your computer and use it in GitHub Desktop.
Save yono/4aa490fc25f2ab63d1ef to your computer and use it in GitHub Desktop.
rake db:seeds で FactoryGirl を使う

参考: http://naoty.hatenablog.com/entry/20111030/1319973849

そのままだと上手く行かなかったけど、factory_girl じゃなくて factory_girl_rails を require すればいいらしい。

db:seeds じゃなくて fixtures:load 的なことをしたい場合は下記の gist 参考にしてやってみる(まだやってない)

https://gist.github.com/brenttheisen/1045588

使い分けとしては以下の様な感じになると思う。

  • db:seeds: マスタデータの取り込み。本番環境のセットアップ時に使う
  • fixtures:load: トランザクションデータ(ダミーデータ)も含めた全データの取り込み。テストや開発環境で使う
require 'factory_girl_rails'
Song.delete_all
Artist.delete_all
SingLog.delete_all
FactoryGirl.create_list(:artist, 5)
FactoryGirl.create_list(:song, 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment