Merge pull request #3862 from evazion/fix-3857

Refactor searching text attributes
This commit is contained in:
Albert Yi
2018-09-04 13:25:40 -07:00
committed by GitHub
24 changed files with 61 additions and 122 deletions

View File

@@ -218,7 +218,7 @@ class CommentTest < ActiveSupport::TestCase
c2 = FactoryBot.create(:comment, :body => "aaa ddd")
c3 = FactoryBot.create(:comment, :body => "eee")
matches = Comment.body_matches("aaa")
matches = Comment.search(body_matches: "aaa")
assert_equal(2, matches.count)
assert_equal(c2.id, matches.all[0].id)
assert_equal(c1.id, matches.all[1].id)

View File

@@ -103,10 +103,10 @@ class DmailTest < ActiveSupport::TestCase
should "return results based on title contents" do
dmail = FactoryBot.create(:dmail, :title => "xxx", :owner => @user)
matches = Dmail.search(title_matches: "x")
matches = Dmail.search(title_matches: "x*")
assert_equal([dmail.id], matches.map(&:id))
matches = Dmail.search(title_matches: "X")
matches = Dmail.search(title_matches: "X*")
assert_equal([dmail.id], matches.map(&:id))
matches = Dmail.search(message_matches: "xxx")
@@ -118,9 +118,9 @@ class DmailTest < ActiveSupport::TestCase
should "return results based on body contents" do
dmail = FactoryBot.create(:dmail, :body => "xxx", :owner => @user)
matches = Dmail.search_message("xxx")
matches = Dmail.search(message_matches: "xxx")
assert(matches.any?)
matches = Dmail.search_message("aaa")
matches = Dmail.search(message_matches: "aaa")
assert(matches.empty?)
end
end

View File

@@ -164,8 +164,8 @@ class ForumPostTest < ActiveSupport::TestCase
should "be searchable by body content" do
post = FactoryBot.create(:forum_post, :topic_id => @topic.id, :body => "xxx")
assert_equal(1, ForumPost.body_matches("xxx").count)
assert_equal(0, ForumPost.body_matches("aaa").count)
assert_equal(1, ForumPost.search(body_matches: "xxx").count)
assert_equal(0, ForumPost.search(body_matches: "aaa").count)
end
should "initialize its creator" do

View File

@@ -196,13 +196,13 @@ class NoteTest < ActiveSupport::TestCase
context "where the body contains the string 'aaa'" do
should "return a hit" do
assert_equal(1, Note.body_matches("aaa").count)
assert_equal(1, Note.search(body_matches: "aaa").count)
end
end
context "where the body contains the string 'bbb'" do
should "return no hits" do
assert_equal(0, Note.body_matches("bbb").count)
assert_equal(0, Note.search(body_matches: "bbb").count)
end
end
end