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”

https://github.com/discourse/discourse/blob/ead6600f4b175b95b2028e3e0b8f7b7ede9b84e4/app/models/category.rb#L210-L218

5 Likes