Files
fizzy/test/models/card/searchable_test.rb
T
Donal McBreen 01d16f96d4 Remove Search::Record.for_account
Instead we'll compute the table name dynamically based on
Current.account where needed. Also we'll prevent searchable records
from being saved if Current.account is not set, otherwise the after
commit callbacks will fail.
2025-11-21 12:09:21 +00:00

45 lines
1.6 KiB
Ruby

require "test_helper"
class Card::SearchableTest < ActiveSupport::TestCase
include SearchTestHelper
test "card search" do
# Searching by title
card = @board.cards.create!(title: "layout is broken", 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.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)
results = Card.mentioning("broken \"", user: @user)
assert_includes results, card_broken
# Empty query returns no results
assert_empty Card.mentioning("\"", user: @user)
# 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)
results = Card.mentioning("searchable", user: @user)
assert_includes results, card_in_board
assert_not_includes results, card_in_other_board
end
test "card requires Current.account to be set" do
Current.account = nil
error = assert_raises(RuntimeError) do
@board.cards.create!(title: "Test card", creator: @user)
end
assert_match(/Current.account must be set to save Card/, error.message)
end
end