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.
This commit is contained in:
@@ -1136,6 +1136,7 @@ class Post < ApplicationRecord
|
|||||||
|
|
||||||
module CountMethods
|
module CountMethods
|
||||||
def fast_count(tags = "", options = {})
|
def fast_count(tags = "", options = {})
|
||||||
|
tags = tags.to_s
|
||||||
tags += " rating:s" if CurrentUser.safe_mode?
|
tags += " rating:s" if CurrentUser.safe_mode?
|
||||||
tags += " -status:deleted" if CurrentUser.hide_deleted_posts? && tags !~ /(?:^|\s)(?:-)?status:.+/
|
tags += " -status:deleted" if CurrentUser.hide_deleted_posts? && tags !~ /(?:^|\s)(?:-)?status:.+/
|
||||||
tags = Tag.normalize_query(tags)
|
tags = Tag.normalize_query(tags)
|
||||||
|
|||||||
@@ -2461,13 +2461,17 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
context "in safe mode" do
|
context "in safe mode" do
|
||||||
setup do
|
setup do
|
||||||
CurrentUser.stubs(:safe_mode?).returns(true)
|
CurrentUser.stubs(:safe_mode?).returns(true)
|
||||||
|
FactoryGirl.create(:post, "rating" => "s")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "execute a search" do
|
should "work for a blank search" do
|
||||||
Post.expects(:fast_count_search).once.with("rating:s", kind_of(Hash)).returns(1)
|
|
||||||
assert_equal(1, Post.fast_count(""))
|
assert_equal(1, Post.fast_count(""))
|
||||||
end
|
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
|
should "not fail for a two tag search by a member" do
|
||||||
post1 = FactoryGirl.create(:post, tag_string: "aaa bbb rating:s")
|
post1 = FactoryGirl.create(:post, tag_string: "aaa bbb rating:s")
|
||||||
post2 = FactoryGirl.create(:post, tag_string: "aaa bbb rating:e")
|
post2 = FactoryGirl.create(:post, tag_string: "aaa bbb rating:e")
|
||||||
|
|||||||
Reference in New Issue
Block a user