diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index 31c024e8037..66e59247f93 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -111,6 +111,7 @@ class ListController < ApplicationController end def category_default + canonical_url "#{Discourse.base_url_no_prefix}#{@category.url}" view_method = @category.default_view view_method = 'latest' unless %w(latest top).include?(view_method) diff --git a/spec/controllers/list_controller_spec.rb b/spec/controllers/list_controller_spec.rb index 0c5b41596bc..4240d78ca9b 100644 --- a/spec/controllers/list_controller_spec.rb +++ b/spec/controllers/list_controller_spec.rb @@ -219,7 +219,22 @@ describe ListController do xhr :get, :category_default, category: category.slug expect(response).to be_success end + end + describe "renders canonical tag" do + render_views + + it 'for category default view' do + get :category_default, category: category.slug + expect(response).to be_success + expect(css_select("link[rel=canonical]").length).to eq(1) + end + + it 'for category latest view' do + get :category_latest, category: category.slug + expect(response).to be_success + expect(css_select("link[rel=canonical]").length).to eq(1) + end end end end