<commit_before>require 'spec/spec_helper'

describe ThinkingSphinx do
  it "should define indexes by default" do
    ThinkingSphinx.define_indexes?.should be_true
  end
  
  it "should disable index definition" do
    ThinkingSphinx.define_indexes = false
    ThinkingSphinx.define_indexes?.should be_false
  end
  
  it "should enable index definition" do
    ThinkingSphinx.define_indexes = false
    ThinkingSphinx.define_indexes?.should be_false
    ThinkingSphinx.define_indexes = true
    ThinkingSphinx.define_indexes?.should be_true
  end
  
  it "should index deltas by default" do
    ThinkingSphinx.deltas_enabled = nil
    ThinkingSphinx.deltas_enabled?.should be_true
  end
  
  it "should disable delta indexing" do
    ThinkingSphinx.deltas_enabled = false
    ThinkingSphinx.deltas_enabled?.should be_false
  end
  
  it "should enable delta indexing" do
    ThinkingSphinx.deltas_enabled = false
    ThinkingSphinx.deltas_enabled?.should be_false
    ThinkingSphinx.deltas_enabled = true
    ThinkingSphinx.deltas_enabled?.should be_true
  end
  
  it "should update indexes by default" do
    ThinkingSphinx.updates_enabled = nil
    ThinkingSphinx.updates_enabled?.should be_true
  end
  
  it "should disable index updating" do
    ThinkingSphinx.updates_enabled = false
    ThinkingSphinx.updates_enabled?.should be_false
  end
  
  it "should enable index updating" do
    ThinkingSphinx.updates_enabled = false
    ThinkingSphinx.updates_enabled?.should be_false
    ThinkingSphinx.updates_enabled = true
    ThinkingSphinx.updates_enabled?.should be_true
  end
  
  it "should always say Sphinx is running if flagged as being on a remote machine" do
    ThinkingSphinx.remote_sphinx = true
    ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
    
    ThinkingSphinx.sphinx_running?.should be_true
  end
  
  it "should actually pay attention to Sphinx if not on a remote machine" do
    ThinkingSphinx.remote_sphinx = false
    ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
    ThinkingSphinx.sphinx_running?.should be_false
    
    ThinkingSphinx.stub!(:sphinx_running_by_pid? => true)
    ThinkingSphinx.sphinx_running?.should be_true
  end
  
  describe '.version' do
    it "should return the version from the stored YAML file" do
      version = Jeweler::VersionHelper.new(
        File.join(File.dirname(__FILE__), '../..')
      ).to_s
      
      ThinkingSphinx.version.should == version
    end
  end
  
  describe "use_group_by_shortcut? method" do
    before :each do
      adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
      unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
        pending "No MySQL"
        return
      end
      
      @connection = stub('adapter',
        :select_all => true,
        :class      => ActiveRecord::ConnectionAdapters::MysqlAdapter,
        :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'}
      )
      ::ActiveRecord::Base.stub!(
        :connection => @connection
      )
    end
    
    it "should return true if no ONLY_FULL_GROUP_BY" do
      @connection.stub!(<commit_msg>Fixing specs that once passed, then didn't, with no code changes. Code's better this way, resetting avariable for each example.<commit_after>require 'spec/spec_helper'

describe ThinkingSphinx do
  it "should define indexes by default" do
    ThinkingSphinx.define_indexes?.should be_true
  end
  
  it "should disable index definition" do
    ThinkingSphinx.define_indexes = false
    ThinkingSphinx.define_indexes?.should be_false
  end
  
  it "should enable index definition" do
    ThinkingSphinx.define_indexes = false
    ThinkingSphinx.define_indexes?.should be_false
    ThinkingSphinx.define_indexes = true
    ThinkingSphinx.define_indexes?.should be_true
  end
  
  it "should index deltas by default" do
    ThinkingSphinx.deltas_enabled = nil
    ThinkingSphinx.deltas_enabled?.should be_true
  end
  
  it "should disable delta indexing" do
    ThinkingSphinx.deltas_enabled = false
    ThinkingSphinx.deltas_enabled?.should be_false
  end
  
  it "should enable delta indexing" do
    ThinkingSphinx.deltas_enabled = false
    ThinkingSphinx.deltas_enabled?.should be_false
    ThinkingSphinx.deltas_enabled = true
    ThinkingSphinx.deltas_enabled?.should be_true
  end
  
  it "should update indexes by default" do
    ThinkingSphinx.updates_enabled = nil
    ThinkingSphinx.updates_enabled?.should be_true
  end
  
  it "should disable index updating" do
    ThinkingSphinx.updates_enabled = false
    ThinkingSphinx.updates_enabled?.should be_false
  end
  
  it "should enable index updating" do
    ThinkingSphinx.updates_enabled = false
    ThinkingSphinx.updates_enabled?.should be_false
    ThinkingSphinx.updates_enabled = true
    ThinkingSphinx.updates_enabled?.should be_true
  end
  
  it "should always say Sphinx is running if flagged as being on a remote machine" do
    ThinkingSphinx.remote_sphinx = true
    ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
    
    ThinkingSphinx.sphinx_running?.should be_true
  end
  
  it "should actually pay attention to Sphinx if not on a remote machine" do
    ThinkingSphinx.remote_sphinx = false
    ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
    ThinkingSphinx.sphinx_running?.should be_false
    
    ThinkingSphinx.stub!(:sphinx_running_by_pid? => true)
    ThinkingSphinx.sphinx_running?.should be_true
  end
  
  describe '.version' do
    it "should return the version from the stored YAML file" do
      version = Jeweler::VersionHelper.new(
        File.join(File.dirname(__FILE__), '../..')
      ).to_s
      
      ThinkingSphinx.version.should == version
    end
  end
  
  describe "use_group_by_shortcut? method" do
    before :each do
      adapter = defined?(JRUBY_VERSION) ? :JdbcAdapter : :MysqlAdapter
      unless ::ActiveRecord::ConnectionAdapters.const_defined?(adapter)
        pending "No MySQL"
        return
      end
      
      @connection = stub('adapter',
        :select_all => true,
        :class      => ActiveRecord::ConnectionAdapters::MysqlAdapter,
        :config => {:adapter => defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'}
      )
      ::ActiveRecord::Base.stub!(
        :connection => @connection
      )
      
      ThinkingSphinx.module_eval do
        class_variable_set :@@use_group_by_shortcut, nil
      end
    end
    
    it "should return true if no ONLY_FULL_GROUP_BY" do
      @connection.stub!(
{'fraction_non_alphanumeric': 0.07248611967921037, 'fraction_numerical': 0.0, 'mean_word_length': 3.3995929443690636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7227116', 'n_tokens_mistral': 2130, 'n_tokens_neox': 2114, 'n_words': 482}