prefactor: update search to use published cards
We're about to make a change to assert that draft cards are not added to the search index, and so let's make the intention behind these tests clear first.
This commit is contained in:
@@ -5,18 +5,18 @@ class Card::SearchableTest < ActiveSupport::TestCase
|
||||
|
||||
test "card search" do
|
||||
# Searching by title
|
||||
card = @board.cards.create!(title: "layout is broken", creator: @user)
|
||||
card = @board.cards.create!(title: "layout is broken", status: "published", creator: @user)
|
||||
results = Card.mentioning("layout", user: @user)
|
||||
assert_includes results, card
|
||||
|
||||
# Searching by comment
|
||||
card_with_comment = @board.cards.create!(title: "Some card", creator: @user)
|
||||
card_with_comment = @board.cards.create!(title: "Some card", status: "published", creator: @user)
|
||||
card_with_comment.comments.create!(body: "overflowing text", creator: @user)
|
||||
results = Card.mentioning("overflowing", user: @user)
|
||||
assert_includes results, card_with_comment
|
||||
|
||||
# Sanitizing search query
|
||||
card_broken = @board.cards.create!(title: "broken layout", creator: @user)
|
||||
card_broken = @board.cards.create!(title: "broken layout", status: "published", creator: @user)
|
||||
results = Card.mentioning("broken \"", user: @user)
|
||||
assert_includes results, card_broken
|
||||
|
||||
@@ -25,8 +25,8 @@ class Card::SearchableTest < ActiveSupport::TestCase
|
||||
|
||||
# Filtering by board_ids
|
||||
other_board = Board.create!(name: "Other Board", account: @account, creator: @user)
|
||||
card_in_board = @board.cards.create!(title: "searchable content", creator: @user)
|
||||
card_in_other_board = other_board.cards.create!(title: "searchable content", creator: @user)
|
||||
card_in_board = @board.cards.create!(title: "searchable content", status: "published", creator: @user)
|
||||
card_in_other_board = other_board.cards.create!(title: "searchable content", status: "published", creator: @user)
|
||||
results = Card.mentioning("searchable", user: @user)
|
||||
assert_includes results, card_in_board
|
||||
assert_not_includes results, card_in_other_board
|
||||
@@ -37,7 +37,7 @@ class Card::SearchableTest < ActiveSupport::TestCase
|
||||
|
||||
# Create a card with unreasonably long content
|
||||
long_content = "asdf " * Searchable::SEARCH_CONTENT_LIMIT
|
||||
card = @board.cards.create!(title: "Card with long description", creator: @user)
|
||||
card = @board.cards.create!(title: "Card with long description", status: "published", creator: @user)
|
||||
card.description = ActionText::Content.new(long_content)
|
||||
card.save!
|
||||
|
||||
@@ -52,7 +52,7 @@ class Card::SearchableTest < ActiveSupport::TestCase
|
||||
|
||||
test "deleting card removes search record and FTS entry" do
|
||||
search_record_class = Search::Record.for(@user.account_id)
|
||||
card = @board.cards.create!(title: "Card to delete", creator: @user)
|
||||
card = @board.cards.create!(title: "Card to delete", status: "published", creator: @user)
|
||||
|
||||
# Verify search record exists
|
||||
search_record = search_record_class.find_by(searchable_type: "Card", searchable_id: card.id)
|
||||
|
||||
@@ -4,7 +4,7 @@ class Comment::SearchableTest < ActiveSupport::TestCase
|
||||
include SearchTestHelper
|
||||
|
||||
setup do
|
||||
@card = @board.cards.create!(title: "Test Card", creator: @user)
|
||||
@card = @board.cards.create!(title: "Test Card", status: "published", creator: @user)
|
||||
end
|
||||
|
||||
test "comment search" do
|
||||
@@ -40,9 +40,9 @@ class Comment::SearchableTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
# Finding cards via comment search
|
||||
card_with_comment = @board.cards.create!(title: "Card One", creator: @user)
|
||||
card_with_comment = @board.cards.create!(title: "Card One", status: "published", creator: @user)
|
||||
card_with_comment.comments.create!(body: "unique searchable phrase", creator: @user)
|
||||
card_without_comment = @board.cards.create!(title: "Card Two", creator: @user)
|
||||
card_without_comment = @board.cards.create!(title: "Card Two", status: "published", creator: @user)
|
||||
results = Card.mentioning("searchable", user: @user)
|
||||
assert_includes results, card_with_comment
|
||||
assert_not_includes results, card_without_comment
|
||||
|
||||
@@ -4,8 +4,7 @@ class Filter::SearchTest < ActiveSupport::TestCase
|
||||
include SearchTestHelper
|
||||
|
||||
test "deduplicate multiple results" do
|
||||
card = @board.cards.create!(title: "Duplicate results test", description: "Have you had any haggis today?", creator: @user)
|
||||
card.published!
|
||||
card = @board.cards.create!(title: "Duplicate results test", description: "Have you had any haggis today?", creator: @user, status: "published")
|
||||
card.comments.create(body: "I hate haggis.", creator: @user)
|
||||
card.comments.create(body: "I love haggis.", creator: @user)
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ class SearchTest < ActiveSupport::TestCase
|
||||
|
||||
test "search" do
|
||||
# Search cards and comments
|
||||
card = @board.cards.create!(title: "layout design", creator: @user)
|
||||
comment_card = @board.cards.create!(title: "Some card", creator: @user)
|
||||
card = @board.cards.create!(title: "layout design", creator: @user, status: "published")
|
||||
comment_card = @board.cards.create!(title: "Some card", creator: @user, status: "published")
|
||||
comment_card.comments.create!(body: "overflowing text", creator: @user)
|
||||
|
||||
results = Search::Record.for(@user.account_id).search("layout", user: @user)
|
||||
@@ -18,8 +18,8 @@ class SearchTest < ActiveSupport::TestCase
|
||||
# Don't include inaccessible boards
|
||||
other_user = User.create!(name: "Other User", account: @account)
|
||||
inaccessible_board = Board.create!(name: "Inaccessible Board", account: @account, creator: other_user)
|
||||
accessible_card = @board.cards.create!(title: "searchable content", creator: @user)
|
||||
inaccessible_card = inaccessible_board.cards.create!(title: "searchable content", creator: other_user)
|
||||
accessible_card = @board.cards.create!(title: "searchable content", creator: @user, status: "published")
|
||||
inaccessible_card = inaccessible_board.cards.create!(title: "searchable content", creator: other_user, status: "published")
|
||||
|
||||
results = Search::Record.for(@user.account_id).search("searchable", user: @user)
|
||||
assert results.find { |it| it.card_id == accessible_card.id }
|
||||
|
||||
Reference in New Issue
Block a user