Skip to content

A platform for community discussion. Free, open, simple.

FIX: tag edit page crashing when slug_generation_method is none (#38376)

Natalie Taydc22e990904c
diff --git a/app/serializers/tag_settings_serializer.rb b/app/serializers/tag_settings_serializer.rb
index fe4c6aecf0e..164c3cad173 100644
--- a/app/serializers/tag_settings_serializer.rb
+++ b/app/serializers/tag_settings_serializer.rb
@@ -19,6 +19,10 @@ class TagSettingsSerializer < ApplicationSerializer
object.name
end
+ def slug
+ object.slug_for_url
+ end
+
def description
object.description
end
diff --git a/spec/requests/tags_controller_spec.rb b/spec/requests/tags_controller_spec.rb
index e6d8a60aa94..f0434a2fe56 100644
--- a/spec/requests/tags_controller_spec.rb
+++ b/spec/requests/tags_controller_spec.rb
@@ -762,6 +762,16 @@ RSpec.describe TagsController do
expect(settings["tag_groups"][0]["name"]).to eq(tag_group.name)
end
+ it "returns slug_for_url when tag has an empty slug" do
+ tag.update_column(:slug, "")
+ sign_in(admin)
+ get "/tag/#{tag.id}/settings.json"
+ expect(response.status).to eq(200)
+
+ settings = response.parsed_body["tag_settings"]
+ expect(settings["slug"]).to eq("#{tag.id}-tag")
+ end
+
context "with content localization enabled" do
before { SiteSetting.content_localization_enabled = true }
diff --git a/spec/system/page_objects/pages/tag.rb b/spec/system/page_objects/pages/tag.rb
index efffd3d919a..3831ff20e51 100644
--- a/spec/system/page_objects/pages/tag.rb
+++ b/spec/system/page_objects/pages/tag.rb
@@ -4,7 +4,7 @@ module PageObjects
module Pages
class Tag < PageObjects::Pages::Base
def visit_tag(tag)
- page.visit "/tag/#{tag.slug}/#{tag.id}"
+ page.visit "/tag/#{tag.slug_for_url}/#{tag.id}"
self
end
diff --git a/spec/system/page_objects/pages/tag_settings.rb b/spec/system/page_objects/pages/tag_settings.rb
index 8e38bd7c38c..a41b70715ea 100644
--- a/spec/system/page_objects/pages/tag_settings.rb
+++ b/spec/system/page_objects/pages/tag_settings.rb
@@ -4,12 +4,12 @@ module PageObjects
module Pages
class TagSettings < PageObjects::Pages::Base
def visit(tag)
- page.visit "/tag/#{tag.slug}/#{tag.id}/edit/general"
+ page.visit "/tag/#{tag.slug_for_url}/#{tag.id}/edit/general"
self
end
def visit_tab(tag, tab)
- page.visit "/tag/#{tag.slug}/#{tag.id}/edit/#{tab}"
+ page.visit "/tag/#{tag.slug_for_url}/#{tag.id}/edit/#{tab}"
self
end
diff --git a/spec/system/tag_settings_spec.rb b/spec/system/tag_settings_spec.rb
index 19202ab9f9c..f3b073103ff 100644
--- a/spec/system/tag_settings_spec.rb
+++ b/spec/system/tag_settings_spec.rb
@@ -21,6 +21,19 @@ describe "Tag Settings", type: :system do
context "when experimental_tag_settings_page is enabled" do
before { SiteSetting.experimental_tag_settings_page = true }
+ it "loads the tag edit page for tags with empty slugs" do
+ tag_1.update_column(:slug, "")
+ sign_in(admin)
+
+ tags_page.visit_tag(tag_1)
+ tags_page.tag_info_btn.click
+
+ expect(tag_settings_page).to have_tag_settings_page
+ expect(page).to have_current_path("/tag/#{tag_1.id}-tag/#{tag_1.id}/edit/general")
+ expect(tag_settings_page).to have_name_value(tag_1.name)
+ expect(tag_settings_page).to have_slug_value("#{tag_1.id}-tag")
+ end
+
it "allows privileged users to access the new tag settings page" do
sign_in(admin)