FIX: Only seed general category on new sites (#18130)

* FIX: Only seed general category on new sites

If the site already has human users (users with an id > 0) don't seed
the categories.

Follow up to: a6ad74c759

* use human_users scope
This commit is contained in:
Blake Erickson 2022-08-29 18:23:14 -06:00 committed by GitHub
parent b58d168f05
commit 00539307e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -128,6 +128,8 @@ module SeedData
end end
def should_create_category?(category_id, force_existence) def should_create_category?(category_id, force_existence)
return false if User.human_users.any?
if category_id > 0 if category_id > 0
force_existence ? !Category.exists?(category_id) : false force_existence ? !Category.exists?(category_id) : false
else else

View File

@ -93,6 +93,22 @@ RSpec.describe SeedData::Categories do
end end
end end
it "does not seed the general category for non-new sites" do
Fabricate(:user) # If the site has human users don't seed
expect { create_category("general_category_id") }
.to not_change { Category.count }
.and not_change { Topic.count }
end
it "seeds the general category for new sites" do
expect { create_category("general_category_id") }
.to change { Category.count }
.and change { Topic.count }
expect(Category.last.name).to eq("General")
end
it "does not override permissions of existing category when not forced" do it "does not override permissions of existing category when not forced" do
create_category("lounge_category_id") create_category("lounge_category_id")