search: fix exception on nil searches.
6ca42947bd (commitcomment-38622036)
This commit is contained in:
@@ -718,7 +718,7 @@ class PostQueryBuilder
|
|||||||
class_methods do
|
class_methods do
|
||||||
def scan_query(query)
|
def scan_query(query)
|
||||||
terms = []
|
terms = []
|
||||||
query = query.gsub(/[[:space:]]/, " ")
|
query = query.to_s.gsub(/[[:space:]]/, " ")
|
||||||
scanner = StringScanner.new(query)
|
scanner = StringScanner.new(query)
|
||||||
|
|
||||||
until scanner.eos?
|
until scanner.eos?
|
||||||
|
|||||||
@@ -63,12 +63,21 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
|||||||
assert_tag_match([post1], "?")
|
assert_tag_match([post1], "?")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "return posts for the empty search" do
|
||||||
|
post1 = create(:post)
|
||||||
|
|
||||||
|
assert_tag_match([post1], "")
|
||||||
|
assert_tag_match([post1], " ")
|
||||||
|
assert_tag_match([post1], nil)
|
||||||
|
end
|
||||||
|
|
||||||
should "return posts for 1 tag" do
|
should "return posts for 1 tag" do
|
||||||
post1 = create(:post, tag_string: "aaa")
|
post1 = create(:post, tag_string: "aaa")
|
||||||
post2 = create(:post, tag_string: "aaa bbb")
|
post2 = create(:post, tag_string: "aaa bbb")
|
||||||
post3 = create(:post, tag_string: "bbb ccc")
|
post3 = create(:post, tag_string: "bbb ccc")
|
||||||
|
|
||||||
assert_tag_match([post2, post1], "aaa")
|
assert_tag_match([post2, post1], "aaa")
|
||||||
|
assert_tag_match([post2, post1], " aaa ")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return posts for a 2 tag join" do
|
should "return posts for a 2 tag join" do
|
||||||
@@ -77,6 +86,7 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
|||||||
post3 = create(:post, tag_string: "bbb ccc")
|
post3 = create(:post, tag_string: "bbb ccc")
|
||||||
|
|
||||||
assert_tag_match([post2], "aaa bbb")
|
assert_tag_match([post2], "aaa bbb")
|
||||||
|
assert_tag_match([post2], " aaa bbb ")
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return posts for a 2 tag union" do
|
should "return posts for a 2 tag union" do
|
||||||
|
|||||||
Reference in New Issue
Block a user