# 为什么新建的类别里会有一篇帖子？

**URL:** https://meta.discourse.org/t/why-does-fabricating-a-category-have-a-post-in-it/100844
**Category:** Development
**Created:** [2018年十月30日 05:01 UTC](https://meta.discourse.org/t/why-does-fabricating-a-category-have-a-post-in-it/100844 "2018-10-30T05:01:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Kampfkarren](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kampfkarren/32/109627_2.png) [@Kampfkarren](https://meta.discourse.org/u/Kampfkarren)
#### Post date: [2018年十月30日 05:01 UTC](https://meta.discourse.org/t/why-does-fabricating-a-category-have-a-post-in-it/100844/1 "2018-10-30T05:01:18Z")

</div>

```rb
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?

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [2018年十月30日 05:47 UTC](https://meta.discourse.org/t/why-does-fabricating-a-category-have-a-post-in-it/100844/2 "2018-10-30T05:47:10Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2018年十月30日 05:57 UTC](https://meta.discourse.org/t/why-does-fabricating-a-category-have-a-post-in-it/100844/3 "2018-10-30T05:57:49Z")

</div>

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

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