Skip to content

Commit

Permalink
Merge branch 'master' into rails3
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Nov 18, 2010
2 parents b288f9c + 89b517e commit edcc48a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/thinking_sphinx/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,22 @@ def include_for_class(klass)
includes.select { |inc| klass.reflections[inc] }
when Symbol
klass.reflections[includes].nil? ? nil : includes
when Hash
include_from_hash includes, klass
else
includes
end
end

def include_from_hash(hash, klass)
scoped_hash = {}
hash.keys.each do |key|
scoped_hash[key] = hash[key] unless klass.reflections[key].nil?
end

scoped_hash.empty? ? nil : scoped_hash
end

def instances_from_class(klass, matches)
index_options = klass.sphinx_index_options

Expand Down
26 changes: 26 additions & 0 deletions spec/thinking_sphinx/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,32 @@
ThinkingSphinx::Search.new(:include => :betas).first
end

it "should respect complex includes" do
Alpha.should_receive(:find) do |type, options|
options[:include].should == {:betas => :gammas}
[@alpha_a, @alpha_b]
end

Beta.should_receive(:find) do |type, options|
options[:include].should be_nil
[@beta_a, @beta_b]
end

ThinkingSphinx::Search.new(:include => {:betas => :gammas}).first
end

it "should respect includes for single class searches" do
Alpha.should_receive(:find) do |type, options|
options[:include].should == {:betas => :gammas}
[@alpha_a, @alpha_b]
end

ThinkingSphinx::Search.new(
:include => {:betas => :gammas},
:classes => [Alpha]
).first
end

describe 'query' do
it "should concatenate arguments with spaces" do
@client.should_receive(:query) do |query, index, comment|
Expand Down

0 comments on commit edcc48a

Please sign in to comment.