From 5b3490553d72fec0d1e7613ce59a08be121b44b7 Mon Sep 17 00:00:00 2001 From: ashpb <31402193+ashpb@users.noreply.github.com> Date: Wed, 12 May 2021 13:58:51 +1000 Subject: [PATCH] Fix filter logic [bugfix] --- Pavel_Borisov/2/lib/machinery.rb | 6 +++--- Pavel_Borisov/2/test/machinery_test.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Pavel_Borisov/2/lib/machinery.rb b/Pavel_Borisov/2/lib/machinery.rb index 7dcaac2f..2dd3a92e 100644 --- a/Pavel_Borisov/2/lib/machinery.rb +++ b/Pavel_Borisov/2/lib/machinery.rb @@ -101,7 +101,7 @@ def process! completion_percentage = (processed_count / total_count.to_f * 100).to_i yield(completion_percentage, item.domain) if block_given? end - reject_results_with_word!(@filtered_word) if @filtered_word + keep_results_with_word!(@filtered_word) if @filtered_word self end @@ -136,8 +136,8 @@ def reject_solutions! end end - def reject_results_with_word!(word) - @list.reject! do |response| + def keep_results_with_word!(word) + @list.keep_if do |response| body_text = Nokogiri::HTML.parse(response.body).css('body').text body_text.downcase.match? word.downcase end diff --git a/Pavel_Borisov/2/test/machinery_test.rb b/Pavel_Borisov/2/test/machinery_test.rb index 816dbbe6..6eee4977 100644 --- a/Pavel_Borisov/2/test/machinery_test.rb +++ b/Pavel_Borisov/2/test/machinery_test.rb @@ -50,8 +50,8 @@ def test_exclude_solutions_rejects_gitlab DomainsList.new(TEST_DOMAINS_FILE, { 'exclude-solutions': true }).list.map(&:domain) end - def test_filter_word_rejects_results_with_word_in_body - assert_equal ['subdomain.example.com', 'gitlab.com'], + def test_filter_word_keeps_only_results_with_word_in_body + assert_equal ['example.com'], DomainsList.new(TEST_DOMAINS_FILE, { filter: 'example' }).process!.list.map(&:domain) end end