<commit_before>require 'spec_helper'

describe ThinkingSphinx::ActiveRecord::SQLSource do
  let(:model)      { double('model', :connection => connection,
    :name => 'User', :column_names => [], :inheritance_column => 'type',
    :primary_key => :id) }
  let(:connection) {
    double('connection', :instance_variable_get => db_config) }
  let(:db_config)  { {:host => 'localhost', :user => 'root',
    :database => 'default'} }
  let(:source)     { ThinkingSphinx::ActiveRecord::SQLSource.new(model,
    :position => 3) }
  let(:adapter)    { double('adapter') }

  before :each do
    ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter.
      stub!(:=== => true)
    ThinkingSphinx::ActiveRecord::DatabaseAdapters.
      stub!(:adapter_for => adapter)
  end

  describe '#adapter' do
    it "returns a database adapter for the model" do
      ThinkingSphinx::ActiveRecord::DatabaseAdapters.
        should_receive(:adapter_for).with(model).and_return(adapter)

      source.adapter.should == adapter
    end
  end

  describe '#attributes' do
    it "has the internal id attribute by default" do
      source.attributes.collect(&:name).should include('sphinx_internal_id')
    end

    it "has the class name attribute by default" do
      source.attributes.collect(&:name).should include('sphinx_internal_class')
    end

    it "has the internal deleted attribute by default" do
      source.attributes.collect(&:name).should include('sphinx_deleted')
    end

    it "marks the internal class attribute as a facet" do
      source.attributes.detect { |attribute|
        attribute.name == 'sphinx_internal_class'
      }.options[:facet].should be_true
    end
  end

  describe '#delta_processor' do
    let(:processor_class) { double('processor class', :try => processor) }
    let(:processor)       { double('processor') }
    let(:source)          {
      ThinkingSphinx::ActiveRecord::SQLSource.new model,
        :delta_processor => processor_class
    }

    it "loads the processor with the adapter" do
      processor_class.should_receive(:try).with(:new, adapter, {}).
        and_return processor

      source.delta_processor
    end

    it "returns the given processor" do
      source.delta_processor.should == processor
    end
  end

  describe '#delta?' do<commit_msg>Added a new test in ThinkingSphinx::ActiveRecord::SQLSource#delta_processor spec to test delta_options<commit_after>require 'spec_helper'

describe ThinkingSphinx::ActiveRecord::SQLSource do
  let(:model)      { double('model', :connection => connection,
    :name => 'User', :column_names => [], :inheritance_column => 'type',
    :primary_key => :id) }
  let(:connection) {
    double('connection', :instance_variable_get => db_config) }
  let(:db_config)  { {:host => 'localhost', :user => 'root',
    :database => 'default'} }
  let(:source)     { ThinkingSphinx::ActiveRecord::SQLSource.new(model,
    :position => 3) }
  let(:adapter)    { double('adapter') }

  before :each do
    ThinkingSphinx::ActiveRecord::DatabaseAdapters::MySQLAdapter.
      stub!(:=== => true)
    ThinkingSphinx::ActiveRecord::DatabaseAdapters.
      stub!(:adapter_for => adapter)
  end

  describe '#adapter' do
    it "returns a database adapter for the model" do
      ThinkingSphinx::ActiveRecord::DatabaseAdapters.
        should_receive(:adapter_for).with(model).and_return(adapter)

      source.adapter.should == adapter
    end
  end

  describe '#attributes' do
    it "has the internal id attribute by default" do
      source.attributes.collect(&:name).should include('sphinx_internal_id')
    end

    it "has the class name attribute by default" do
      source.attributes.collect(&:name).should include('sphinx_internal_class')
    end

    it "has the internal deleted attribute by default" do
      source.attributes.collect(&:name).should include('sphinx_deleted')
    end

    it "marks the internal class attribute as a facet" do
      source.attributes.detect { |attribute|
        attribute.name == 'sphinx_internal_class'
      }.options[:facet].should be_true
    end
  end

  describe '#delta_processor' do
    let(:processor_class) { double('processor class', :try => processor) }
    let(:processor)       { double('processor') }
    let(:source)          {
      ThinkingSphinx::ActiveRecord::SQLSource.new model,
        :delta_processor => processor_class
    }
    let(:source_with_options)    {
      ThinkingSphinx::ActiveRecord::SQLSource.new model,
        :delta_processor => processor_class,
        :delta_options   => { :opt_key => :opt_value }
    }

    it "loads the processor with the adapter" do
      processor_class.should_receive(:try).with(:new, adapter, {}).
        and_return processor

      source.delta_processor
    end

    it "returns the given processor" do
      source.delta_processor.should == processor
    end

    it "passes given options to the processor" do
      processor_class.should_receive(:try).with(:new, adapter, {:opt_key => :opt_value})
      source_with_options.delta_processor
    end
  end

  describe '#delta?' do
{'fraction_non_alphanumeric': 0.12088993896436306, 'fraction_numerical': 0.00039377830281551486, 'mean_word_length': 3.593128390596745, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '251220', 'n_tokens_mistral': 1496, 'n_tokens_neox': 1451, 'n_words': 350}