01d16f96d4
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.
52 lines
1.9 KiB
Ruby
52 lines
1.9 KiB
Ruby
require "test_helper"
|
|
|
|
class Comment::SearchableTest < ActiveSupport::TestCase
|
|
include SearchTestHelper
|
|
|
|
setup do
|
|
@card = @board.cards.create!(title: "Test Card", creator: @user)
|
|
end
|
|
|
|
test "comment search" do
|
|
# Comment is indexed on create
|
|
comment = @card.comments.create!(body: "searchable comment text", creator: @user)
|
|
record = Search::Record.find_by(searchable_type: "Comment", searchable_id: comment.id)
|
|
assert_not_nil record
|
|
|
|
# Comment is updated in index
|
|
comment.update!(body: "updated text")
|
|
record = Search::Record.find_by(searchable_type: "Comment", searchable_id: comment.id)
|
|
assert_match /updat/, record.content
|
|
|
|
# Comment is removed from index on destroy
|
|
comment_id = comment.id
|
|
comment.destroy
|
|
record = Search::Record.find_by(searchable_type: "Comment", searchable_id: comment_id)
|
|
assert_nil record
|
|
|
|
# Finding cards via comment search
|
|
card_with_comment = @board.cards.create!(title: "Card One", creator: @user)
|
|
card_with_comment.comments.create!(body: "unique searchable phrase", creator: @user)
|
|
card_without_comment = @board.cards.create!(title: "Card Two", creator: @user)
|
|
results = Card.mentioning("searchable", user: @user)
|
|
assert_includes results, card_with_comment
|
|
assert_not_includes results, card_without_comment
|
|
|
|
# Comment stores parent card_id and board_id
|
|
new_comment = @card.comments.create!(body: "test comment", creator: @user)
|
|
record = Search::Record.find_by(searchable_type: "Comment", searchable_id: new_comment.id)
|
|
assert_equal @card.id, record.card_id
|
|
assert_equal @board.id, record.board_id
|
|
end
|
|
|
|
test "comment requires Current.account to be set" do
|
|
Current.account = nil
|
|
|
|
error = assert_raises(RuntimeError) do
|
|
@card.comments.create!(body: "Test comment", creator: @user)
|
|
end
|
|
|
|
assert_match(/Current.account must be set to save Comment/, error.message)
|
|
end
|
|
end
|