FIX: Subfolder path is missing in category permalinks after slug update

This commit is contained in:
Vinoth Kannan 2018-12-21 09:29:54 +05:30
parent a2ae67509d
commit 2909e7fbdf
2 changed files with 12 additions and 5 deletions

View File

@ -572,11 +572,9 @@ class Category < ActiveRecord::Base
def create_category_permalink def create_category_permalink
old_slug = saved_changes.transform_values(&:first)["slug"] old_slug = saved_changes.transform_values(&:first)["slug"]
if self.parent_category url = +"#{Discourse.base_uri}/c"
url = "c/#{self.parent_category.slug}/#{old_slug}" url << "/#{parent_category.slug}" if parent_category_id
else url << "/#{old_slug}"
url = "c/#{old_slug}"
end
if Permalink.where(url: url).exists? if Permalink.where(url: url).exists?
Permalink.where(url: url).update_all(category_id: id) Permalink.where(url: url).update_all(category_id: id)

View File

@ -332,6 +332,15 @@ describe Category do
expect(Permalink.count).to eq(0) expect(Permalink.count).to eq(0)
end end
it "correctly creates permalink when category slug is changed in subfolder install" do
GlobalSetting.stubs(:relative_url_root).returns('/forum')
Discourse.stubs(:base_uri).returns("/forum")
old_url = @category.url
@category.update_attributes(slug: 'new-category')
permalink = Permalink.last
expect(permalink.url).to eq(old_url[1..-1])
end
it "should not set its description topic to auto-close" do it "should not set its description topic to auto-close" do
category = Fabricate(:category, name: 'Closing Topics', auto_close_hours: 1) category = Fabricate(:category, name: 'Closing Topics', auto_close_hours: 1)
expect(category.topic.public_topic_timer).to eq(nil) expect(category.topic.public_topic_timer).to eq(nil)