From 8c060d4af6c5658216acea36d54a776940218c86 Mon Sep 17 00:00:00 2001 From: Caio <117518+caiosba@users.noreply.github.com> Date: Tue, 3 Sep 2024 18:45:05 -0300 Subject: [PATCH] Adding test --- app/models/team.rb | 4 ++-- test/models/team_2_test.rb | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/team.rb b/app/models/team.rb index 02387976a..be43ee2c7 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -547,9 +547,9 @@ def filtered_fact_checks(filters = {}) def filter_by_keywords(query, filters, type = 'FactCheck') tsquery = Team.sanitize_sql_array(["websearch_to_tsquery(?)", filters[:text]]) if type == 'FactCheck' - tsvector = "to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(summary, '') || coalesce(url, '') || coalesce(claim_descriptions.description, '') || coalesce(claim_descriptions.context, ''))" + tsvector = "to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(summary, '') || ' ' || coalesce(url, '') || ' ' || coalesce(claim_descriptions.description, '') || ' ' || coalesce(claim_descriptions.context, ''))" else - tsvector = "to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(description, '') || coalesce(url, ''))" + tsvector = "to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(description, '') || ' ' || coalesce(url, ''))" end query.where(Arel.sql("#{tsvector} @@ #{tsquery}")) end diff --git a/test/models/team_2_test.rb b/test/models/team_2_test.rb index 3906def15..5b2df9544 100644 --- a/test/models/team_2_test.rb +++ b/test/models/team_2_test.rb @@ -1528,12 +1528,13 @@ def setup Sidekiq::Testing.fake! t = create_team # Fact-checks - create_fact_check title: 'Some Other Test', claim_description: create_claim_description(project_media: create_project_media(team: t)) - create_fact_check title: 'Bar Bravo Foo Test', claim_description: create_claim_description(project_media: create_project_media(team: t)) + create_fact_check title: 'Some Other Test', claim_description: create_claim_description(description: 'Claim', project_media: create_project_media(team: t)) + create_fact_check title: 'Bar Bravo Foo Test', claim_description: create_claim_description(context: 'Claim', project_media: create_project_media(team: t)) create_fact_check title: 'Foo Alpha Bar Test', claim_description: create_claim_description(project_media: create_project_media(team: t)) assert_equal 3, t.filtered_fact_checks.count assert_equal 3, t.filtered_fact_checks(text: 'Test').count assert_equal 2, t.filtered_fact_checks(text: 'Foo Bar').count + assert_equal 2, t.filtered_fact_checks(text: 'Claim').count assert_equal 1, t.filtered_fact_checks(text: 'Foo Bar Bravo').count assert_equal 1, t.filtered_fact_checks(text: 'Foo Bar Alpha').count assert_equal 0, t.filtered_fact_checks(text: 'Foo Bar Delta').count