From bb2d3a59b5ce392e68b3eb13d1eb2f51c547c8ee Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 22 Jan 2026 14:09:03 -0500 Subject: [PATCH] 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. --- test/controllers/searches_controller_test.rb | 9 +++++---- test/models/card/searchable_test.rb | 14 +++++++------- test/models/comment/searchable_test.rb | 6 +++--- test/models/filter/search_test.rb | 3 +-- test/models/search_test.rb | 8 ++++---- test/test_helpers/search_test_helper.rb | 1 + 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/test/controllers/searches_controller_test.rb b/test/controllers/searches_controller_test.rb index 70ec15da9..2493fe43f 100644 --- a/test/controllers/searches_controller_test.rb +++ b/test/controllers/searches_controller_test.rb @@ -5,10 +5,10 @@ class SearchesControllerTest < ActionDispatch::IntegrationTest setup do @board.update!(all_access: true) - @card = @board.cards.create!(title: "Layout is broken", description: "Look at this mess.", creator: @user) - @comment_card = @board.cards.create!(title: "Some card", creator: @user) + @card = @board.cards.create!(title: "Layout is broken", description: "Look at this mess.", status: "published", creator: @user) + @comment_card = @board.cards.create!(title: "Some card", status: "published", creator: @user) @comment_card.comments.create!(body: "overflowing text issue", creator: @user) - @comment2_card = @board.cards.create!(title: "Just haggis", description: "More haggis", creator: @user) + @comment2_card = @board.cards.create!(title: "Just haggis", description: "More haggis", status: "published", creator: @user) @comment2_card.comments.create!(body: "I love haggis", creator: @user) untenanted { sign_in_as @user } @@ -43,7 +43,7 @@ class SearchesControllerTest < ActionDispatch::IntegrationTest end test "search highlights matched terms with proper HTML marks" do - @board.cards.create!(title: "Testing search highlighting", creator: @user) + @board.cards.create!(title: "Testing search highlighting", status: "published", creator: @user) get search_path(q: "highlighting", script_name: "/#{@account.external_account_id}") assert_response :success @@ -52,6 +52,7 @@ class SearchesControllerTest < ActionDispatch::IntegrationTest test "search preserves highlight marks but escapes surrounding HTML" do @board.cards.create!( title: "Bold testing content", + status: "published", creator: @user ) diff --git a/test/models/card/searchable_test.rb b/test/models/card/searchable_test.rb index 5c7ca9c86..a67890620 100644 --- a/test/models/card/searchable_test.rb +++ b/test/models/card/searchable_test.rb @@ -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) diff --git a/test/models/comment/searchable_test.rb b/test/models/comment/searchable_test.rb index 7ba73847c..c1a62e607 100644 --- a/test/models/comment/searchable_test.rb +++ b/test/models/comment/searchable_test.rb @@ -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 diff --git a/test/models/filter/search_test.rb b/test/models/filter/search_test.rb index f7b7e7968..cbdd9558d 100644 --- a/test/models/filter/search_test.rb +++ b/test/models/filter/search_test.rb @@ -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) diff --git a/test/models/search_test.rb b/test/models/search_test.rb index 1f4981090..343295dd0 100644 --- a/test/models/search_test.rb +++ b/test/models/search_test.rb @@ -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 } diff --git a/test/test_helpers/search_test_helper.rb b/test/test_helpers/search_test_helper.rb index 78b113781..81cf271dc 100644 --- a/test/test_helpers/search_test_helper.rb +++ b/test/test_helpers/search_test_helper.rb @@ -17,6 +17,7 @@ module SearchTestHelper Current.account = @account @identity = Identity.create!(email_address: "test@example.com") @user = User.create!(name: "Test User", account: @account, identity: @identity) + Current.user = @user @board = Board.create!(name: "Test Board", account: @account, creator: @user) end