From 72c92b0f4e2c324a9902613c9464fc45bf7fc09b Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 3 Jul 2017 13:25:22 +0530 Subject: [PATCH] FIX: include canonical meta tag on category pages --- app/controllers/list_controller.rb | 1 + spec/controllers/list_controller_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+) 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