Clean `Topic#slug` when `SiteSetting.slug_generation_method` changes.
https://meta.discourse.org/t/removing-the-concept-of-slugs-for-some-languages/26643/24?u=tgxworld
This commit is contained in:
parent
dee498a281
commit
d5293aeae2
|
@ -33,6 +33,14 @@ class Topic < ActiveRecord::Base
|
|||
|
||||
attr_accessor :allowed_user_ids, :tags_changed
|
||||
|
||||
DiscourseEvent.on(:site_setting_saved) do |site_setting|
|
||||
if site_setting.name.to_s == "slug_generation_method" && site_setting.saved_change_to_value?
|
||||
Scheduler::Defer.later("Null topic slug") do
|
||||
Topic.update_all(slug: nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.max_sort_order
|
||||
@max_sort_order ||= (2**31) - 1
|
||||
end
|
||||
|
|
|
@ -201,6 +201,26 @@ describe Topic do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when updating SiteSetting.slug_generation_method' do
|
||||
let(:title) { '熱帶風暴畫眉熱帶風暴畫眉熱帶風暴畫眉' }
|
||||
let(:slug) { 'topic' }
|
||||
|
||||
it 'should clear the slug' do
|
||||
topic.save!
|
||||
expect(topic.title).to eq(title)
|
||||
expect(topic.slug).to eq(slug)
|
||||
|
||||
begin
|
||||
Scheduler::Defer.async = false
|
||||
SiteSetting.update(name: 'slug_generation_method', value: 'encoded')
|
||||
expect(topic.reload.read_attribute(:slug)).to eq(nil)
|
||||
ensure
|
||||
SiteSetting.where(name: 'slug_generation_method').destroy_all
|
||||
Scheduler::Defer.async = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "updating a title to be shorter" do
|
||||
|
|
Loading…
Reference in New Issue