From 3c6a613964dcbe5e16281e2fc4d4ebbecd416def Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 29 Nov 2017 12:26:32 -0600 Subject: [PATCH] Fix #3410: Unable to create a new wiki page. Fix `Post.fast_count(nil)` failing when the user had the "safe mode" or "deleted post filter" options turned on. --- app/models/post.rb | 1 + test/unit/post_test.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 1a25add2e..215516afb 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1136,6 +1136,7 @@ class Post < ApplicationRecord module CountMethods def fast_count(tags = "", options = {}) + tags = tags.to_s tags += " rating:s" if CurrentUser.safe_mode? tags += " -status:deleted" if CurrentUser.hide_deleted_posts? && tags !~ /(?:^|\s)(?:-)?status:.+/ tags = Tag.normalize_query(tags) diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 026ad97b5..2ce394014 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -2461,13 +2461,17 @@ class PostTest < ActiveSupport::TestCase context "in safe mode" do setup do CurrentUser.stubs(:safe_mode?).returns(true) + FactoryGirl.create(:post, "rating" => "s") end - should "execute a search" do - Post.expects(:fast_count_search).once.with("rating:s", kind_of(Hash)).returns(1) + should "work for a blank search" do assert_equal(1, Post.fast_count("")) end + should "work for a nil search" do + assert_equal(1, Post.fast_count(nil)) + end + should "not fail for a two tag search by a member" do post1 = FactoryGirl.create(:post, tag_string: "aaa bbb rating:s") post2 = FactoryGirl.create(:post, tag_string: "aaa bbb rating:e")