Permalink
Browse files

Merge branch 'master' of git://github.com/freelancing-god/thinking-sp…

…hinx
  • Loading branch information...
2 parents 59b890c + 4c0e214 commit fdd6e40f22c13c4aa0cb38d00e0f97b1621cad9a @johnny committed Nov 19, 2009
View
@@ -0,0 +1 @@
+1.3.5
View
@@ -1,5 +0,0 @@
----
-:patch: 4
-:major: 1
-:build:
-:minor: 3
@@ -23,5 +23,5 @@ Feature: Searching on a single model
When I destroy robot Expendable
And I wait for Sphinx to catch up
- And I search for three
+ And I search for Expendable
Then I should get 0 results
@@ -1,40 +0,0 @@
-require 'yaml'
-require 'active_record'
-
-# Database Defaults
-host = "localhost"
-username = "thinking_sphinx"
-password = nil
-
-# Read in YAML file
-if File.exist?("features/support/db/database.yml")
- config = YAML.load open("features/support/db/database.yml")
- host = config["host"] || host
- username = config["username"] || username
- password = config["password"] || password
-end
-
-# Set up Connection
-ActiveRecord::Base.establish_connection(
- :adapter => Database,
- :database => 'thinking_sphinx',
- :username => username,
- :password => password,
- :host => host
-)
-
-# Copied from ActiveRecord's test suite
-ActiveRecord::Base.connection.class.class_eval do
- IGNORED_SQL = [
- /^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/,
- /^SELECT @@ROWCOUNT/, /^SHOW FIELDS/
- ]
-
- def execute_with_query_record(sql, name = nil, &block)
- $queries_executed ||= []
- $queries_executed << sql unless IGNORED_SQL.any? { |r| sql =~ r }
- execute_without_query_record(sql, name, &block)
- end
-
- alias_method_chain :execute, :query_record
-end
@@ -1,3 +0,0 @@
-require 'active_record'
-Database = defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql'
-require "active_record/connection_adapters/#{Database}_adapter"
@@ -1,3 +0,0 @@
-require 'active_record'
-Database = defined?(JRUBY_VERSION) ? 'jdbcpostgresql' : 'postgresql'
-require "active_record/connection_adapters/#{Database}_adapter"
@@ -1,43 +0,0 @@
-$:.unshift File.dirname(__FILE__) + '/../../lib'
-
-require 'lib/thinking_sphinx'
-
-%w( tmp/config tmp/log tmp/db/sphinx/development ).each do |path|
- FileUtils.mkdir_p "#{Dir.pwd}/#{path}"
-end
-
-Kernel.const_set :RAILS_ROOT, "#{Dir.pwd}/tmp" unless defined?(RAILS_ROOT)
-
-at_exit do
- ThinkingSphinx::Configuration.instance.controller.stop
- sleep(1) # Ensure Sphinx has shut down completely
- ActiveRecord::Base.logger.close
- FileUtils.rm_r "#{Dir.pwd}/tmp"
-end
-
-# Add log file
-ActiveRecord::Base.logger = Logger.new open("tmp/active_record.log", "a")
-
-# Set up database tables
-Dir["features/support/db/migrations/*.rb"].each do |file|
- require file.gsub(/\.rb$/, '')
-end
-
-# Load Models
-Dir["features/support/models/*.rb"].sort.each do |file|
- require file.gsub(/\.rb$/, '')
-end
-
-ThinkingSphinx.deltas_enabled = false
-
-# Load Fixtures
-Dir["features/support/db/fixtures/*.rb"].each do |file|
- require file.gsub(/\.rb$/, '')
-end
-
-ThinkingSphinx.deltas_enabled = true
-ThinkingSphinx.suppress_delta_output = true
-
-ThinkingSphinx::Configuration.instance.build
-ThinkingSphinx::Configuration.instance.controller.index
-ThinkingSphinx::Configuration.instance.controller.start
@@ -52,100 +52,109 @@ def initialize(ids)
# @return [String] The version number as a string
#
def self.version
- hash = YAML.load_file File.join(File.dirname(__FILE__), '../VERSION.yml')
- [hash[:major], hash[:minor], hash[:patch]].join('.')
+ open(File.join(File.dirname(__FILE__), '../VERSION')) { |f|
+ f.read.strip
+ }
end
# The collection of indexed models. Keep in mind that Rails lazily loads
# its classes, so this may not actually be populated with _all_ the models
# that have Sphinx indexes.
def self.indexed_models
- @@indexed_models ||= []
+ Thread.current[:thinking_sphinx_indexed_models] ||= []
end
def self.unique_id_expression(offset = nil)
- "* #{ThinkingSphinx.indexed_models.size} + #{offset || 0}"
+ "* #{indexed_models.size} + #{offset || 0}"
end
# Check if index definition is disabled.
#
def self.define_indexes?
- @@define_indexes = true unless defined?(@@define_indexes)
- @@define_indexes == true
+ if Thread.current[:thinking_sphinx_define_indexes].nil?
+ Thread.current[:thinking_sphinx_define_indexes] = true
+ end
+
+ Thread.current[:thinking_sphinx_define_indexes]
end
# Enable/disable indexes - you may want to do this while migrating data.
#
# ThinkingSphinx.define_indexes = false
#
def self.define_indexes=(value)
- @@define_indexes = value
+ Thread.current[:thinking_sphinx_define_indexes] = value
end
- @@deltas_enabled = nil
-
# Check if delta indexing is enabled.
#
def self.deltas_enabled?
- @@deltas_enabled = (ThinkingSphinx::Configuration.environment != 'test') if @@deltas_enabled.nil?
- @@deltas_enabled
+ if Thread.current[:thinking_sphinx_deltas_enabled].nil?
+ Thread.current[:thinking_sphinx_deltas_enabled] = (
+ ThinkingSphinx::Configuration.environment != "test"
+ )
+ end
+
+ Thread.current[:thinking_sphinx_deltas_enabled]
end
# Enable/disable all delta indexing.
#
# ThinkingSphinx.deltas_enabled = false
#
def self.deltas_enabled=(value)
- @@deltas_enabled = value
+ Thread.current[:thinking_sphinx_deltas_enabled] = value
end
- @@updates_enabled = nil
-
# Check if updates are enabled. True by default, unless within the test
# environment.
#
def self.updates_enabled?
- @@updates_enabled = (ThinkingSphinx::Configuration.environment != 'test') if @@updates_enabled.nil?
- @@updates_enabled
+ if Thread.current[:thinking_sphinx_updates_enabled].nil?
+ Thread.current[:thinking_sphinx_updates_enabled] = (
+ ThinkingSphinx::Configuration.environment != "test"
+ )
+ end
+
+ Thread.current[:thinking_sphinx_updates_enabled]
end
# Enable/disable updates to Sphinx
#
# ThinkingSphinx.updates_enabled = false
#
def self.updates_enabled=(value)
- @@updates_enabled = value
+ Thread.current[:thinking_sphinx_updates_enabled] = value
end
- @@suppress_delta_output = false
-
def self.suppress_delta_output?
- @@suppress_delta_output
+ Thread.current[:thinking_sphinx_suppress_delta_output] ||= false
end
def self.suppress_delta_output=(value)
- @@suppress_delta_output = value
+ Thread.current[:thinking_sphinx_suppress_delta_output] = value
end
- @@use_group_by_shortcut = nil
# Checks to see if MySQL will allow simplistic GROUP BY statements. If not,
# or if not using MySQL, this will return false.
#
def self.use_group_by_shortcut?
- @@use_group_by_shortcut ||= !!(
- mysql? && ::ActiveRecord::Base.connection.select_all(
- "SELECT @@global.sql_mode, @@session.sql_mode;"
- ).all? { |key,value| value.nil? || value[/ONLY_FULL_GROUP_BY/].nil? }
- )
+ if Thread.current[:thinking_sphinx_use_group_by_shortcut].nil?
+ Thread.current[:thinking_sphinx_use_group_by_shortcut] = !!(
+ mysql? && ::ActiveRecord::Base.connection.select_all(
+ "SELECT @@global.sql_mode, @@session.sql_mode;"
+ ).all? { |key,value| value.nil? || value[/ONLY_FULL_GROUP_BY/].nil? }
+ )
+ end
+
+ Thread.current[:thinking_sphinx_use_group_by_shortcut]
end
- @@remote_sphinx = false
-
# An indication of whether Sphinx is running on a remote machine instead of
# the same machine.
#
def self.remote_sphinx?
- @@remote_sphinx
+ Thread.current[:thinking_sphinx_remote_sphinx] ||= false
end
# Tells Thinking Sphinx that Sphinx is running on a different machine, and
@@ -157,7 +166,7 @@ def self.remote_sphinx?
# ThinkingSphinx.remote_sphinx = true
#
def self.remote_sphinx=(value)
- @@remote_sphinx = value
+ Thread.current[:thinking_sphinx_remote_sphinx] = value
end
# Check if Sphinx is running. If remote_sphinx is set to true (indicating
@@ -124,7 +124,7 @@ def reset(custom_app_root=nil)
end
def self.environment
- @@environment ||= (
+ Thread.current[:thinking_sphinx_environment] ||= (
defined?(Merb) ? Merb.environment : ENV['RAILS_ENV']
) || "development"
end
@@ -3,8 +3,8 @@
describe ThinkingSphinx::Configuration do
describe "environment class method" do
before :each do
- ThinkingSphinx::Configuration.send(:class_variable_set, :@@environment, nil)
-
+ Thread.current[:thinking_sphinx_environment] = nil
+
ENV["RAILS_ENV"] = nil
end
Oops, something went wrong. Retry.

0 comments on commit fdd6e40

Please sign in to comment.