A platform for community discussion. Free, open, simple.
DEV: Default to skipping creating a topic when fabricating categories (#7976)
Daniel Waterworth4ae8065f2ca8
diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rbindex 748f08888c7..3cf118811f0 100644--- a/spec/components/search_spec.rb+++ b/spec/components/search_spec.rb@@ -13,7 +13,7 @@ describe Search docontext 'post indexing observer' dobefore do- @category = Fabricate(:category, name: 'america')+ @category = Fabricate(:category_with_definition, name: 'america')@topic = Fabricate(:topic, title: 'sam saffron test topic', category: @category)@post = Fabricate(:post, topic: @topic, raw: 'this <b>fun test</b> <img src="bla" title="my image">')@indexed = @post.post_search_data.search_data@@ -48,7 +48,7 @@ describe Search docontext 'category indexing observer' dobefore do- @category = Fabricate(:category, name: 'america')+ @category = Fabricate(:category_with_definition, name: 'america')@indexed = @category.category_search_data.search_dataend@@ -397,7 +397,7 @@ describe Search doendit 'does not allow a post with repeated words to dominate the ranking' do- category = Fabricate(:category, name: "winter is coming")+ category = Fabricate(:category_with_definition, name: "winter is coming")post = Fabricate(:post,raw: "I think winter will end soon",@@ -495,7 +495,7 @@ describe Search doendit 'secures results correctly' do- category = Fabricate(:category)+ category = Fabricate(:category_with_definition)topic.category_id = category.idtopic.save@@ -532,12 +532,12 @@ describe Search doendcontext 'categories' do- let(:category) { Fabricate(:category, name: "monkey Category 2") }+ let(:category) { Fabricate(:category_with_definition, name: "monkey Category 2") }let(:topic) { Fabricate(:topic, category: category) }let!(:post) { Fabricate(:post, topic: topic, raw: "snow monkey") }let!(:ignored_category) do- Fabricate(:category,+ Fabricate(:category_with_definition,name: "monkey Category 1",slug: "test",search_priority: Searchable::PRIORITIES[:ignore]@@ -560,7 +560,7 @@ describe Search dodescribe "with child categories" dolet!(:child_of_ignored_category) do- Fabricate(:category,+ Fabricate(:category_with_definition,name: "monkey Category 3",parent_category: ignored_category)@@ -606,7 +606,7 @@ describe Search doenddescribe 'categories with different priorities' do- let(:category2) { Fabricate(:category) }+ let(:category2) { Fabricate(:category_with_definition) }it "should return posts in the right order" doraw = "The pure genuine evian"@@ -667,7 +667,7 @@ describe Search dolet!(:tag) { Fabricate(:tag) }let!(:uppercase_tag) { Fabricate(:tag, name: "HeLlO") }let(:tag_group) { Fabricate(:tag_group) }- let(:category) { Fabricate(:category) }+ let(:category) { Fabricate(:category_with_definition) }context 'post searching' doit 'can find posts with tags' do@@ -731,7 +731,7 @@ describe Search docontext 'type_filter' dolet!(:user) { Fabricate(:user, username: 'amazing', email: '[email protected]') }- let!(:category) { Fabricate(:category, name: 'amazing category', user: user) }+ let!(:category) { Fabricate(:category_with_definition, name: 'amazing category', user: user) }context 'user filter' dolet(:results) { Search.execute('amazing', type_filter: 'user') }@@ -773,7 +773,7 @@ describe Search doendit 'can use category as a search context' do- category = Fabricate(:category,+ category = Fabricate(:category_with_definition,search_priority: Searchable::PRIORITIES[:ignore])@@ -781,7 +781,7 @@ describe Search dotopic_no_cat = Fabricate(:topic)# includes subcategory in search- subcategory = Fabricate(:category, parent_category_id: category.id)+ subcategory = Fabricate(:category_with_definition, parent_category_id: category.id)sub_topic = Fabricate(:topic, category: subcategory)post = Fabricate(:post, topic: topic, user: topic.user)@@ -1044,7 +1044,7 @@ describe Search dotoday = Date.todayyesterday = 1.day.agotwo_days_ago = 2.days.ago- category = Fabricate(:category)+ category = Fabricate(:category_with_definition)old_topic = Fabricate(:topic,title: 'First Topic, testing the created_at sort',@@ -1098,7 +1098,7 @@ describe Search doit 'supports category slug and tags' do# main category- category = Fabricate(:category, name: 'category 24', slug: 'cateGory-24')+ category = Fabricate(:category_with_definition, name: 'category 24', slug: 'cateGory-24')topic = Fabricate(:topic, created_at: 3.months.ago, category: category)post = Fabricate(:post, raw: 'Sams first post', topic: topic)@@ -1106,7 +1106,7 @@ describe Search doexpect(Search.execute("sams post category:#{category.id}").posts.length).to eq(1)expect(Search.execute('sams post #categoRy-25').posts.length).to eq(0)- sub_category = Fabricate(:category, name: 'sub category', slug: 'sub-category', parent_category_id: category.id)+ sub_category = Fabricate(:category_with_definition, name: 'sub category', slug: 'sub-category', parent_category_id: category.id)second_topic = Fabricate(:topic, created_at: 3.months.ago, category: sub_category)Fabricate(:post, raw: 'sams second post', topic: second_topic)@@ -1214,7 +1214,7 @@ describe Search doendit 'orders posts correctly when combining tags with categories or terms' do- cat1 = Fabricate(:category, name: 'food')+ cat1 = Fabricate(:category_with_definition, name: 'food')topic6 = Fabricate(:topic, tags: [tag1, tag2], category: cat1)topic7 = Fabricate(:topic, tags: [tag1, tag2, tag3], category: cat1)post7 = Fabricate(:post, topic: topic6, raw: "Wakey, wakey, eggs and bakey.", like_count: 5)diff --git a/spec/components/suggested_topics_builder_spec.rb b/spec/components/suggested_topics_builder_spec.rbindex ab135df796e..4d73d032f78 100644--- a/spec/components/suggested_topics_builder_spec.rb+++ b/spec/components/suggested_topics_builder_spec.rb@@ -98,7 +98,7 @@ describe SuggestedTopicsBuilder doendcontext "category definition topics" do- fab!(:category) { Fabricate(:category) }+ fab!(:category) { Fabricate(:category_with_definition) }it "doesn't add a category definition topic" doexpect(category.topic_id).to be_presentdiff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rbindex 273c64081d7..3eccdec1420 100644--- a/spec/components/topic_query_spec.rb+++ b/spec/components/topic_query_spec.rb@@ -19,7 +19,7 @@ describe TopicQuery docontext 'secure category' doit "filters categories out correctly" do- category = Fabricate(:category)+ category = Fabricate(:category_with_definition)group = Fabricate(:group)category.set_permissions(group => :full)category.save@@ -133,9 +133,8 @@ describe TopicQuery doendcontext 'category filter' do- let(:category) { Fabricate(:category) }-- let(:diff_category) { Fabricate(:diff_category) }+ let(:category) { Fabricate(:category_with_definition) }+ let(:diff_category) { Fabricate(:category_with_definition, name: "Different Category") }it "returns topics in the category when we filter to it" doexpect(TopicQuery.new(moderator).list_latest.topics.size).to eq(0)@@ -153,7 +152,7 @@ describe TopicQuery doendcontext 'subcategories' do- let!(:subcategory) { Fabricate(:category, parent_category_id: category.id) }+ let!(:subcategory) { Fabricate(:category_with_definition, parent_category_id: category.id) }it "works with subcategories" doexpect(TopicQuery.new(moderator, category: category.id).list_latest.topics.size).to eq(1)@@ -214,8 +213,8 @@ describe TopicQuery doendcontext "and categories too" do- let(:category1) { Fabricate(:category) }- let(:category2) { Fabricate(:category) }+ let(:category1) { Fabricate(:category_with_definition) }+ let(:category2) { Fabricate(:category_with_definition) }it "returns topics in the given category with the given tag" dotagged_topic1 = Fabricate(:topic, category: category1, tags: [tag])@@ -231,7 +230,7 @@ describe TopicQuery docontext 'muted categories' doit 'is removed from new and latest lists' do- category = Fabricate(:category)+ category = Fabricate(:category_with_definition)topic = Fabricate(:topic, category: category)CategoryUser.create!(user_id: user.id,category_id: category.id,@@ -430,7 +429,7 @@ describe TopicQuery doendcontext 'categorized' do- fab!(:category) { Fabricate(:category) }+ fab!(:category) { Fabricate(:category_with_definition) }let(:topic_category) { category.topic }fab!(:topic_no_cat) { Fabricate(:topic) }fab!(:topic_in_cat1) { Fabricate(:topic, category: category,@@ -948,12 +947,12 @@ describe TopicQuery dofab!(:user3) { Fabricate(:user) }fab!(:private_category) do- Fabricate(:private_category, group: group)+ Fabricate(:private_category_with_definition, group: group)endlet!(:private_message_topic) { Fabricate(:private_message_post, user: user).topic }let!(:topic1) { Fabricate(:topic, user: user) }- let!(:topic2) { Fabricate(:topic, user: user, category: Fabricate(:category)) }+ let!(:topic2) { Fabricate(:topic, user: user, category: Fabricate(:category_with_definition)) }let!(:topic3) { Fabricate(:topic, user: user, category: private_category) }let!(:topic4) { Fabricate(:topic) }let!(:topic5) { Fabricate(:topic, user: user, visible: false) }@@ -1024,8 +1023,8 @@ describe TopicQuery doendcontext "shared drafts" do- fab!(:category) { Fabricate(:category) }- fab!(:shared_drafts_category) { Fabricate(:category) }+ fab!(:category) { Fabricate(:category_with_definition) }+ fab!(:shared_drafts_category) { Fabricate(:category_with_definition) }fab!(:topic) { Fabricate(:topic, category: shared_drafts_category) }fab!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) }fab!(:admin) { Fabricate(:admin) }diff --git a/spec/fabricators/category_fabricator.rb b/spec/fabricators/category_fabricator.rbindex 450f7987ee2..0bf66a2cdf7 100644--- a/spec/fabricators/category_fabricator.rb+++ b/spec/fabricators/category_fabricator.rb@@ -2,9 +2,14 @@Fabricator(:category) doname { sequence(:name) { |n| "Amazing Category #{n}" } }+ skip_category_definition trueuserend+Fabricator(:category_with_definition, from: :category) do+ skip_category_definition false+end+Fabricator(:diff_category, from: :category) doname "Different Category"user@@ -28,6 +33,9 @@ Fabricator(:private_category, from: :category) doendend+Fabricator(:private_category_with_definition, from: :private_category) do+ skip_category_definition false+endFabricator(:link_category, from: :category) dobefore_validation { |category, transients| category.topic_featured_link_allowed = true }enddiff --git a/spec/models/category_list_spec.rb b/spec/models/category_list_spec.rbindex 93bee278a00..85f4507894c 100644--- a/spec/models/category_list_spec.rb+++ b/spec/models/category_list_spec.rb@@ -16,7 +16,7 @@ describe CategoryList docontext "security" doit "properly hide secure categories" do- cat = Fabricate(:category)+ cat = Fabricate(:category_with_definition)Fabricate(:topic, category: cat)cat.set_permissions(admins: :full)cat.save@@ -28,15 +28,15 @@ describe CategoryList doendit "doesn't show topics that you can't view" do- public_cat = Fabricate(:category) # public category+ public_cat = Fabricate(:category_with_definition) # public categoryFabricate(:topic, category: public_cat)- private_cat = Fabricate(:category) # private category+ private_cat = Fabricate(:category_with_definition) # private categoryFabricate(:topic, category: private_cat)private_cat.set_permissions(admins: :full)private_cat.save- secret_subcat = Fabricate(:category, parent_category_id: public_cat.id) # private subcategory+ secret_subcat = Fabricate(:category_with_definition, parent_category_id: public_cat.id) # private subcategoryFabricate(:topic, category: secret_subcat)secret_subcat.set_permissions(admins: :full)secret_subcat.save@@ -54,7 +54,7 @@ describe CategoryList doendit "properly hide muted categories" do- cat_muted = Fabricate(:category)+ cat_muted = Fabricate(:category_with_definition)CategoryUser.create!(user_id: user.id,category_id: cat_muted.id,notification_level: CategoryUser.notification_levels[:muted])@@ -67,7 +67,7 @@ describe CategoryList docontext "with a category" do- fab!(:topic_category) { Fabricate(:category, num_featured_topics: 2) }+ fab!(:topic_category) { Fabricate(:category_with_definition, num_featured_topics: 2) }context "with a topic in a category" dolet(:topic) { Fabricate(:topic, category: topic_category) }@@ -146,16 +146,16 @@ describe CategoryList doendit "returns categories in specified order" do- cat1 = Fabricate(:category, position: 1)- cat2 = Fabricate(:category, position: 0)+ cat1 = Fabricate(:category_with_definition, position: 1)+ cat2 = Fabricate(:category_with_definition, position: 0)expect(category_ids_admin).to eq([cat2.id, cat1.id])endit "handles duplicate position values" do- cat1 = Fabricate(:category, position: 0)- cat2 = Fabricate(:category, position: 0)- cat3 = Fabricate(:category, position: nil)- cat4 = Fabricate(:category, position: 0)+ cat1 = Fabricate(:category_with_definition, position: 0)+ cat2 = Fabricate(:category_with_definition, position: 0)+ cat3 = Fabricate(:category_with_definition, position: nil)+ cat4 = Fabricate(:category_with_definition, position: 0)first_three = category_ids_admin[0, 3] # The order is not deterministicexpect(first_three).to include(cat1.id)expect(first_three).to include(cat2.id)@@ -170,11 +170,11 @@ describe CategoryList doendit "returns categories in order of activity" do- cat1 = Fabricate(:category, position: 0)- cat2 = Fabricate(:category, position: 1)- cat3 = Fabricate(:category, position: 2)- cat4 = Fabricate(:category, position: 3)- cat5 = Fabricate(:category, parent_category_id: cat2.id)+ cat1 = Fabricate(:category_with_definition, position: 0)+ cat2 = Fabricate(:category_with_definition, position: 1)+ cat3 = Fabricate(:category_with_definition, position: 2)+ cat4 = Fabricate(:category_with_definition, position: 3)+ cat5 = Fabricate(:category_with_definition, parent_category_id: cat2.id)Fabricate(:topic, category_id: cat3.id, bumped_at: 1.minutes.ago)Fabricate(:topic, category_id: cat5.id, bumped_at: 2.minutes.ago)@@ -187,16 +187,16 @@ describe CategoryList doendit "returns categories in order of id when there's no activity" do- cat1 = Fabricate(:category, position: 2)- cat2 = Fabricate(:category, position: 1)- cat3 = Fabricate(:category, position: 0)+ cat1 = Fabricate(:category_with_definition, position: 2)+ cat2 = Fabricate(:category_with_definition, position: 1)+ cat3 = Fabricate(:category_with_definition, position: 0)expect(category_ids_admin).to eq([cat1.id, cat2.id, cat3.id])endit "shows correct order when a topic in a private category is bumped" do- public_cat = Fabricate(:category)- public_cat2 = Fabricate(:category)- sub_cat_private = Fabricate(:category, parent_category_id: public_cat2.id)+ public_cat = Fabricate(:category_with_definition)+ public_cat2 = Fabricate(:category_with_definition)+ sub_cat_private = Fabricate(:category_with_definition, parent_category_id: public_cat2.id)sub_cat_private.set_permissions(admins: :full)sub_cat_private.savediff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rbindex 8d1b49621c4..c660a6bd6b3 100644--- a/spec/models/category_spec.rb+++ b/spec/models/category_spec.rb@@ -11,7 +11,7 @@ describe Category doit { is_expected.to validate_presence_of :name }it 'validates uniqueness of name' do- Fabricate(:category)+ Fabricate(:category_with_definition)is_expected.to validate_uniqueness_of(:name).scoped_to(:parent_category_id).case_insensitiveend@@ -27,7 +27,7 @@ describe Category doendit 'validates uniqueness in case insensitive way' do- Fabricate(:category, name: "Cats")+ Fabricate(:category_with_definition, name: "Cats")cats = Fabricate.build(:category, name: "cats")expect(cats).to_not be_validexpect(cats.errors[:name]).to be_present@@ -44,7 +44,7 @@ describe Category dodescribe "permissions_params" doit "returns the right group names and permission type" do- category = Fabricate(:category)+ category = Fabricate(:category_with_definition)group = Fabricate(:group)category_group = Fabricate(:category_group, category: category, group: group)expect(category.permissions_params).to eq("#{group.name}" => category_group.permission_type)@@ -53,7 +53,7 @@ describe Category dodescribe "#review_group_id" dofab!(:group) { Fabricate(:group) }- fab!(:category) { Fabricate(:category, reviewable_by_group: group) }+ fab!(:category) { Fabricate(:category_with_definition, reviewable_by_group: group) }fab!(:topic) { Fabricate(:topic, category: category) }fab!(:post) { Fabricate(:post, topic: topic) }fab!(:user) { Fabricate(:user) }@@ -108,24 +108,24 @@ describe Category dofab!(:admin) { Fabricate(:admin) }- fab!(:default_category) { Fabricate(:category) }+ fab!(:default_category) { Fabricate(:category_with_definition) }fab!(:full_category) do- c = Fabricate(:category)+ c = Fabricate(:category_with_definition)c.set_permissions(group => :full)c.savecendfab!(:can_post_category) do- c = Fabricate(:category)+ c = Fabricate(:category_with_definition)c.set_permissions(group => :create_post)c.savecendfab!(:can_read_category) do- c = Fabricate(:category)+ c = Fabricate(:category_with_definition)c.set_permissions(group => :readonly)c.saveend@@ -193,8 +193,8 @@ describe Category doenddescribe "security" do- fab!(:category) { Fabricate(:category) }- fab!(:category_2) { Fabricate(:category) }+ fab!(:category) { Fabricate(:category_with_definition) }+ fab!(:category_2) { Fabricate(:category_with_definition) }fab!(:user) { Fabricate(:user) }fab!(:group) { Fabricate(:group) }@@ -234,23 +234,23 @@ describe Category doendit "strips leading blanks" do- expect(Fabricate(:category, name: " music").name).to eq("music")+ expect(Fabricate(:category_with_definition, name: " music").name).to eq("music")endit "strips trailing blanks" do- expect(Fabricate(:category, name: "bugs ").name).to eq("bugs")+ expect(Fabricate(:category_with_definition, name: "bugs ").name).to eq("bugs")endit "strips leading and trailing blanks" do- expect(Fabricate(:category, name: " blanks ").name).to eq("blanks")+ expect(Fabricate(:category_with_definition, name: " blanks ").name).to eq("blanks")endit "sets name_lower" do- expect(Fabricate(:category, name: "Not MySQL").name_lower).to eq("not mysql")+ expect(Fabricate(:category_with_definition, name: "Not MySQL").name_lower).to eq("not mysql")endit "has custom fields" do- category = Fabricate(:category, name: " music")+ category = Fabricate(:category_with_definition, name: " music")expect(category.custom_fields["a"]).to be_nilcategory.custom_fields["bob"] = "marley"@@ -262,7 +262,7 @@ describe Category doenddescribe "short name" do- fab!(:category) { Fabricate(:category, name: 'xx') }+ fab!(:category) { Fabricate(:category_with_definition, name: 'xx') }it "creates the category" doexpect(category).to be_present@@ -277,7 +277,7 @@ describe Category docontext 'uses ascii slug generator' dobefore doSiteSetting.slug_generation_method = 'ascii'- @category = Fabricate(:category, name: "测试")+ @category = Fabricate(:category_with_definition, name: "测试")endafter { @category.destroy }@@ -290,7 +290,7 @@ describe Category docontext 'uses none slug generator' dobefore doSiteSetting.slug_generation_method = 'none'- @category = Fabricate(:category, name: "测试")+ @category = Fabricate(:category_with_definition, name: "测试")endafter doSiteSetting.slug_generation_method = 'ascii'@@ -306,7 +306,7 @@ describe Category docontext 'uses encoded slug generator' dobefore doSiteSetting.slug_generation_method = 'encoded'- @category = Fabricate(:category, name: "测试")+ @category = Fabricate(:category_with_definition, name: "测试")endafter doSiteSetting.slug_generation_method = 'ascii'@@ -331,8 +331,8 @@ describe Category dodescribe 'custom slug can be provided' doit 'can be sanitized' do- @c = Fabricate(:category, name: "Fun Cats", slug: "fun-cats")- @cat = Fabricate(:category, name: "love cats", slug: "love-cats")+ @c = Fabricate(:category_with_definition, name: "Fun Cats", slug: "fun-cats")+ @cat = Fabricate(:category_with_definition, name: "love cats", slug: "love-cats")@c.slug = ' invalid slug'@c.save@@ -363,7 +363,7 @@ describe Category dodescribe 'after create' dobefore do- @category = Fabricate(:category, name: 'Amazing Category')+ @category = Fabricate(:category_with_definition, name: 'Amazing Category')@topic = @category.topicend@@ -422,21 +422,21 @@ describe Category doendit "creates permalink when sub category slug is changed" do- sub_category = Fabricate(:category, slug: 'sub-category', parent_category_id: @category.id)+ sub_category = Fabricate(:category_with_definition, slug: 'sub-category', parent_category_id: @category.id)sub_category.update(slug: 'new-sub-category')expect(Permalink.count).to eq(1)endit "deletes permalink when category slug is reused" doFabricate(:permalink, url: "/c/bikeshed-category")- Fabricate(:category, slug: 'bikeshed-category')+ Fabricate(:category_with_definition, slug: 'bikeshed-category')expect(Permalink.count).to eq(0)endit "deletes permalink when sub category slug is reused" doFabricate(:permalink, url: "/c/main-category/sub-category")- main_category = Fabricate(:category, slug: 'main-category')- Fabricate(:category, slug: 'sub-category', parent_category_id: main_category.id)+ main_category = Fabricate(:category_with_definition, slug: 'main-category')+ Fabricate(:category_with_definition, slug: 'sub-category', parent_category_id: main_category.id)expect(Permalink.count).to eq(0)end@@ -450,20 +450,20 @@ describe Category doendit "should not set its description topic to auto-close" do- category = Fabricate(:category, name: 'Closing Topics', auto_close_hours: 1)+ category = Fabricate(:category_with_definition, name: 'Closing Topics', auto_close_hours: 1)expect(category.topic.public_topic_timer).to eq(nil)enddescribe "creating a new category with the same slug" doit "should have a blank slug if at the same level" do- category = Fabricate(:category, name: "Amazing Categóry")+ category = Fabricate(:category_with_definition, name: "Amazing Categóry")expect(category.slug).to be_blankexpect(category.slug_for_url).to eq("#{category.id}-category")endit "doesn't have a blank slug if not at the same level" do- parent = Fabricate(:category, name: 'Other parent')- category = Fabricate(:category, name: "Amazing Categóry", parent_category_id: parent.id)+ parent = Fabricate(:category_with_definition, name: 'Other parent')+ category = Fabricate(:category_with_definition, name: "Amazing Categóry", parent_category_id: parent.id)expect(category.slug).to eq('amazing-category')expect(category.slug_for_url).to eq("amazing-category")end@@ -471,7 +471,7 @@ describe Category dodescribe "trying to change the category topic's category" dobefore do- @new_cat = Fabricate(:category, name: '2nd Category', user: @category.user)+ @new_cat = Fabricate(:category_with_definition, name: '2nd Category', user: @category.user)@topic.change_category_to_id(@new_cat.id)@topic.reload@category.reload@@ -498,8 +498,8 @@ describe Category dodescribe "update" doit "should enforce uniqueness of slug" do- Fabricate(:category, slug: "the-slug")- c2 = Fabricate(:category, slug: "different-slug")+ Fabricate(:category_with_definition, slug: "the-slug")+ c2 = Fabricate(:category_with_definition, slug: "different-slug")c2.slug = "the-slug"expect(c2).to_not be_validexpect(c2.errors[:slug]).to be_present@@ -508,7 +508,7 @@ describe Category dodescribe 'destroy' dobefore do- @category = Fabricate(:category)+ @category = Fabricate(:category_with_definition)@category_id = @category.id@topic_id = @category.topic_idSiteSetting.shared_drafts_category = @category.id.to_s@@ -531,7 +531,7 @@ describe Category dodescribe 'latest' doit 'should be updated correctly' do- category = Fabricate(:category)+ category = Fabricate(:category_with_definition)post = create_post(category: category.id)category.reload@@ -557,7 +557,7 @@ describe Category dodescribe 'update_stats' dobefore do- @category = Fabricate(:category)+ @category = Fabricate(:category_with_definition)endcontext 'with regular topics' do@@ -642,29 +642,35 @@ describe Category dodescribe "#url" doit "builds a url for normal categories" do- category = Fabricate(:category, name: "cats")+ category = Fabricate(:category_with_definition, name: "cats")expect(category.url).to eq "/c/cats"enddescribe "for subcategories" doit "includes the parent category" do- parent_category = Fabricate(:category, name: "parent")- subcategory = Fabricate(:category, name: "child",- parent_category_id: parent_category.id)+ parent_category = Fabricate(:category_with_definition, name: "parent")++ subcategory =+ Fabricate(+ :category_with_definition,+ name: "child",+ parent_category_id: parent_category.id+ )+expect(subcategory.url).to eq "/c/parent/child"endendenddescribe "#url_with_id" do- fab!(:category) { Fabricate(:category, name: 'cats') }+ fab!(:category) { Fabricate(:category_with_definition, name: 'cats') }it "includes the id in the URL" doexpect(category.url_with_id).to eq("/c/#{category.id}-cats")endcontext "child category" do- fab!(:child_category) { Fabricate(:category, parent_category_id: category.id, name: 'dogs') }+ fab!(:child_category) { Fabricate(:category_with_definition, parent_category_id: category.id, name: 'dogs') }it "includes the id in the URL" doexpect(child_category.url_with_id).to eq("/c/cats/dogs/#{child_category.id}")@@ -680,14 +686,14 @@ describe Category doendit "cannot have a parent category" do- cat.parent_category_id = Fabricate(:category).id+ cat.parent_category_id = Fabricate(:category_with_definition).idexpect(cat).to_not be_validendenddescribe "parent categories" dofab!(:user) { Fabricate(:user) }- fab!(:parent_category) { Fabricate(:category, user: user) }+ fab!(:parent_category) { Fabricate(:category_with_definition, user: user) }it "can be associated with a parent category" dosub_category = Fabricate.build(:category, parent_category_id: parent_category.id, user: user)@@ -696,13 +702,13 @@ describe Category doendit "cannot associate a category with itself" do- category = Fabricate(:category, user: user)+ category = Fabricate(:category_with_definition, user: user)category.parent_category_id = category.idexpect(category).to_not be_validendit "cannot have a category two levels deep" do- sub_category = Fabricate(:category, parent_category_id: parent_category.id, user: user)+ sub_category = Fabricate(:category_with_definition, parent_category_id: parent_category.id, user: user)nested_sub_category = Fabricate.build(:category, parent_category_id: sub_category.id, user: user)expect(nested_sub_category).to_not be_validend@@ -716,7 +722,7 @@ describe Category dodescribe ".query_category" doit "should return the category" do- category = Fabricate(:category, name: "Amazing Category", parent_category_id: parent_category.id, user: user)+ category = Fabricate(:category_with_definition, name: "Amazing Category", parent_category_id: parent_category.id, user: user)parent_category.name = "Amazing Parent Category"expect(category).to eq(Category.query_category(category.slug, parent_category.id))end@@ -726,9 +732,9 @@ describe Category dodescribe "find_by_email" doit "is case insensitive" do- c1 = Fabricate(:category, email_in: '[email protected]')- c2 = Fabricate(:category, email_in: '[email protected]')- c3 = Fabricate(:category, email_in: '[email protected]')+ c1 = Fabricate(:category_with_definition, email_in: '[email protected]')+ c2 = Fabricate(:category_with_definition, email_in: '[email protected]')+ c3 = Fabricate(:category_with_definition, email_in: '[email protected]')expect(Category.find_by_email('[email protected]')).to eq(c1)expect(Category.find_by_email('[email protected]')).to eq(c2)expect(Category.find_by_email('[email protected]')).to eq(c3)@@ -738,8 +744,8 @@ describe Category dodescribe "find_by_slug" doit "finds with category and sub category" do- category = Fabricate(:category, slug: 'awesome-category')- sub_category = Fabricate(:category, parent_category_id: category.id, slug: 'awesome-sub-category')+ category = Fabricate(:category_with_definition, slug: 'awesome-category')+ sub_category = Fabricate(:category_with_definition, parent_category_id: category.id, slug: 'awesome-sub-category')expect(Category.find_by_slug('awesome-category')).to eq(category)expect(Category.find_by_slug('awesome-sub-category', 'awesome-category')).to eq(sub_category)@@ -769,7 +775,7 @@ describe Category doendcontext "with duplicate email in a category" do- fab!(:category) { Fabricate(:category, user: user, name: '<b>cool</b>', email_in: '[email protected]') }+ fab!(:category) { Fabricate(:category_with_definition, user: user, name: '<b>cool</b>', email_in: '[email protected]') }it "adds an error with an invalid email" docategory = Category.new(name: 'test', user: user, email_in: "[email protected]")@@ -781,7 +787,7 @@ describe Category doenddescribe 'require topic/post approval' do- fab!(:category) { Fabricate(:category) }+ fab!(:category) { Fabricate(:category_with_definition) }describe '#require_topic_approval?' dobefore do@@ -809,7 +815,7 @@ describe Category doit 'should correctly automatically bump topics' dofreeze_time 1.second.ago- category = Fabricate(:category)+ category = Fabricate(:category_with_definition)category.clear_auto_bump_cache!freeze_time 1.second.from_now@@ -863,9 +869,9 @@ describe Category dofab!(:admin) { Fabricate(:admin) }fab!(:group) { Fabricate(:group) }fab!(:group2) { Fabricate(:group) }- fab!(:parent_category) { Fabricate(:category, name: "parent") }- fab!(:subcategory) { Fabricate(:category, name: "child1", parent_category_id: parent_category.id) }- fab!(:subcategory2) { Fabricate(:category, name: "child2", parent_category_id: parent_category.id) }+ fab!(:parent_category) { Fabricate(:category_with_definition, name: "parent") }+ fab!(:subcategory) { Fabricate(:category_with_definition, name: "child1", parent_category_id: parent_category.id) }+ fab!(:subcategory2) { Fabricate(:category_with_definition, name: "child2", parent_category_id: parent_category.id) }context "when changing subcategory permissions" doit "it is not valid if permissions are less restrictive" do@@ -943,9 +949,9 @@ describe Category do# make stuff extra brokenuncategorized.topic.trash!- category = Fabricate(:category)- category_destroyed = Fabricate(:category)- category_trashed = Fabricate(:category)+ category = Fabricate(:category_with_definition)+ category_destroyed = Fabricate(:category_with_definition)+ category_trashed = Fabricate(:category_with_definition)category_topic_id = category.topic.idcategory_destroyed.topic.destroy!diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rbindex f2e78a2d62b..64d0fb63de7 100644--- a/spec/models/report_spec.rb+++ b/spec/models/report_spec.rb@@ -3,9 +3,9 @@require 'rails_helper'describe Report do- let(:c0) { Fabricate(:category, skip_category_definition: true) } # id: 3- let(:c1) { Fabricate(:category, parent_category: c0, skip_category_definition: true) } # id: 2- let(:c2) { Fabricate(:category, skip_category_definition: true) } # id: 4+ let(:c0) { Fabricate(:category) } # id: 3+ let(:c1) { Fabricate(:category, parent_category: c0) } # id: 2+ let(:c2) { Fabricate(:category) } # id: 4shared_examples 'no data' docontext "with no data" dodiff --git a/spec/models/reviewable_flagged_post_spec.rb b/spec/models/reviewable_flagged_post_spec.rbindex 5323efcc41a..7df51b115f5 100644--- a/spec/models/reviewable_flagged_post_spec.rb+++ b/spec/models/reviewable_flagged_post_spec.rb@@ -46,7 +46,7 @@ RSpec.describe ReviewableFlaggedPost, type: :model doendit "doesn't include deletes for category topics" do- c = Fabricate(:category)+ c = Fabricate(:category_with_definition)flag = PostActionCreator.spam(user, c.topic.posts.first).reviewableactions = flag.actions_for(guardian)expect(actions.has?(:delete_and_ignore)).to eq(false)diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rbindex 26dda3fb468..7b35b38eea7 100644--- a/spec/models/topic_spec.rb+++ b/spec/models/topic_spec.rb@@ -414,7 +414,7 @@ describe Topic doendcontext 'category validation' do- fab!(:category) { Fabricate(:category) }+ fab!(:category) { Fabricate(:category_with_definition) }context 'allow_uncategorized_topics is false' dobefore do@@ -459,7 +459,7 @@ describe Topic doendcontext "with a category definition" do- let!(:category) { Fabricate(:category) }+ let!(:category) { Fabricate(:category_with_definition) }it "excludes the category definition topic from similar_to" doexpect(Topic.similar_to('category definition for', "no body")).to be_blank@@ -478,7 +478,7 @@ describe Topic doendcontext "secure categories" do- fab!(:category) { Fabricate(:category, read_restricted: true) }+ fab!(:category) { Fabricate(:category_with_definition, read_restricted: true) }before dotopic.category = category@@ -680,7 +680,7 @@ describe Topic dofab!(:group) { Fabricate(:group) }fab!(:category) do- Fabricate(:category, groups: [group]).tap do |category|+ Fabricate(:category_with_definition, groups: [group]).tap do |category|category.set_permissions(group => :full)category.save!end@@ -1171,7 +1171,7 @@ describe Topic dodescribe 'with category' dobefore do- @category = Fabricate(:category)+ @category = Fabricate(:category_with_definition)endit "should not increase the topic_count with no category" do@@ -1259,7 +1259,7 @@ describe Topic dodescribe '#change_category_to_id' dofab!(:topic) { Fabricate(:topic) }fab!(:user) { topic.user }- fab!(:category) { Fabricate(:category, user: user) }+ fab!(:category) { Fabricate(:category_with_definition, user: user) }describe 'without a previous category' doit 'changes the category' do@@ -1303,7 +1303,7 @@ describe Topic doenddescribe 'to a different category' do- fab!(:new_category) { Fabricate(:category, user: user, name: '2nd category') }+ fab!(:new_category) { Fabricate(:category_with_definition, user: user, name: '2nd category') }it 'should work' dotopic.change_category_to_id(new_category.id)@@ -1416,7 +1416,7 @@ describe Topic doSiteSetting.allow_uncategorized_topics = falseend- let!(:topic) { Fabricate(:topic, category: Fabricate(:category)) }+ let!(:topic) { Fabricate(:topic, category: Fabricate(:category_with_definition)) }it 'returns false' doexpect(topic.change_category_to_id(nil)).to eq(false) # don't use "== false" here because it would also match nil@@ -1480,9 +1480,9 @@ describe Topic dodescribe '#in_category_and_subcategories' doit 'returns topics in a category and its subcategories' do- c1 = Fabricate(:category)- c2 = Fabricate(:category, parent_category_id: c1.id)- c3 = Fabricate(:category)+ c1 = Fabricate(:category_with_definition)+ c2 = Fabricate(:category_with_definition, parent_category_id: c1.id)+ c3 = Fabricate(:category_with_definition)t1 = Fabricate(:topic, user: user, category_id: c1.id)t2 = Fabricate(:topic, user: user, category_id: c2.id)@@ -1640,7 +1640,7 @@ describe Topic doenddescribe "when category's default auto close is set" do- let(:category) { Fabricate(:category, auto_close_hours: 4) }+ let(:category) { Fabricate(:category_with_definition, auto_close_hours: 4) }let(:topic) { Fabricate(:topic, category: category) }it "should be able to override category's default auto close" do@@ -1705,7 +1705,7 @@ describe Topic doendit "doesn't return category topics" do- Fabricate(:category)+ Fabricate(:category_with_definition)expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blankend@@ -1716,7 +1716,7 @@ describe Topic doit "doesn't return topics from muted categories" douser = Fabricate(:user)- category = Fabricate(:category)+ category = Fabricate(:category_with_definition)Fabricate(:topic, category: category)CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id)@@ -1739,7 +1739,7 @@ describe Topic doit "doesn't return topics from suppressed categories" douser = Fabricate(:user)- category = Fabricate(:category)+ category = Fabricate(:category_with_definition)Fabricate(:topic, category: category)SiteSetting.digest_suppress_categories = "#{category.id}"@@ -1802,7 +1802,7 @@ describe Topic doendit "sorts by category notification levels" do- category1, category2 = Fabricate(:category), Fabricate(:category)+ category1, category2 = Fabricate(:category_with_definition), Fabricate(:category_with_definition)2.times { |i| Fabricate(:topic, category: category1) }topic1 = Fabricate(:topic, category: category2)2.times { |i| Fabricate(:topic, category: category1) }@@ -1837,12 +1837,12 @@ describe Topic dodescribe '.secured' doit 'should return the right topics' do- category = Fabricate(:category, read_restricted: true)+ category = Fabricate(:category_with_definition, read_restricted: true)topic = Fabricate(:topic, category: category, created_at: 1.day.ago)group = Fabricate(:group)user = Fabricate(:user)group.add(user)- private_category = Fabricate(:private_category, group: group)+ private_category = Fabricate(:private_category_with_definition, group: group)expect(Topic.secured(Guardian.new(nil))).to eq([])@@ -1941,7 +1941,7 @@ describe Topic dodescribe 'trash!' docontext "its category's topic count" dofab!(:moderator) { Fabricate(:moderator) }- fab!(:category) { Fabricate(:category) }+ fab!(:category) { Fabricate(:category_with_definition) }it "subtracts 1 if topic is being deleted" dotopic = Fabricate(:topic, category: category)@@ -1966,7 +1966,7 @@ describe Topic dodescribe 'recover!' docontext "its category's topic count" do- fab!(:category) { Fabricate(:category) }+ fab!(:category) { Fabricate(:category_with_definition) }it "adds 1 if topic is deleted" dotopic = Fabricate(:topic, category: category, deleted_at: 1.day.ago)@@ -2195,7 +2195,7 @@ describe Topic doendit 'can not save the featured link if category does not allow it' do- topic.category = Fabricate(:category, topic_featured_link_allowed: false)+ topic.category = Fabricate(:category_with_definition, topic_featured_link_allowed: false)topic.featured_link = 'https://github.com/discourse/discourse'expect(topic.save).to be_falseyend@@ -2424,7 +2424,7 @@ describe Topic dog.save!endend- let(:category) { Fabricate(:category) }+ let(:category) { Fabricate(:category_with_definition) }let(:topic) { Fabricate(:topic, category: category) }it "returns a group that is open or accepts membership requests and has access to the topic" dodiff --git a/spec/models/user_search_spec.rb b/spec/models/user_search_spec.rbindex 582a0b9bc15..2c1fb83f783 100644--- a/spec/models/user_search_spec.rb+++ b/spec/models/user_search_spec.rb@@ -33,15 +33,12 @@ describe UserSearch dogroup.add(user)group.save- category = Fabricate.build(- :category,- read_restricted: true,- user: user- )- # TODO: maybe we amend all category fabrication to skip this?- # test is half a second faster- category.skip_category_definition = true- category.save!+ category =+ Fabricate(+ :category,+ read_restricted: true,+ user: user+ )Fabricate(:category_group, category: category, group: group)diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rbindex 22869f1388b..8bacb833248 100644--- a/spec/requests/admin/users_controller_spec.rb+++ b/spec/requests/admin/users_controller_spec.rb@@ -186,7 +186,7 @@ RSpec.describe Admin::UsersController doendit "won't delete a category topic" do- c = Fabricate(:category)+ c = Fabricate(:category_with_definition)cat_post = c.topic.posts.firstput("/admin/users/#{user.id}/suspend.json",@@ -201,7 +201,7 @@ RSpec.describe Admin::UsersController doendit "won't delete a category topic by replies" do- c = Fabricate(:category)+ c = Fabricate(:category_with_definition)cat_post = c.topic.posts.firstput("/admin/users/#{user.id}/suspend.json",diff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rbindex 7f85be92835..0b3c93e73a5 100644--- a/spec/requests/list_controller_spec.rb+++ b/spec/requests/list_controller_spec.rb@@ -341,7 +341,7 @@ RSpec.describe ListController dodescribe 'category' docontext 'in a category' do- let(:category) { Fabricate(:category) }+ let(:category) { Fabricate(:category_with_definition) }let(:group) { Fabricate(:group) }let(:private_category) { Fabricate(:private_category, group: group) }@@ -367,7 +367,7 @@ RSpec.describe ListController doendcontext 'with a link that has a parent slug, slug and id in its path' do- let(:child_category) { Fabricate(:category, parent_category: category) }+ let(:child_category) { Fabricate(:category_with_definition, parent_category: category) }context "with valid slug" doit "redirects to the child category" do@@ -390,7 +390,7 @@ RSpec.describe ListController docontext 'another category exists with a number at the beginning of its name' do# One category has another category's id at the beginning of its name- let!(:other_category) { Fabricate(:category, name: "#{category.id} name") }+ let!(:other_category) { Fabricate(:category_with_definition, name: "#{category.id} name") }it 'uses the correct category' doget "/c/#{other_category.slug}/l/latest.json"@@ -402,7 +402,7 @@ RSpec.describe ListController doendcontext 'a child category' do- let(:sub_category) { Fabricate(:category, parent_category_id: category.id) }+ let(:sub_category) { Fabricate(:category_with_definition, parent_category_id: category.id) }context 'when parent and child are requested' doit "succeeds" do@@ -485,7 +485,7 @@ RSpec.describe ListController doendcontext "renders correct title" do- let!(:amazing_category) { Fabricate(:category, name: "Amazing Category") }+ let!(:amazing_category) { Fabricate(:category_with_definition, name: "Amazing Category") }it 'for category default view' doget "/c/#{amazing_category.slug}"@@ -623,11 +623,11 @@ RSpec.describe ListController doenddescribe "categories suppression" do- let(:category_one) { Fabricate(:category) }- let(:sub_category) { Fabricate(:category, parent_category: category_one, suppress_from_latest: true) }+ let(:category_one) { Fabricate(:category_with_definition) }+ let(:sub_category) { Fabricate(:category_with_definition, parent_category: category_one, suppress_from_latest: true) }let!(:topic_in_sub_category) { Fabricate(:topic, category: sub_category) }- let(:category_two) { Fabricate(:category, suppress_from_latest: true) }+ let(:category_two) { Fabricate(:category_with_definition, suppress_from_latest: true) }let!(:topic_in_category_two) { Fabricate(:topic, category: category_two) }it "suppresses categories from the latest list" dodiff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex d46e89ac96b..864931ef12e 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -2080,9 +2080,8 @@ RSpec.describe TopicsController doendit "can mark sub-categories unread" do- # TODO do we want to skip category definition by default in fabricator- category = Fabricate(:category, skip_category_definition: true)- sub = Fabricate(:category, parent_category_id: category.id, skip_category_definition: true)+ category = Fabricate(:category)+ sub = Fabricate(:category, parent_category_id: category.id)topic.update!(category_id: sub.id)diff --git a/spec/services/destroy_task_spec.rb b/spec/services/destroy_task_spec.rbindex 9d81aa2c46f..5d41a73d0cc 100644--- a/spec/services/destroy_task_spec.rb+++ b/spec/services/destroy_task_spec.rb@@ -5,13 +5,13 @@ require 'rails_helper'describe DestroyTask dodescribe 'destroy topics' do- fab!(:c) { Fabricate(:category) }+ fab!(:c) { Fabricate(:category_with_definition) }fab!(:t) { Fabricate(:topic, category: c) }let!(:p) { Fabricate(:post, topic: t) }- fab!(:c2) { Fabricate(:category) }+ fab!(:c2) { Fabricate(:category_with_definition) }fab!(:t2) { Fabricate(:topic, category: c2) }let!(:p2) { Fabricate(:post, topic: t2) }- fab!(:sc) { Fabricate(:category, parent_category: c2) }+ fab!(:sc) { Fabricate(:category_with_definition, parent_category: c2) }fab!(:t3) { Fabricate(:topic, category: sc) }let!(:p3) { Fabricate(:post, topic: t3) }@@ -41,13 +41,13 @@ describe DestroyTask doenddescribe 'destroy categories' do- fab!(:c) { Fabricate(:category) }+ fab!(:c) { Fabricate(:category_with_definition) }fab!(:t) { Fabricate(:topic, category: c) }let!(:p) { Fabricate(:post, topic: t) }- fab!(:c2) { Fabricate(:category) }+ fab!(:c2) { Fabricate(:category_with_definition) }fab!(:t2) { Fabricate(:topic, category: c) }let!(:p2) { Fabricate(:post, topic: t2) }- fab!(:sc) { Fabricate(:category, parent_category: c2) }+ fab!(:sc) { Fabricate(:category_with_definition, parent_category: c2) }fab!(:t3) { Fabricate(:topic, category: sc) }let!(:p3) { Fabricate(:post, topic: t3) }diff --git a/spec/services/user_destroyer_spec.rb b/spec/services/user_destroyer_spec.rbindex af7596a2ec1..3b89b47db78 100644--- a/spec/services/user_destroyer_spec.rb+++ b/spec/services/user_destroyer_spec.rb@@ -313,7 +313,7 @@ describe UserDestroyer doendcontext 'user created a category' do- let!(:category) { Fabricate(:category, user: @user) }+ let!(:category) { Fabricate(:category_with_definition, user: @user) }it "assigns the system user to the categories" doUserDestroyer.new(@admin).destroy(@user, delete_posts: true)