mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Add hook for plugins modify how slugs are computed (#16907)
Allows plugins to hook into and change how topic slugs are computed.
This commit is contained in:
@@ -270,6 +270,37 @@ describe Topic do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'slug computed hooks' do
|
||||
before do
|
||||
invert_slug = ->(topic, slug, title) { slug.reverse }
|
||||
Topic.slug_computed_callbacks << invert_slug
|
||||
end
|
||||
|
||||
let!(:title) { "hello test topic" }
|
||||
let!(:slug) { "hello-test-topic".reverse }
|
||||
let!(:other_title) { "other title" }
|
||||
let!(:other_slug) { "other-title".reverse }
|
||||
let!(:topic) { Fabricate.build(:topic, title: title) }
|
||||
|
||||
it "returns a reversed slug for a title" do
|
||||
expect(topic.title).to eq(title)
|
||||
expect(topic.slug).to eq(slug)
|
||||
end
|
||||
|
||||
it "returns a reversed slug after the title is changed" do
|
||||
expect(topic.title).to eq(title)
|
||||
expect(topic.slug).to eq(slug)
|
||||
|
||||
topic.title = other_title
|
||||
expect(topic.title).to eq(other_title)
|
||||
expect(topic.slug).to eq(other_slug)
|
||||
end
|
||||
|
||||
after do
|
||||
Topic.slug_computed_callbacks.clear
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "updating a title to be shorter" do
|
||||
|
||||
Reference in New Issue
Block a user