maeshimaの日記

メモ書きです

machinistの復習

fixture代換プラグインMachinistの使い方 - おもしろWEBサービス開発日記の復習。忘れてた or 気になったところを再度メモ

Shamのブロック引数

Shamのブロック変数にはインデックス番号が入る

Sham.name {|index| "Name #{index}" }

make_unsaved

saveしたくないときはmake_unsavedを使う

named blueprint

ごちゃごちゃした感じになりがちなので積極的に使っていきたい

User.blueprint do
  name
  email
end

User.blueprint(:admin) do
  name  { Sham.name + " (admin)" }
  admin { true }
end

関連上でmake, plan

makeは関連上でも使える

post.comments.make

planも関連上で使える

post.comments.plan

ブロック

makeはブロックをとることもできる

def make_post_with_comments(attributes = {})
  Post.make(attributes) do |post|
    3.times { post.comments.make }
  end
end