Skip to content

Commit f80541d

Browse files
committed
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.
1 parent 23fe40f commit f80541d

File tree

6 files changed

+21
-20
lines changed

6 files changed

+21
-20
lines changed

test/controllers/searches_controller_test.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ class SearchesControllerTest < ActionDispatch::IntegrationTest
55

66
setup do
77
@board.update!(all_access: true)
8-
@card = @board.cards.create!(title: "Layout is broken", description: "Look at this mess.", creator: @user)
9-
@comment_card = @board.cards.create!(title: "Some card", creator: @user)
8+
@card = @board.cards.create!(title: "Layout is broken", description: "Look at this mess.", status: "published", creator: @user)
9+
@comment_card = @board.cards.create!(title: "Some card", status: "published", creator: @user)
1010
@comment_card.comments.create!(body: "overflowing text issue", creator: @user)
11-
@comment2_card = @board.cards.create!(title: "Just haggis", description: "More haggis", creator: @user)
11+
@comment2_card = @board.cards.create!(title: "Just haggis", description: "More haggis", status: "published", creator: @user)
1212
@comment2_card.comments.create!(body: "I love haggis", creator: @user)
1313

1414
untenanted { sign_in_as @user }
@@ -43,7 +43,7 @@ class SearchesControllerTest < ActionDispatch::IntegrationTest
4343
end
4444

4545
test "search highlights matched terms with proper HTML marks" do
46-
@board.cards.create!(title: "Testing search highlighting", creator: @user)
46+
@board.cards.create!(title: "Testing search highlighting", status: "published", creator: @user)
4747

4848
get search_path(q: "highlighting", script_name: "/#{@account.external_account_id}")
4949
assert_response :success
@@ -52,6 +52,7 @@ class SearchesControllerTest < ActionDispatch::IntegrationTest
5252
test "search preserves highlight marks but escapes surrounding HTML" do
5353
@board.cards.create!(
5454
title: "<b>Bold</b> testing content",
55+
status: "published",
5556
creator: @user
5657
)
5758

test/models/card/searchable_test.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ class Card::SearchableTest < ActiveSupport::TestCase
55

66
test "card search" do
77
# Searching by title
8-
card = @board.cards.create!(title: "layout is broken", creator: @user)
8+
card = @board.cards.create!(title: "layout is broken", status: "published", creator: @user)
99
results = Card.mentioning("layout", user: @user)
1010
assert_includes results, card
1111

1212
# Searching by comment
13-
card_with_comment = @board.cards.create!(title: "Some card", creator: @user)
13+
card_with_comment = @board.cards.create!(title: "Some card", status: "published", creator: @user)
1414
card_with_comment.comments.create!(body: "overflowing text", creator: @user)
1515
results = Card.mentioning("overflowing", user: @user)
1616
assert_includes results, card_with_comment
1717

1818
# Sanitizing search query
19-
card_broken = @board.cards.create!(title: "broken layout", creator: @user)
19+
card_broken = @board.cards.create!(title: "broken layout", status: "published", creator: @user)
2020
results = Card.mentioning("broken \"", user: @user)
2121
assert_includes results, card_broken
2222

@@ -25,8 +25,8 @@ class Card::SearchableTest < ActiveSupport::TestCase
2525

2626
# Filtering by board_ids
2727
other_board = Board.create!(name: "Other Board", account: @account, creator: @user)
28-
card_in_board = @board.cards.create!(title: "searchable content", creator: @user)
29-
card_in_other_board = other_board.cards.create!(title: "searchable content", creator: @user)
28+
card_in_board = @board.cards.create!(title: "searchable content", status: "published", creator: @user)
29+
card_in_other_board = other_board.cards.create!(title: "searchable content", status: "published", creator: @user)
3030
results = Card.mentioning("searchable", user: @user)
3131
assert_includes results, card_in_board
3232
assert_not_includes results, card_in_other_board
@@ -37,7 +37,7 @@ class Card::SearchableTest < ActiveSupport::TestCase
3737

3838
# Create a card with unreasonably long content
3939
long_content = "asdf " * Searchable::SEARCH_CONTENT_LIMIT
40-
card = @board.cards.create!(title: "Card with long description", creator: @user)
40+
card = @board.cards.create!(title: "Card with long description", status: "published", creator: @user)
4141
card.description = ActionText::Content.new(long_content)
4242
card.save!
4343

@@ -52,7 +52,7 @@ class Card::SearchableTest < ActiveSupport::TestCase
5252

5353
test "deleting card removes search record and FTS entry" do
5454
search_record_class = Search::Record.for(@user.account_id)
55-
card = @board.cards.create!(title: "Card to delete", creator: @user)
55+
card = @board.cards.create!(title: "Card to delete", status: "published", creator: @user)
5656

5757
# Verify search record exists
5858
search_record = search_record_class.find_by(searchable_type: "Card", searchable_id: card.id)

test/models/comment/searchable_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Comment::SearchableTest < ActiveSupport::TestCase
44
include SearchTestHelper
55

66
setup do
7-
@card = @board.cards.create!(title: "Test Card", creator: @user)
7+
@card = @board.cards.create!(title: "Test Card", status: "published", creator: @user)
88
end
99

1010
test "comment search" do
@@ -40,9 +40,9 @@ class Comment::SearchableTest < ActiveSupport::TestCase
4040
end
4141

4242
# Finding cards via comment search
43-
card_with_comment = @board.cards.create!(title: "Card One", creator: @user)
43+
card_with_comment = @board.cards.create!(title: "Card One", status: "published", creator: @user)
4444
card_with_comment.comments.create!(body: "unique searchable phrase", creator: @user)
45-
card_without_comment = @board.cards.create!(title: "Card Two", creator: @user)
45+
card_without_comment = @board.cards.create!(title: "Card Two", status: "published", creator: @user)
4646
results = Card.mentioning("searchable", user: @user)
4747
assert_includes results, card_with_comment
4848
assert_not_includes results, card_without_comment

test/models/filter/search_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ class Filter::SearchTest < ActiveSupport::TestCase
44
include SearchTestHelper
55

66
test "deduplicate multiple results" do
7-
card = @board.cards.create!(title: "Duplicate results test", description: "Have you had any haggis today?", creator: @user)
8-
card.published!
7+
card = @board.cards.create!(title: "Duplicate results test", description: "Have you had any haggis today?", creator: @user, status: "published")
98
card.comments.create(body: "I hate haggis.", creator: @user)
109
card.comments.create(body: "I love haggis.", creator: @user)
1110

test/models/search_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ class SearchTest < ActiveSupport::TestCase
55

66
test "search" do
77
# Search cards and comments
8-
card = @board.cards.create!(title: "layout design", creator: @user)
9-
comment_card = @board.cards.create!(title: "Some card", creator: @user)
8+
card = @board.cards.create!(title: "layout design", creator: @user, status: "published")
9+
comment_card = @board.cards.create!(title: "Some card", creator: @user, status: "published")
1010
comment_card.comments.create!(body: "overflowing text", creator: @user)
1111

1212
results = Search::Record.for(@user.account_id).search("layout", user: @user)
@@ -18,8 +18,8 @@ class SearchTest < ActiveSupport::TestCase
1818
# Don't include inaccessible boards
1919
other_user = User.create!(name: "Other User", account: @account)
2020
inaccessible_board = Board.create!(name: "Inaccessible Board", account: @account, creator: other_user)
21-
accessible_card = @board.cards.create!(title: "searchable content", creator: @user)
22-
inaccessible_card = inaccessible_board.cards.create!(title: "searchable content", creator: other_user)
21+
accessible_card = @board.cards.create!(title: "searchable content", creator: @user, status: "published")
22+
inaccessible_card = inaccessible_board.cards.create!(title: "searchable content", creator: other_user, status: "published")
2323

2424
results = Search::Record.for(@user.account_id).search("searchable", user: @user)
2525
assert results.find { |it| it.card_id == accessible_card.id }

test/test_helpers/search_test_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def setup_search_test
1717
Current.account = @account
1818
@identity = Identity.create!(email_address: "test@example.com")
1919
@user = User.create!(name: "Test User", account: @account, identity: @identity)
20+
Current.user = @user
2021
@board = Board.create!(name: "Test Board", account: @account, creator: @user)
2122
end
2223

0 commit comments

Comments
 (0)