From 9c1c63804880176ff8d6a88c5887bf73a656eba3 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Mon, 30 Oct 2017 00:16:30 +0800 Subject: [PATCH] factory_bot: clarify ways to build --- factory_bot.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/factory_bot.md b/factory_bot.md index 74ab3dac4..ed8a297bd 100644 --- a/factory_bot.md +++ b/factory_bot.md @@ -54,24 +54,30 @@ end ### Using +#### Build a model + ```ruby FactoryBot.build(:user) ``` +#### Other ways + ```ruby -build(:user) # not saved -create(:user) # saved -attributes_for(:user) # hash +build(:user) # → model (not saved) +create(:user) # → model (saved) +attributes_for(:user) # → hash build_stubbed(:user) # stubbed out attributes ``` +#### With options + ```ruby -# With options: build(:user, name: 'John') ``` +#### Lists + ```ruby -# List: create_list(:user, 3) build_list(:user, 3) ```