Skip to content

Commit e479d3b

Browse files
committed
Show generator-driven records without blocks in docs and playground
1 parent 69e3b83 commit e479d3b

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,10 @@ FixtureBot.define do
4848
tags :ruby, :rails # creates rows in posts_tags
4949
end
5050

51-
tag :ruby do
52-
name "Ruby"
53-
end
51+
tag.name { |fixture| fixture.key.to_s.capitalize }
5452

55-
tag :rails do
56-
name "Rails"
57-
end
53+
tag :ruby # name: "Ruby"
54+
tag :rails # name: "Rails"
5855
end
5956
```
6057

@@ -180,6 +177,18 @@ end
180177

181178
The generator block receives a `fixture` object as a block parameter with access to `fixture.key` (the record's symbol name). Bare methods inside the block refer to column values set on the record.
182179

180+
When a generator covers all the columns you need, records don't need a block at all:
181+
182+
```ruby
183+
FixtureBot.define do
184+
tag.name { |fixture| fixture.key.to_s.capitalize }
185+
186+
tag :ruby # name: "Ruby"
187+
tag :rails # name: "Rails"
188+
tag :testing # name: "Testing"
189+
end
190+
```
191+
183192
A literal value shadows the generator. An explicit `nil` also shadows it:
184193

185194
```ruby

playground/blog/fixtures.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,11 @@
1414
name "Charlie"
1515
end
1616

17-
tag :ruby do
18-
name "Ruby"
19-
end
20-
21-
tag :rails do
22-
name "Rails"
23-
end
17+
tag.name { |fixture| fixture.key.to_s.capitalize }
2418

25-
tag :testing do
26-
name "Testing"
27-
end
19+
tag :ruby
20+
tag :rails
21+
tag :testing
2822

2923
post :hello_world do
3024
title "Hello World"

0 commit comments

Comments
 (0)