mirror of
https://github.com/discourse/discourse.git
synced 2026-08-13 06:25:11 -05:00
FEATURE: Create legal topics for set company name (#21620)
Legal topics, such as the Terms of Service and Privacy Policy topics do not make sense if the entity creating the community is not a company. These topics will be created and updated only when the company name is present and deleted when it is not.
This commit is contained in:
@@ -43,4 +43,54 @@ RSpec.describe "Setting changes" do
|
||||
expect(Reviewable.min_score_for_priority(:low)).not_to eq(new_threshold)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#title and #site_description" do
|
||||
before do
|
||||
general_category = Fabricate(:category, name: "General")
|
||||
SiteSetting.general_category_id = general_category.id
|
||||
SeedData::Topics.with_default_locale.create(site_setting_names: ["welcome_topic_id"])
|
||||
end
|
||||
|
||||
it "updates the welcome topic when title changes" do
|
||||
SiteSetting.title = SecureRandom.alphanumeric
|
||||
|
||||
topic = Topic.find(SiteSetting.welcome_topic_id)
|
||||
expect(topic.title).to include(SiteSetting.title)
|
||||
expect(topic.first_post.raw).to include(SiteSetting.title)
|
||||
end
|
||||
|
||||
it "updates the welcome topic when site_description changes" do
|
||||
SiteSetting.site_description = SecureRandom.alphanumeric
|
||||
|
||||
topic = Topic.find(SiteSetting.welcome_topic_id)
|
||||
expect(topic.first_post.raw).to include(SiteSetting.site_description)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#company_name" do
|
||||
it "creates the TOS and Privacy topics" do
|
||||
expect { SiteSetting.company_name = "Company Name" }.to change { Topic.count }.by(
|
||||
2,
|
||||
).and change { SiteSetting.tos_topic_id }.and change { SiteSetting.privacy_topic_id }
|
||||
end
|
||||
|
||||
it "creates, updates and deletes the topic" do
|
||||
# Topic is created
|
||||
expect { SiteSetting.company_name = "Company Name" }.to change { Topic.count }.by(2)
|
||||
topic = Topic.find(SiteSetting.tos_topic_id)
|
||||
first_post = topic.first_post
|
||||
expect(first_post.raw).to include("Company Name")
|
||||
|
||||
# Topic is edited
|
||||
expect { SiteSetting.company_name = "Other Name" }.not_to change { Topic.count }
|
||||
expect(first_post.reload.raw).to include("Other Name")
|
||||
|
||||
# Topic can be deleted
|
||||
expect { SiteSetting.company_name = "" }.to change { Topic.count }.by(-2)
|
||||
|
||||
# Topic can be recovered and edited
|
||||
SiteSetting.company_name = "New Name"
|
||||
expect(first_post.reload.raw).to include("New Name")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ RSpec.describe SeedData::Topics do
|
||||
end
|
||||
|
||||
def create_topic(name = "welcome_topic_id")
|
||||
subject.create(site_setting_names: [name])
|
||||
subject.create(site_setting_names: [name], include_legal_topics: true)
|
||||
end
|
||||
|
||||
describe "#create" do
|
||||
@@ -71,6 +71,19 @@ RSpec.describe SeedData::Topics do
|
||||
|
||||
expect { create_topic }.to_not change { Topic.count }
|
||||
end
|
||||
|
||||
it "does not create a legal topic if company_name is not set" do
|
||||
subject.create(site_setting_names: ["tos_topic_id"])
|
||||
|
||||
expect(SiteSetting.tos_topic_id).to eq(-1)
|
||||
end
|
||||
|
||||
it "creates a legal topic if company_name is set" do
|
||||
SiteSetting.company_name = "Company Name"
|
||||
subject.create(site_setting_names: ["tos_topic_id"])
|
||||
|
||||
expect(SiteSetting.tos_topic_id).to_not eq(-1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#update" do
|
||||
@@ -129,6 +142,29 @@ RSpec.describe SeedData::Topics do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#delete" do
|
||||
def delete_topic(name = "welcome_topic_id", skip_changed: false)
|
||||
subject.delete(site_setting_names: [name], skip_changed: skip_changed)
|
||||
end
|
||||
|
||||
it "deletes the topic" do
|
||||
create_topic
|
||||
|
||||
topic = Topic.last
|
||||
|
||||
expect { delete_topic }.to change { Topic.count }.by(-1)
|
||||
end
|
||||
|
||||
it "does not delete the topic if changed" do
|
||||
create_topic
|
||||
|
||||
topic = Topic.last
|
||||
topic.first_post.revise(Fabricate(:admin), raw: "New text of first post.")
|
||||
|
||||
expect { delete_topic(skip_changed: true) }.not_to change { Topic.count }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#reseed_options" do
|
||||
it "returns only existing topics as options" do
|
||||
create_topic("guidelines_topic_id")
|
||||
|
||||
Reference in New Issue
Block a user