DEV: Default to skipping creating a topic when fabricating categories (#7976)

This speeds up the test suite by 9%
This commit is contained in:
Daniel Waterworth 2019-08-06 11:26:54 +01:00 committed by GitHub
parent dbb410697e
commit 4ae8065f2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 178 additions and 169 deletions

View File

@ -13,7 +13,7 @@ describe Search do
context 'post indexing observer' do
before 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 do
context 'category indexing observer' do
before do
@category = Fabricate(:category, name: 'america')
@category = Fabricate(:category_with_definition, name: 'america')
@indexed = @category.category_search_data.search_data
end
@ -397,7 +397,7 @@ describe Search do
end
it '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 do
end
it 'secures results correctly' do
category = Fabricate(:category)
category = Fabricate(:category_with_definition)
topic.category_id = category.id
topic.save
@ -532,12 +532,12 @@ describe Search do
end
context '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 do
describe "with child categories" do
let!(: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 do
end
describe 'categories with different priorities' do
let(:category2) { Fabricate(:category) }
let(:category2) { Fabricate(:category_with_definition) }
it "should return posts in the right order" do
raw = "The pure genuine evian"
@ -667,7 +667,7 @@ describe Search do
let!(: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' do
it 'can find posts with tags' do
@ -731,7 +731,7 @@ describe Search do
context 'type_filter' do
let!(:user) { Fabricate(:user, username: 'amazing', email: 'amazing@amazing.com') }
let!(:category) { Fabricate(:category, name: 'amazing category', user: user) }
let!(:category) { Fabricate(:category_with_definition, name: 'amazing category', user: user) }
context 'user filter' do
let(:results) { Search.execute('amazing', type_filter: 'user') }
@ -773,7 +773,7 @@ describe Search do
end
it '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 do
topic_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 do
today = Date.today
yesterday = 1.day.ago
two_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 do
it '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 do
expect(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 do
end
it '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)

View File

@ -98,7 +98,7 @@ describe SuggestedTopicsBuilder do
end
context "category definition topics" do
fab!(:category) { Fabricate(:category) }
fab!(:category) { Fabricate(:category_with_definition) }
it "doesn't add a category definition topic" do
expect(category.topic_id).to be_present

View File

@ -19,7 +19,7 @@ describe TopicQuery do
context 'secure category' do
it "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 do
end
context '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" do
expect(TopicQuery.new(moderator).list_latest.topics.size).to eq(0)
@ -153,7 +152,7 @@ describe TopicQuery do
end
context '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" do
expect(TopicQuery.new(moderator, category: category.id).list_latest.topics.size).to eq(1)
@ -214,8 +213,8 @@ describe TopicQuery do
end
context "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" do
tagged_topic1 = Fabricate(:topic, category: category1, tags: [tag])
@ -231,7 +230,7 @@ describe TopicQuery do
context 'muted categories' do
it '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 do
end
context '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 do
fab!(:user3) { Fabricate(:user) }
fab!(:private_category) do
Fabricate(:private_category, group: group)
Fabricate(:private_category_with_definition, group: group)
end
let!(: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 do
end
context "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) }

View File

@ -2,9 +2,14 @@
Fabricator(:category) do
name { sequence(:name) { |n| "Amazing Category #{n}" } }
skip_category_definition true
user
end
Fabricator(:category_with_definition, from: :category) do
skip_category_definition false
end
Fabricator(:diff_category, from: :category) do
name "Different Category"
user
@ -28,6 +33,9 @@ Fabricator(:private_category, from: :category) do
end
end
Fabricator(:private_category_with_definition, from: :private_category) do
skip_category_definition false
end
Fabricator(:link_category, from: :category) do
before_validation { |category, transients| category.topic_featured_link_allowed = true }
end

View File

@ -16,7 +16,7 @@ describe CategoryList do
context "security" do
it "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 do
end
it "doesn't show topics that you can't view" do
public_cat = Fabricate(:category) # public category
public_cat = Fabricate(:category_with_definition) # public category
Fabricate(:topic, category: public_cat)
private_cat = Fabricate(:category) # private category
private_cat = Fabricate(:category_with_definition) # private category
Fabricate(: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 subcategory
Fabricate(:topic, category: secret_subcat)
secret_subcat.set_permissions(admins: :full)
secret_subcat.save
@ -54,7 +54,7 @@ describe CategoryList do
end
it "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 do
context "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" do
let(:topic) { Fabricate(:topic, category: topic_category) }
@ -146,16 +146,16 @@ describe CategoryList do
end
it "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])
end
it "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 deterministic
expect(first_three).to include(cat1.id)
expect(first_three).to include(cat2.id)
@ -170,11 +170,11 @@ describe CategoryList do
end
it "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 do
end
it "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])
end
it "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.save

View File

@ -11,7 +11,7 @@ describe Category do
it { 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_insensitive
end
@ -27,7 +27,7 @@ describe Category do
end
it '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_valid
expect(cats.errors[:name]).to be_present
@ -44,7 +44,7 @@ describe Category do
describe "permissions_params" do
it "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 do
describe "#review_group_id" do
fab!(: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 do
fab!(: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.save
c
end
fab!(:can_post_category) do
c = Fabricate(:category)
c = Fabricate(:category_with_definition)
c.set_permissions(group => :create_post)
c.save
c
end
fab!(:can_read_category) do
c = Fabricate(:category)
c = Fabricate(:category_with_definition)
c.set_permissions(group => :readonly)
c.save
end
@ -193,8 +193,8 @@ describe Category do
end
describe "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 do
end
it "strips leading blanks" do
expect(Fabricate(:category, name: " music").name).to eq("music")
expect(Fabricate(:category_with_definition, name: " music").name).to eq("music")
end
it "strips trailing blanks" do
expect(Fabricate(:category, name: "bugs ").name).to eq("bugs")
expect(Fabricate(:category_with_definition, name: "bugs ").name).to eq("bugs")
end
it "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")
end
it "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")
end
it "has custom fields" do
category = Fabricate(:category, name: " music")
category = Fabricate(:category_with_definition, name: " music")
expect(category.custom_fields["a"]).to be_nil
category.custom_fields["bob"] = "marley"
@ -262,7 +262,7 @@ describe Category do
end
describe "short name" do
fab!(:category) { Fabricate(:category, name: 'xx') }
fab!(:category) { Fabricate(:category_with_definition, name: 'xx') }
it "creates the category" do
expect(category).to be_present
@ -277,7 +277,7 @@ describe Category do
context 'uses ascii slug generator' do
before do
SiteSetting.slug_generation_method = 'ascii'
@category = Fabricate(:category, name: "测试")
@category = Fabricate(:category_with_definition, name: "测试")
end
after { @category.destroy }
@ -290,7 +290,7 @@ describe Category do
context 'uses none slug generator' do
before do
SiteSetting.slug_generation_method = 'none'
@category = Fabricate(:category, name: "测试")
@category = Fabricate(:category_with_definition, name: "测试")
end
after do
SiteSetting.slug_generation_method = 'ascii'
@ -306,7 +306,7 @@ describe Category do
context 'uses encoded slug generator' do
before do
SiteSetting.slug_generation_method = 'encoded'
@category = Fabricate(:category, name: "测试")
@category = Fabricate(:category_with_definition, name: "测试")
end
after do
SiteSetting.slug_generation_method = 'ascii'
@ -331,8 +331,8 @@ describe Category do
describe 'custom slug can be provided' do
it '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 do
describe 'after create' do
before do
@category = Fabricate(:category, name: 'Amazing Category')
@category = Fabricate(:category_with_definition, name: 'Amazing Category')
@topic = @category.topic
end
@ -422,21 +422,21 @@ describe Category do
end
it "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)
end
it "deletes permalink when category slug is reused" do
Fabricate(:permalink, url: "/c/bikeshed-category")
Fabricate(:category, slug: 'bikeshed-category')
Fabricate(:category_with_definition, slug: 'bikeshed-category')
expect(Permalink.count).to eq(0)
end
it "deletes permalink when sub category slug is reused" do
Fabricate(: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 do
end
it "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)
end
describe "creating a new category with the same slug" do
it "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_blank
expect(category.slug_for_url).to eq("#{category.id}-category")
end
it "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 do
describe "trying to change the category topic's category" do
before 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 do
describe "update" do
it "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_valid
expect(c2.errors[:slug]).to be_present
@ -508,7 +508,7 @@ describe Category do
describe 'destroy' do
before do
@category = Fabricate(:category)
@category = Fabricate(:category_with_definition)
@category_id = @category.id
@topic_id = @category.topic_id
SiteSetting.shared_drafts_category = @category.id.to_s
@ -531,7 +531,7 @@ describe Category do
describe 'latest' do
it '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 do
describe 'update_stats' do
before do
@category = Fabricate(:category)
@category = Fabricate(:category_with_definition)
end
context 'with regular topics' do
@ -642,29 +642,35 @@ describe Category do
describe "#url" do
it "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"
end
describe "for subcategories" do
it "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"
end
end
end
describe "#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" do
expect(category.url_with_id).to eq("/c/#{category.id}-cats")
end
context "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" do
expect(child_category.url_with_id).to eq("/c/cats/dogs/#{child_category.id}")
@ -680,14 +686,14 @@ describe Category do
end
it "cannot have a parent category" do
cat.parent_category_id = Fabricate(:category).id
cat.parent_category_id = Fabricate(:category_with_definition).id
expect(cat).to_not be_valid
end
end
describe "parent categories" do
fab!(: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" do
sub_category = Fabricate.build(:category, parent_category_id: parent_category.id, user: user)
@ -696,13 +702,13 @@ describe Category do
end
it "cannot associate a category with itself" do
category = Fabricate(:category, user: user)
category = Fabricate(:category_with_definition, user: user)
category.parent_category_id = category.id
expect(category).to_not be_valid
end
it "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_valid
end
@ -716,7 +722,7 @@ describe Category do
describe ".query_category" do
it "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 do
describe "find_by_email" do
it "is case insensitive" do
c1 = Fabricate(:category, email_in: 'lower@example.com')
c2 = Fabricate(:category, email_in: 'UPPER@EXAMPLE.COM')
c3 = Fabricate(:category, email_in: 'Mixed.Case@Example.COM')
c1 = Fabricate(:category_with_definition, email_in: 'lower@example.com')
c2 = Fabricate(:category_with_definition, email_in: 'UPPER@EXAMPLE.COM')
c3 = Fabricate(:category_with_definition, email_in: 'Mixed.Case@Example.COM')
expect(Category.find_by_email('LOWER@EXAMPLE.COM')).to eq(c1)
expect(Category.find_by_email('upper@example.com')).to eq(c2)
expect(Category.find_by_email('mixed.case@example.com')).to eq(c3)
@ -738,8 +744,8 @@ describe Category do
describe "find_by_slug" do
it "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 do
end
context "with duplicate email in a category" do
fab!(:category) { Fabricate(:category, user: user, name: '<b>cool</b>', email_in: 'test@example.com') }
fab!(:category) { Fabricate(:category_with_definition, user: user, name: '<b>cool</b>', email_in: 'test@example.com') }
it "adds an error with an invalid email" do
category = Category.new(name: 'test', user: user, email_in: "test@example.com")
@ -781,7 +787,7 @@ describe Category do
end
describe 'require topic/post approval' do
fab!(:category) { Fabricate(:category) }
fab!(:category) { Fabricate(:category_with_definition) }
describe '#require_topic_approval?' do
before do
@ -809,7 +815,7 @@ describe Category do
it 'should correctly automatically bump topics' do
freeze_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 do
fab!(: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" do
it "it is not valid if permissions are less restrictive" do
@ -943,9 +949,9 @@ describe Category do
# make stuff extra broken
uncategorized.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.id
category_destroyed.topic.destroy!

View File

@ -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: 4
shared_examples 'no data' do
context "with no data" do

View File

@ -46,7 +46,7 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
end
it "doesn't include deletes for category topics" do
c = Fabricate(:category)
c = Fabricate(:category_with_definition)
flag = PostActionCreator.spam(user, c.topic.posts.first).reviewable
actions = flag.actions_for(guardian)
expect(actions.has?(:delete_and_ignore)).to eq(false)

View File

@ -414,7 +414,7 @@ describe Topic do
end
context 'category validation' do
fab!(:category) { Fabricate(:category) }
fab!(:category) { Fabricate(:category_with_definition) }
context 'allow_uncategorized_topics is false' do
before do
@ -459,7 +459,7 @@ describe Topic do
end
context "with a category definition" do
let!(:category) { Fabricate(:category) }
let!(:category) { Fabricate(:category_with_definition) }
it "excludes the category definition topic from similar_to" do
expect(Topic.similar_to('category definition for', "no body")).to be_blank
@ -478,7 +478,7 @@ describe Topic do
end
context "secure categories" do
fab!(:category) { Fabricate(:category, read_restricted: true) }
fab!(:category) { Fabricate(:category_with_definition, read_restricted: true) }
before do
topic.category = category
@ -680,7 +680,7 @@ describe Topic do
fab!(: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 do
describe 'with category' do
before do
@category = Fabricate(:category)
@category = Fabricate(:category_with_definition)
end
it "should not increase the topic_count with no category" do
@ -1259,7 +1259,7 @@ describe Topic do
describe '#change_category_to_id' do
fab!(: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' do
it 'changes the category' do
@ -1303,7 +1303,7 @@ describe Topic do
end
describe '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' do
topic.change_category_to_id(new_category.id)
@ -1416,7 +1416,7 @@ describe Topic do
SiteSetting.allow_uncategorized_topics = false
end
let!(:topic) { Fabricate(:topic, category: Fabricate(:category)) }
let!(:topic) { Fabricate(:topic, category: Fabricate(:category_with_definition)) }
it 'returns false' do
expect(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 do
describe '#in_category_and_subcategories' do
it '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 do
end
describe "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 do
end
it "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_blank
end
@ -1716,7 +1716,7 @@ describe Topic do
it "doesn't return topics from muted categories" do
user = 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 do
it "doesn't return topics from suppressed categories" do
user = 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 do
end
it "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 do
describe '.secured' do
it '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 do
describe 'trash!' do
context "its category's topic count" do
fab!(:moderator) { Fabricate(:moderator) }
fab!(:category) { Fabricate(:category) }
fab!(:category) { Fabricate(:category_with_definition) }
it "subtracts 1 if topic is being deleted" do
topic = Fabricate(:topic, category: category)
@ -1966,7 +1966,7 @@ describe Topic do
describe 'recover!' do
context "its category's topic count" do
fab!(:category) { Fabricate(:category) }
fab!(:category) { Fabricate(:category_with_definition) }
it "adds 1 if topic is deleted" do
topic = Fabricate(:topic, category: category, deleted_at: 1.day.ago)
@ -2195,7 +2195,7 @@ describe Topic do
end
it '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_falsey
end
@ -2424,7 +2424,7 @@ describe Topic do
g.save!
end
end
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" do

View File

@ -33,15 +33,12 @@ describe UserSearch do
group.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)

View File

@ -186,7 +186,7 @@ RSpec.describe Admin::UsersController do
end
it "won't delete a category topic" do
c = Fabricate(:category)
c = Fabricate(:category_with_definition)
cat_post = c.topic.posts.first
put(
"/admin/users/#{user.id}/suspend.json",
@ -201,7 +201,7 @@ RSpec.describe Admin::UsersController do
end
it "won't delete a category topic by replies" do
c = Fabricate(:category)
c = Fabricate(:category_with_definition)
cat_post = c.topic.posts.first
put(
"/admin/users/#{user.id}/suspend.json",

View File

@ -341,7 +341,7 @@ RSpec.describe ListController do
describe 'category' do
context '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 do
end
context '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" do
it "redirects to the child category" do
@ -390,7 +390,7 @@ RSpec.describe ListController do
context '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' do
get "/c/#{other_category.slug}/l/latest.json"
@ -402,7 +402,7 @@ RSpec.describe ListController do
end
context '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' do
it "succeeds" do
@ -485,7 +485,7 @@ RSpec.describe ListController do
end
context "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' do
get "/c/#{amazing_category.slug}"
@ -623,11 +623,11 @@ RSpec.describe ListController do
end
describe "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" do

View File

@ -2080,9 +2080,8 @@ RSpec.describe TopicsController do
end
it "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)

View File

@ -5,13 +5,13 @@ require 'rails_helper'
describe DestroyTask do
describe '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 do
end
describe '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) }

View File

@ -313,7 +313,7 @@ describe UserDestroyer do
end
context '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" do
UserDestroyer.new(@admin).destroy(@user, delete_posts: true)