<commit_before>require 'rails_helper'
require_relative '../page_searcher_spec_data.rb'

describe 'Search ::' do
  describe 'PageSearcher' do
    context 'searches by single criterion,' do
      context 'by tag' do
        include_context 'page_searcher_spec_data'
        let!(:has_many_tags) {
          create(:page,
                 title: 'a very taggy page',
                 tags: [alternative_tag, the_best_tag],
          )
        }
        let!(:intersection_page_1) {
          create(:page,
                 title: 'has one same tag as intersection page 2',
                 tags: [tag1, tag2, tag3, tag4],
          )
        }

        let!(:intersection_page_2) {
          create(:page,
                 title: 'has one same tag as intersection page 1',
                 tags: [tag3, tag4, tag5],
          )
        }
        let(:tag_searcher) { Search::PageSearcher.new({search: {tags: [tag.id]} }) }
        it 'searches for a page based on the tags on that page' do
          expect(tag_searcher.search).to match_array([content_tag_plugin_layout_match])
        end

        describe 'does not filter by tag when searching' do
          it 'with an empty tag array' do
            expect((Search::PageSearcher.new({search: {tags: []}})).search).to match_array(Page.all)
          end
          it 'with tag array set to nil' do
            expect((Search::PageSearcher.new({search: {tags: nil}})).search).to match_array(Page.all)
          end
          it 'with an empty string' do
            expect((Search::PageSearcher.new({search: {tags: ''}})).search).to match_array(Page.all)
          end
        end
        describe 'does not return any pages when searching' do
          it 'with a non-existent tag id' do
            expect((Search::PageSearcher.new({search: {tags: [Tag.last.id+1]}})).search).to match_array([])
          end
          it 'with an unused tag' do
            expect((Search::PageSearcher.new({search: {tags: [unused_tag.id]}})).search).to match_array([])
          end
          it 'with a used tag and an unused tag' do
            expect((Search::PageSearcher.new({search: {tags: [unused_tag.id, tag.id]}})).search).to match_array([])
          end

          it 'with two used tags never used on the same page' do
            expect((Search::PageSearcher.new({search: {tags: [tag.id, alternative_tag.id]}})).search).to match_array([])<commit_msg>Declare slug to stop validation error<commit_after>require 'rails_helper'
require_relative '../page_searcher_spec_data.rb'

describe 'Search ::' do
  describe 'PageSearcher' do
    context 'searches by single criterion,' do
      context 'by tag' do
        include_context 'page_searcher_spec_data'
        let!(:has_many_tags) {
          create(:page,
                 title: 'a very taggy page',
                 tags: [alternative_tag, the_best_tag],
          )
        }
        let!(:intersection_page_1) {
          create(:page,
                 title: 'has one same tag as intersection page 2',
                 slug:  'has-same-page-2',
                 tags:  [tag1, tag2, tag3, tag4]
          )
        }

        let!(:intersection_page_2) {
          create(:page,
                 title: 'has one same tag as intersection page 1',
                 slug:  'has-same-page-1',
                 tags:  [tag3, tag4, tag5]
          )
        }
        let(:tag_searcher) { Search::PageSearcher.new({search: {tags: [tag.id]} }) }
        it 'searches for a page based on the tags on that page' do
          expect(tag_searcher.search).to match_array([content_tag_plugin_layout_match])
        end

        describe 'does not filter by tag when searching' do
          it 'with an empty tag array' do
            expect((Search::PageSearcher.new({search: {tags: []}})).search).to match_array(Page.all)
          end
          it 'with tag array set to nil' do
            expect((Search::PageSearcher.new({search: {tags: nil}})).search).to match_array(Page.all)
          end
          it 'with an empty string' do
            expect((Search::PageSearcher.new({search: {tags: ''}})).search).to match_array(Page.all)
          end
        end
        describe 'does not return any pages when searching' do
          it 'with a non-existent tag id' do
            expect((Search::PageSearcher.new({search: {tags: [Tag.last.id+1]}})).search).to match_array([])
          end
          it 'with an unused tag' do
            expect((Search::PageSearcher.new({search: {tags: [unused_tag.id]}})).search).to match_array([])
          end
          it 'with a used tag and an unused tag' do
            expect((Search::PageSearcher.new({search: {tags: [unused_tag.id, tag.id]}})).search).to match_array([])
          end

          it 'with two used tags never used on the same page' do
            expect((Search::PageSearcher.new({search: {tags: [tag.id, alternative_tag.id]}})).search).to match_array([])
{'fraction_non_alphanumeric': 0.12382892057026476, 'fraction_numerical': 0.005295315682281059, 'mean_word_length': 2.15211810012837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7663555', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1452, 'n_words': 396}