Permalink
Browse files

Merge branch 'v1'

  • Loading branch information...
2 parents 6bf8874 + 01c72a0 commit 648e6392395014abbd310006db03a28a5288ff16 @pat pat committed May 11, 2012
Showing with 23 additions and 10 deletions.
  1. +21 −4 lib/thinking_sphinx/source/sql.rb
  2. +2 −6 spec/thinking_sphinx/active_record_spec.rb
@@ -123,24 +123,34 @@ def crc_column
return @model.to_crc32.to_s if types.empty?
adapter.case(adapter.convert_nulls(
- adapter.quote_with_table(@model.inheritance_column)),
+ adapter.quote_with_table(@model.inheritance_column), @model.name),
types, @model.to_crc32)
else
@model.to_crc32.to_s
end
end
def internal_class_column
+ quoted_name = "'#{@model.name}'"
+
if @model.table_exists? &&
@model.column_names.include?(@model.inheritance_column)
- adapter.quote_with_table(@model.inheritance_column)
+
+ types = types_to_hash
+ return quoted_name if types.empty?
+
+ adapter.case(adapter.convert_nulls(
+ adapter.quote_with_table(@model.inheritance_column), @model.name),
+ types, quoted_name)
else
- "'#{@model.name}'"
+ quoted_name
end
end
def type_values
- @model.sphinx_types.presence or @model.connection.select_values <<-SQL
+ return @model.sphinx_types unless @model.sphinx_types.nil?
+
+ @model.connection.select_values <<-SQL
SELECT DISTINCT #{@model.inheritance_column}
FROM #{@model.table_name}
SQL
@@ -152,6 +162,13 @@ def types_to_crcs
hash
}
end
+
+ def types_to_hash
+ type_values.compact.inject({}) { |hash, type|
+ hash[type] = "'#{type}'"
+ hash
+ }
+ end
end
end
end
@@ -420,21 +420,17 @@
end
describe '#types_for_sphinx' do
- before :each do
- @person = Person.find(:first)
- end
-
after :each do
Person.set_sphinx_types nil
end
it "should return nil by default" do
- @person.sphinx_types.should == nil
+ Person.sphinx_types.should == nil
end
it "should return the specified value" do
Person.set_sphinx_types %w(Person Parent)
- @person.sphinx_types.should == %w(Person Parent)
+ Person.sphinx_types.should == %w(Person Parent)
end
end

0 comments on commit 648e639

Please sign in to comment.