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")