From 22ce638ec388bd86ec50c21ab337200f8f34f8b1 Mon Sep 17 00:00:00 2001 From: Natalie Tay Date: Tue, 28 Nov 2023 19:08:14 +0800 Subject: [PATCH] FIX: Use subfolder-safe url for category in html view (#24595) Use subfolder-safe url for category in html view --- app/views/topics/show.html.erb | 2 +- spec/views/topics/show.html.erb_spec.rb | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index 5ddec148677..87311ead7db 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -8,7 +8,7 @@
<% @breadcrumbs.each_with_index do |c, i| %> - + <%= c[:name] %> diff --git a/spec/views/topics/show.html.erb_spec.rb b/spec/views/topics/show.html.erb_spec.rb index 3c8eb951f2c..9b9ba061973 100644 --- a/spec/views/topics/show.html.erb_spec.rb +++ b/spec/views/topics/show.html.erb_spec.rb @@ -4,7 +4,22 @@ require "rails_helper" require "ostruct" RSpec.describe "topics/show.html.erb" do - fab!(:topic) + fab!(:category) + fab!(:topic) { Fabricate(:topic, category: category) } + + it "uses subfolder-safe category url" do + set_subfolder "/subpath" + topic_view = OpenStruct.new(topic: topic, posts: []) + topic_view.stubs(:summary).returns("") + view.stubs(:crawler_layout?).returns(false) + assign(:topic_view, topic_view) + assign(:breadcrumbs, [{ name: category.name, color: category.color }]) + assign(:tags, []) + + render template: "topics/show", formats: [:html] + + assert_select "a[href='/subpath/c/#{category.slug}/#{category.id}']" + end it "add nofollow to RSS alternate link for topic" do topic_view = OpenStruct.new(topic: topic, posts: [])