From ede04d6d96097790cb8b0d1b8dc22f732a0ff8e9 Mon Sep 17 00:00:00 2001 From: Jose Farias Date: Sun, 27 Oct 2024 12:33:33 -0600 Subject: [PATCH] Fix search tests --- app/models/bubble/searchable.rb | 4 ++-- test/models/comment_test.rb | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/models/bubble/searchable.rb b/app/models/bubble/searchable.rb index 4901df82c..5cd3128d4 100644 --- a/app/models/bubble/searchable.rb +++ b/app/models/bubble/searchable.rb @@ -9,8 +9,8 @@ module Bubble::Searchable scope :mentioning, ->(query) do if query = query.presence bubbles = search(query).select(:id).to_sql - comments = Comment.search(query).select(:bubble_id).to_sql - left_joins(:comments).where("bubbles.id in (#{bubbles}) or comments.bubble_id in (#{comments})").distinct + comments = Comment.search(query).select(:id).to_sql + left_joins(:messages).where("bubbles.id in (#{bubbles}) or messages.messageable_id in (#{comments})").distinct end end end diff --git a/test/models/comment_test.rb b/test/models/comment_test.rb index 18e111549..8a579da2e 100644 --- a/test/models/comment_test.rb +++ b/test/models/comment_test.rb @@ -1,9 +1,13 @@ require "test_helper" class CommentTest < ActiveSupport::TestCase - test "searchable by body" do - comment = bubbles(:logo).comments.create! body: "I'd prefer something more rustic", creator: users(:kevin) + setup do + Current.session = sessions(:david) + end - assert_includes Comment.search("something rustic"), comment + test "searchable by body" do + message = bubbles(:logo).comment "I'd prefer something more rustic" + + assert_includes Comment.search("something rustic"), message.comment end end