<commit_before>require_relative '../../unit_helper'
require_relative '../../../../app/query/query_options/filter_query_option'

module Hacienda
  module Test
    describe FilterQueryOption do

      let(:filter_factory) { double('filter_factory') }
      let(:filter_1) { double('filter', :is_satisfied_by? => true) }
      let(:filter_2) { double('filter', :is_satisfied_by? => true) }

      let(:content_items) { [ { content: '"Hello"'} ] }

      it 'should apply each filter against a piece of content' do
        content_items =  [ { content: '"Hello"'} ]
        query_option = 'filter_1 and filter_2'

        filter_factory.stub(:get_individual_filter).with('filter_1').and_return(filter_1)
        filter_factory.stub(:get_individual_filter).with('filter_2').and_return(filter_2)

        filters = FilterQueryOption.new(query_option, filter_factory)

        filters.apply(content_items)

        expect(filter_1).to have_received(:is_satisfied_by?).with({ content: '"Hello"'})
        expect(filter_2).to have_received(:is_satisfied_by?).with({ content: '"Hello"'})

      end


    end
  end
end<commit_msg>Added tests for the "and" filter query option<commit_after>require_relative '../../unit_helper'
require_relative '../../../../app/query/query_options/filter_query_option'

module Hacienda
  module Test
    describe FilterQueryOption do

      let(:filter_factory) { double('filter_factory') }
      let(:filter_1) { double('filter', :is_satisfied_by? => true) }
      let(:filter_2) { double('filter', :is_satisfied_by? => true) }

      let(:content_items) { [ { content: '"Hello"'} ] }

      it 'should apply each filter against a piece of content' do
        content_items =  [ { content: '"Hello"'} ]
        query_option = 'filter_1 and filter_2'

        filter_factory.stub(:get_individual_filter).with('filter_1').and_return(filter_1)
        filter_factory.stub(:get_individual_filter).with('filter_2').and_return(filter_2)

        filters = FilterQueryOption.new(query_option, filter_factory)

        filters.apply(content_items)

        expect(filter_1).to have_received(:is_satisfied_by?).with({ content: '"Hello"'})
        expect(filter_2).to have_received(:is_satisfied_by?).with({ content: '"Hello"'})

      end

      context 'has an and' do
        it 'should keep the content items that satisfy all filters' do
          content_items =  [ { content: '"Hello"'} ]
          query_option = 'a_true_filter and another_true_filter'

          true_filter = double('filter', is_satisfied_by?: true)

          filter_factory.stub(:get_individual_filter).with('a_true_filter').and_return(true_filter)
          filter_factory.stub(:get_individual_filter).with('another_true_filter').and_return(true_filter)

          filters = FilterQueryOption.new(query_option, filter_factory)

          filtered_content_items = filters.apply(content_items)

          expect(filtered_content_items.size).to eq 1
        end

        it 'should filter out the content items that fail one of the filters' do
          content_items =  [ { content: '"Hello"'} ]
          query_option = 'true_filter and false_filter'

          true_filter = double('filter', is_satisfied_by?: true)
          false_filter = double('filter', is_satisfied_by?: false)

          filter_factory.stub(:get_individual_filter).with('true_filter').and_return(true_filter)
          filter_factory.stub(:get_individual_filter).with('false_filter').and_return(false_filter)

          filters = FilterQueryOption.new(query_option, filter_factory)

          filtered_content_items = filters.apply(content_items)

          expect(filtered_content_items.size).to eq 0
        end
      end



    end
  end
end
{'fraction_non_alphanumeric': 0.12186573200323537, 'fraction_numerical': 0.005931517929361013, 'mean_word_length': 3.507897934386391, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7657270', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1079, 'n_words': 205}