A platform for community discussion. Free, open, simple.
FIX: Use correct subcategory subfolder path in crawler (#34250)
Natalie Tayeb04e98abdcf
diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erbindex dd260e70057..273c21f52cd 100644--- a/app/views/topics/show.html.erb+++ b/app/views/topics/show.html.erb@@ -8,7 +8,7 @@<div class="topic-category" itemscope itemtype="http://schema.org/BreadcrumbList"><% @breadcrumbs.each_with_index do |c, i| %><span itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">- <a href="<%= @topic_view.topic.category.url %>" class="badge-wrapper bullet" itemprop="item">+ <a href="<%= c[:url] %>" class="badge-wrapper bullet" itemprop="item"><span class='badge-category-bg' style='background-color: #<%= c[:color] %>'></span><span class='badge-category clear-badge'><span class='category-name' itemprop='name'><%= c[:name] %></span>diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 4e121d406a2..24e5e6a97ab 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -5639,6 +5639,27 @@ RSpec.describe TopicsController doget "#{topic.relative_url}/2"end+ it "adds breadcrumbs to the correct subcategory and category url in subfolder" do+ set_subfolder "/subpath"++ subcategory = Fabricate(:category, parent_category_id: category.id)+ topic.update!(category: subcategory)++ get "/t/#{topic.slug}/#{topic.id}",+ env: {+ "HTTP_USER_AGENT" => "Mozilla/5.0 ...",+ "HTTP_VIA" => "HTTP/1.0 web.archive.org",+ }+ expect(response.body).to have_tag(+ "a",+ with: {+ href: subcategory.url,+ },+ text: subcategory.name,+ )+ expect(response.body).to have_tag("a", with: { href: category.url }, text: category.name)+ end+context "with canonical_url" dofab!(:topic_embed) { Fabricate(:topic_embed, embed_url: "https://markvanlan.com") }let!(:user_agent) dodiff --git a/spec/views/topics/show.html.erb_spec.rb b/spec/views/topics/show.html.erb_spec.rbindex 00be16abdc4..bdd60e431f4 100644--- a/spec/views/topics/show.html.erb_spec.rb+++ b/spec/views/topics/show.html.erb_spec.rb@@ -6,20 +6,6 @@ RSpec.describe "topics/show.html.erb" dofab!(:category)fab!(:topic) { Fabricate(:topic, category: category) }- it "uses subfolder-safe category url" do- set_subfolder "/subpath"- topic_view = OpenStruct.new(topic: topic, posts: [], crawler_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" dotopic_view = OpenStruct.new(topic: topic, posts: [], crawler_posts: [])topic_view.stubs(:summary).returns("")