From 30872ebb4113be503483228c246633f3375a9000 Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 23 Apr 2017 16:53:34 -0500 Subject: [PATCH] Fix #2990: Wiki Autocomplete Misses On Certain Meta-wikis /wiki_pages?search[order]=post_count didn't include wiki pages that didn't belong to a tag. This was due to doing an inner join on the tags table instead of a left outer join. --- app/models/artist.rb | 2 +- app/models/wiki_page.rb | 2 +- test/functional/wiki_pages_controller_test.rb | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/artist.rb b/app/models/artist.rb index b92defa29..a123a64b7 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -437,7 +437,7 @@ class Artist < ActiveRecord::Base when "updated_at" q = q.order("artists.updated_at desc") when "post_count" - q = q.joins(:tag).order("tags.post_count desc") + q = q.includes(:tag).order("tags.post_count desc nulls last").references(:tags) else q = q.order("artists.id desc") end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index ad4a497ea..34da591bb 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -87,7 +87,7 @@ class WikiPage < ActiveRecord::Base when "title" q = q.order("title") when "post_count" - q = q.joins(:tag).order("tags.post_count desc") + q = q.includes(:tag).order("tags.post_count desc nulls last").references(:tags) else q = q.order("updated_at desc") end diff --git a/test/functional/wiki_pages_controller_test.rb b/test/functional/wiki_pages_controller_test.rb index 2c9496aa1..45b9b55b5 100644 --- a/test/functional/wiki_pages_controller_test.rb +++ b/test/functional/wiki_pages_controller_test.rb @@ -28,6 +28,11 @@ class WikiPagesControllerTest < ActionController::TestCase get :index, {:search => {:title => "abc"}} assert_redirected_to(wiki_page_path(@wiki_page_abc)) end + + should "list wiki_pages without tags with order=post_count" do + get :index, {:search => {:title => "abc", :order => "post_count"}} + assert_redirected_to(wiki_page_path(@wiki_page_abc)) + end end context "show action" do