<commit_before># encoding: utf-8

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe XapianDb::DocumentBlueprint do

  before :each do
    XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
  end

  describe ".configured_classes" do

    it "returns all configured classes" do
      XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
      XapianDb::DocumentBlueprint.configured_classes.size.should == 0

      XapianDb::DocumentBlueprint.setup(IndexedObject) do |blueprint|
        blueprint.index :id
        blueprint.index :name
      end
      XapianDb::DocumentBlueprint.configured_classes.size.should == 1
      XapianDb::DocumentBlueprint.configured_classes.first.should == IndexedObject
    end

  end

  describe ".blueprint_for(klass)" do

    it "returns the blueprint for a class" do
      XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
      XapianDb::DocumentBlueprint.setup(IndexedObject) do |blueprint|
        blueprint.index :id
        blueprint.index :name
      end
      XapianDb::DocumentBlueprint.blueprint_for(IndexedObject).should be_a_kind_of XapianDb::DocumentBlueprint
    end

    it "returns the blueprint for the super class if no specific blueprint is configured" do
      XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
      XapianDb::DocumentBlueprint.setup(IndexedObject) do |blueprint|
        blueprint.index :id
        blueprint.index :name
      end
      class InheritedIndexedObject < IndexedObject; end
      XapianDb::DocumentBlueprint.blueprint_for(InheritedIndexedObject).should == XapianDb::DocumentBlueprint.blueprint_for(IndexedObject)
    end

    it "can handle namespaces" do
      XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
      XapianDb::DocumentBlueprint.setup(Namespace::IndexedObject) do |blueprint|
        blueprint.index :id
        blueprint.index :name
      end
      XapianDb::DocumentBlueprint.blueprint_for(Namespace::IndexedObject).should be_a_kind_of XapianDb::DocumentBlueprint
    end

    it "raises an exception if there is no blueprint configuration for a class" do
      lambda {XapianDb::DocumentBlueprint.blueprint_for(Object)}.should raise_error
    end

    it "raises an exception if there is no blueprint configuration at all" do
      XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
      lambda {XapianDb::DocumentBlueprint.blueprint_for(Object)}.should raise_error
    end

  end

  describe ".searchable_prefixes" do

    it "should return an array of all method names configured to be indexed" do
      XapianDb::DocumentBlueprint.setup(IndexedObject) do |blueprint|
        blueprint.index :id
        blueprint.index :name
      end
      XapianDb::DocumentBlueprint.searchable_prefixes.should include(:id, :name)
    end

    it "should return a hash with unique values" do
      XapianDb::DocumentBlueprint.setup(IndexedObject) do |blueprint|
        blueprint.index :id
        blueprint.index :name
      end
      XapianDb::DocumentBlueprint.setup(Object) do |blueprint|
        blueprint.index :id
        blueprint.index :name
      end
      XapianDb::DocumentBlueprint.searchable_prefixes.select{|prefix, options| prefix == :id}.size.should ==1
      XapianDb::DocumentBlueprint.searchable_prefixes.select{|prefix, options| prefix == :name}.size.should ==1
    end

    it "should return an empty array if no blueprints are configured" do
      XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
      XapianDb::DocumentBlueprint.searchable_prefixes.should == []
    end
  end

  describe ".type_info_for(indexed_method)" do

    before :each do
      XapianDb::DocumentBlueprint.setup(IndexedObject) do |blueprint|<commit_msg>deleted obsolete spec<commit_after># encoding: utf-8

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe XapianDb::DocumentBlueprint do

  before :each do
    XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
  end

  describe ".configured_classes" do

    it "returns all configured classes" do
      XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
      XapianDb::DocumentBlueprint.configured_classes.size.should == 0

      XapianDb::DocumentBlueprint.setup(IndexedObject) do |blueprint|
        blueprint.index :id
        blueprint.index :name
      end
      XapianDb::DocumentBlueprint.configured_classes.size.should == 1
      XapianDb::DocumentBlueprint.configured_classes.first.should == IndexedObject
    end

  end

  describe ".blueprint_for(klass)" do

    it "returns the blueprint for a class" do
      XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
      XapianDb::DocumentBlueprint.setup(IndexedObject) do |blueprint|
        blueprint.index :id
        blueprint.index :name
      end
      XapianDb::DocumentBlueprint.blueprint_for(IndexedObject).should be_a_kind_of XapianDb::DocumentBlueprint
    end

    it "returns the blueprint for the super class if no specific blueprint is configured" do
      XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
      XapianDb::DocumentBlueprint.setup(IndexedObject) do |blueprint|
        blueprint.index :id
        blueprint.index :name
      end
      class InheritedIndexedObject < IndexedObject; end
      XapianDb::DocumentBlueprint.blueprint_for(InheritedIndexedObject).should == XapianDb::DocumentBlueprint.blueprint_for(IndexedObject)
    end

    it "can handle namespaces" do
      XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
      XapianDb::DocumentBlueprint.setup(Namespace::IndexedObject) do |blueprint|
        blueprint.index :id
        blueprint.index :name
      end
      XapianDb::DocumentBlueprint.blueprint_for(Namespace::IndexedObject).should be_a_kind_of XapianDb::DocumentBlueprint
    end

    it "raises an exception if there is no blueprint configuration for a class" do
      lambda {XapianDb::DocumentBlueprint.blueprint_for(Object)}.should raise_error
    end

    it "raises an exception if there is no blueprint configuration at all" do
      XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
      lambda {XapianDb::DocumentBlueprint.blueprint_for(Object)}.should raise_error
    end

  end

  describe ".searchable_prefixes" do

    it "should return an array of all method names configured to be indexed" do
      XapianDb::DocumentBlueprint.setup(IndexedObject) do |blueprint|
        blueprint.index :id
        blueprint.index :name
      end
      XapianDb::DocumentBlueprint.searchable_prefixes.should include(:id, :name)
    end

    it "should return an empty array if no blueprints are configured" do
      XapianDb::DocumentBlueprint.instance_variable_set(:@blueprints, nil)
      XapianDb::DocumentBlueprint.searchable_prefixes.should == []
    end
  end

  describe ".type_info_for(indexed_method)" do

    before :each do
      XapianDb::DocumentBlueprint.setup(IndexedObject) do |blueprint|
{'fraction_non_alphanumeric': 0.08222285228239297, 'fraction_numerical': 0.0011341083073433513, 'mean_word_length': 4.046494992846924, 'pattern_counts': {'":': 0, '<': 5, '<?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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4320527', 'n_tokens_mistral': 2121, 'n_tokens_neox': 2076, 'n_words': 459}