Why does fabricating a category have a post in it?

category = Fabricate(:category)
puts Topic.where(category_id: category).count # 1

Is this not surprising behavior? This tripped me up when writing a test that relies on the number of posts in a category, am I thinking about this wrong?

I don’t know where you saw this, so without context this is a best guess.

All categories have at least one topic - the “about the ___ topic”.

I’m thinking the test expects, or even depends on, the test conditions being as close to being the same as the “non-test” conditions as possible.

1 Like

Yes, what @Mittineague said, this is the “about XYZ topic”

5 Likes