Skip to content

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

FIX: new-topic route with sub-category and tags were broken (#12503)

Arpit Jalanc449bf77b3b3
diff --git a/app/models/topic_list.rb b/app/models/topic_list.rb
index 2223dc6ad73..9a69fe1c99b 100644
--- a/app/models/topic_list.rb
+++ b/app/models/topic_list.rb
@@ -69,9 +69,8 @@ class TopicList < DraftableList
else
"topic_list_#{@category.url.sub(/^\//, '')}/l/#{@filter}"
end
- elsif @tags
- tag = @tags.first
- "topic_list_tag/#{tag.name}/l/#{@filter}"
+ elsif @tags && @tags.first.present?
+ "topic_list_tag/#{@tags.first.name}/l/#{@filter}"
else
"topic_list_#{@filter}"
end
diff --git a/spec/models/topic_list_spec.rb b/spec/models/topic_list_spec.rb
index 8f2ea2b5ab7..97555b46172 100644
--- a/spec/models/topic_list_spec.rb
+++ b/spec/models/topic_list_spec.rb
@@ -109,5 +109,10 @@ describe TopicList do
topic_list = TopicList.new('latest', nil, nil, tags: [tag])
expect(topic_list.preload_key).to eq("topic_list_tag/#{tag.name}/l/latest")
end
+
+ it "generates correct key when both category and tags are missing" do
+ topic_list = TopicList.new('latest', nil, nil, tags: Tag.none)
+ expect(topic_list.preload_key).to eq("topic_list_latest")
+ end
end
end