Permalink
Browse files

Merge branch 'v1'

Conflicts:
	Gemfile
	thinking-sphinx.gemspec
  • Loading branch information...
2 parents c81bbdf + aead006 commit a1393df4e02d688571ea82456d17b6a8890c2e53 @pat committed Jan 22, 2012
View
@@ -1,12 +1,8 @@
rvm:
- 1.8.7
- - 1.9.2
- - 1.9.3
- rbx
- - rbx-2.0
- ree
- jruby
- - ruby-head
branches:
only:
- master
@@ -15,3 +11,7 @@ branches:
before_script:
- "mysql -e 'create database thinking_sphinx;' > /dev/null"
- "psql -c 'create database thinking_sphinx;' -U postgres >/dev/null"
+gemfiles:
+ - gemfiles/rails_2_1.gemfile
+ - gemfiles/rails_2_2.gemfile
+ - gemfiles/rails_2_3.gemfile
View
@@ -0,0 +1,13 @@
+appraise 'rails_2_1' do
+ gem 'activerecord', '~> 2.1.2'
+ gem 'mysql', '2.8.1', :platform=>:ruby
+end
+
+appraise 'rails_2_2' do
+ gem 'activerecord', '~> 2.2.3'
+ gem 'mysql', '2.8.1', :platform=>:ruby
+end
+
+appraise 'rails_2_3' do
+ gem 'activerecord', '~> 2.3.8'
+end
View
14 Gemfile
@@ -2,14 +2,10 @@ source :rubygems
gemspec
-gem 'rcov', '0.9.8', :platform => :mri_18
+gem 'rcov', '0.9.8', :platform => :mri_18
-platforms :ruby do
- gem 'mysql2', '~> 0.3.7'
- gem 'pg', '~> 0.11.0'
-end
+gem 'mysql2', '~> 0.3.7', :platform => :ruby
+gem 'pg', '~> 0.11.0', :platform => :ruby
-platform :jruby do
- gem 'activerecord-jdbcmysql-adapter', '~> 1.1.3'
- gem 'activerecord-jdbcpostgresql-adapter', '~> 1.1.3'
-end
+gem 'activerecord-jdbcmysql-adapter', '~> 1.1.3', :platform => :jruby
+gem 'activerecord-jdbcpostgresql-adapter', '~> 1.1.3', :platform => :jruby
View
@@ -0,0 +1 @@
+*.gemfile.lock
View
@@ -0,0 +1,13 @@
+# This file was generated by Appraisal
+
+source :rubygems
+
+gem "rcov", "0.9.8", :platform=>:mri_18
+gem "mysql2", "~> 0.2.11", :platform=>:ruby
+gem "pg", "0.9.0", :platform=>:ruby
+gem "activerecord-jdbcmysql-adapter", "~> 1.1.3", :platform=>:jruby
+gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby
+gem "activerecord", "~> 2.1.2"
+gem "mysql", "2.8.1", :platform=>:ruby
+
+gemspec :path=>"../"
View
@@ -0,0 +1,13 @@
+# This file was generated by Appraisal
+
+source :rubygems
+
+gem "rcov", "0.9.8", :platform=>:mri_18
+gem "mysql2", "~> 0.2.11", :platform=>:ruby
+gem "pg", "0.9.0", :platform=>:ruby
+gem "activerecord-jdbcmysql-adapter", "~> 1.1.3", :platform=>:jruby
+gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby
+gem "activerecord", "~> 2.2.3"
+gem "mysql", "2.8.1", :platform=>:ruby
+
+gemspec :path=>"../"
View
@@ -0,0 +1,12 @@
+# This file was generated by Appraisal
+
+source :rubygems
+
+gem "rcov", "0.9.8", :platform=>:mri_18
+gem "mysql2", "~> 0.2.11", :platform=>:ruby
+gem "pg", "0.9.0", :platform=>:ruby
+gem "activerecord-jdbcmysql-adapter", "~> 1.1.3", :platform=>:jruby
+gem "activerecord-jdbcpostgresql-adapter", "~> 1.1.3", :platform=>:jruby
+gem "activerecord", "~> 2.3.8"
+
+gemspec :path=>"../"
@@ -16,11 +16,20 @@ def initialize
@fixtures_directory = "#{pwd}/features/thinking_sphinx/db/fixtures"
@database_file = "#{pwd}/features/thinking_sphinx/database.yml"
- @adapter = (ENV['DATABASE'] || 'mysql').gsub /^mysql$/, 'mysql2'
+ @adapter = (ENV['DATABASE'] || 'mysql')
@database = 'thinking_sphinx'
- @username = @adapter[/mysql/] ? 'root' : 'postgres'
- # @password = 'thinking_sphinx'
+ @username = ENV['USER']
@host = 'localhost'
+
+ if ActiveRecord.constants.include?('VERSION')
+ @adapter.gsub! /^mysql$/, 'mysql2'
+ end
+
+ if @adapter[/mysql/]
+ @username = 'root'
+ elsif ENV['TRAVIS']
+ @username = 'postgres'
+ end
end
def setup
@@ -1,11 +1,11 @@
module ThinkingSphinx
class Facet
attr_reader :property, :value_source
-
+
def initialize(property, value_source = nil)
@property = property
@value_source = value_source
-
+
if property.columns.length != 1
raise "Can't translate Facets on multiple-column field or attribute"
end
@@ -20,11 +20,11 @@ def self.name_for(facet)
facet.to_s.gsub(/(_facet|_crc)$/,'').to_sym
end
end
-
+
def self.attribute_name_for(name)
name.to_s == 'class' ? 'class_crc' : "#{name}_facet"
end
-
+
def self.attribute_name_from_value(name, value)
case value
when String
@@ -39,10 +39,10 @@ def self.attribute_name_from_value(name, value)
name
end
end
-
+
def self.translate?(property)
return true if property.is_a?(Field)
-
+
case property.type
when :string
true
@@ -52,35 +52,35 @@ def self.translate?(property)
!property.all_ints?
end
end
-
+
def name
property.unique_name
end
-
+
def attribute_name
if translate?
Facet.attribute_name_for(@property.unique_name)
else
@property.unique_name.to_s
end
end
-
+
def translate?
Facet.translate?(@property)
end
-
+
def type
@property.is_a?(Field) ? :string : @property.type
end
-
+
def float?
@property.type == :float
end
-
+
def value(object, attribute_hash)
attribute_value = attribute_hash['@groupby']
return translate(object, attribute_value) if translate? || float?
-
+
case @property.type
when :datetime
Time.at(attribute_value)
@@ -90,13 +90,13 @@ def value(object, attribute_hash)
attribute_value
end
end
-
+
def to_s
name
end
-
+
private
-
+
def translate(object, attribute_value)
objects = source_objects(object)
return if objects.blank?
@@ -107,20 +107,20 @@ def translate(object, attribute_value)
result && result.to_crc32 == attribute_value
}
- object.try(method)
+ object ? object.send(method) : nil
end
-
+
def source_objects(object)
column.__stack.each { |method|
object = Array(object).collect { |item|
item.send(method)
}.flatten.compact
-
+
return nil if object.empty?
}
Array(object)
end
-
+
def column
@property.columns.first
end
View
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'builder', '>= 2.1.2'
s.add_development_dependency 'actionpack', '>= 3.0.3'
+ s.add_development_dependency 'appraisal', '0.4.0'
s.add_development_dependency 'cucumber', '1.0.2'
s.add_development_dependency 'faker', '0.3.1'
s.add_development_dependency 'rake', '>= 0.9.2'

0 comments on commit a1393df

Please sign in to comment.