A platform for community discussion. Free, open, simple.
FIX: Make category updates slug validation idempotent
Rafael dos Santos Silva2e73985d1b9d
diff --git a/app/models/category.rb b/app/models/category.rbindex 40f5791090b..a6c5deb4885 100644--- a/app/models/category.rb+++ b/app/models/category.rb@@ -285,6 +285,7 @@ class Category < ActiveRecord::Baseif slug.present?# santized custom slug+ slug = SiteSetting.slug_generation_method == 'encoded' ? CGI.unescape(self.slug) : self.slugself.slug = Slug.sanitize(slug)errors.add(:slug, 'is already in use') if duplicate_slug?elsediff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rbindex 225b87eeab7..fdf2b7a9e52 100644--- a/spec/models/category_spec.rb+++ b/spec/models/category_spec.rb@@ -316,6 +316,12 @@ describe Category doexpect(@category.slug).to eq("%E6%B5%8B%E8%AF%95")expect(@category.slug_for_url).to eq("%E6%B5%8B%E8%AF%95")end++ it "keeps the slug" do+ @category.save+ expect(@category.slug).to eq("%E6%B5%8B%E8%AF%95")+ expect(@category.slug_for_url).to eq("%E6%B5%8B%E8%AF%95")+ endendend