Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Getting started with factory_girl in 7 minutes
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Luis Alfredo Lorenzo
June 25, 2015
Programming
42
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Getting started with factory_girl in 7 minutes
Luis Alfredo Lorenzo
June 25, 2015
More Decks by Luis Alfredo Lorenzo
See All by Luis Alfredo Lorenzo
The Active Model
babasbot
0
28
Other Decks in Programming
See All in Programming
ChromeでローカルLLM
ryu1013
0
140
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.2k
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
280
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
800
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
170
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
260
ジョジョの世界をXRで再現する
mofurune
0
170
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.2k
Domain-Driven Transformation
hschwentner
2
2.3k
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
Featured
See All Featured
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
570
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Utilizing Notion as your number one productivity tool
mfonobong
4
620
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Bash Introduction
62gerente
615
220k
Mind Mapping
helmedeiros
1
400
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
Technical Leadership for Architectural Decision Making
baasie
3
600
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
740
The browser strikes back
jonoalderson
0
1.8k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
850
Transcript
f.association => factory f.name f.owner f.description f. f.published GETTING STARTED
WITH IN 7 MINUTES! FACTORY GIRL
FactoryGirl.define do factory :user do first_name "Luis Alfredo" last_name "Lorenzo"
works_at "mxabierto" twitter "@babasbot" end end
WHAT’S FACTORY GIRL? factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory
f.name f.owner f.description f.
None
None
None
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. A REPLACEMENT FOR FIXTURES
jon: first_name: Jon last_name: Snow
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. PRO-TIP DO NOT USE FIXTURES :)
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. HOW TO DEFINE FACTORIES ?
FactoryGirl.define do factory :character do first_name "Jon" last_name "Snow" end
end
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. HOW TO USE FACTORIES?
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. 4 WAYS TO GO
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. 1 CREATE
character = create(:character) # => #<Character id: 1, first_name: "Jon",
last_name: "Snow"> character.persisted? # => true
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. 2 BUILD
user = build(:character) # => #<Character id: nil, first_name: "Jon",
last_name: "Snow"> character.persisted? # => false
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. 3 BUILD_STUBBED
character = build_stubbed(:character) # => #<Character id: 1001, first_name: "Jon",
last_name: "Snow"> character.persisted? # => true
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. 4 ATTRIBUTES_FOR
attrs = attributes_for(:character) # => { :first_name => "Jon", :last_name
=> "Snow" }
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. FACTORIES IN ACTION!
describe Character do describe "#full_name" do it "is composed of
first and last name" do user = create(:character, first_name: "Jon", last_name: "Snow") user.full_name.should eql("Jon Snow") end end end
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. SOME AWESOME STUFF
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. OVERRIDE ATTRIBUTES
character = build(:character, first_name: "Tyrion") character.first_name # => "Tyrion"
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. LAZY ATTRIBUTES
FactoryGirl.define do factory :character do first_name "Jon" last_name "Snow" date_of_birth
{ 20.years.ago } end end
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. DEPENDENT ATTRIBUTES
FactoryGirl.define do factory :character do first_name "jon" last_name "snow" email
{ "#{first_name}.#{last_name}@nightswatch.com" } end end
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. TRANSIENT ATTRIBUTES
FactoryGirl.define do factory :character do ignore do broke_bows false end
name "Jon Snow" after_create do |character, instance| character.revoke_nights_watch! if instance.broke_bows? end end end create(:character, broke_bows: true)
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. CALLBACKS
FactoryGirl.define do factory :character do after_create { |character| character.give_direwolf! }
# also: after_build, after_stub, before_create end end
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. INHERITANCE
FactoryGirl.define do factory :character do first_name "Jon" last_name "Snow" factory
:deceased_character do deceased_at { Date.today } deceased true end end end
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. ASSOCIATIONS
FactoryGirl.define do factory :character do first_name "Jon" last_name "Snow" animal
end factory :animal do name "Ghost" species "Direwolf" end end
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. ASSOCIATION ALIASES
FactoryGirl.define do factory :character do first_name "Jon" last_name "Snow" direwolf
end factory :animal, aliases: [:direwolf] do name "Ghost" species "Direwolf" end end
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. SEQUENCES
FactoryGirl.define do factory :crow do sequence :email do |n| "crow#{n}@nightswatch.com"
end end end
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. TRAITS
FactoryGirl.define do factory :character do on_nights_watch false trait(:nights_watch) { on_nights_watch(true)
} trait(:has_direwolf) { direwolf } factory :jon_snow, traits %i(nights_watch has_direwolf) end end
factory f.csv_file File. spec/fixtures/files/inventory.csv" f.association => factory f.name f.owner f.description
f. < EOF >
None
FactoryGirl.define do factory :babasbot do name "Luis Alfredo Lorenzo" github
"/babasbot" twitter "@babasbot" end end