Skip to content

Commit

Permalink
Use array instead of splat on search initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
eddloschi committed Mar 14, 2014
1 parent 409184e commit 196dff5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/mongoid/giza.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def process_dynamic_sphinx_index(dynamic_index)
# @return [Array] an Array with Riddle result hashes containing an additional key with the name of the class.
# The value of this aditional key is a Mongoid::Criteria that return the actual objects of the match
def search(&block)
search = Mongoid::Giza::Search.new(giza_configuration.searchd.address, giza_configuration.searchd.port, *sphinx_indexes_names)
search = Mongoid::Giza::Search.new(giza_configuration.searchd.address, giza_configuration.searchd.port, sphinx_indexes_names)
Docile.dsl_eval(search, &block)
results = search.run
results.each { |result| result[name.to_sym] = self.in(giza_id: result[:matches].map { |match| match[:doc] }) }
Expand Down
8 changes: 4 additions & 4 deletions lib/mongoid/giza/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class Search
#
# @param host [String] the host address of sphinxd
# @param port [Fixnum] the TCP port of sphinxd
# @param indexes [String] an optional string define the indexes that the search will run on.
# Defaults to "*" which means all indexes
def initialize(host, port, *indexes)
# @param names [Array] an optional array defining the indexes that the search will run on.
# Defaults to "[]" which means all indexes
def initialize(host, port, names = [])
@client = Riddle::Client.new(host, port)
@indexes = indexes
@indexes = names
end

# Sets the search criteria on full-text fields
Expand Down
2 changes: 1 addition & 1 deletion spec/mongoid/giza/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
end

it "should accept a index list" do
indexes = Mongoid::Giza::Search.new("localhost", 9132, :index1, :index2).indexes
indexes = Mongoid::Giza::Search.new("localhost", 9132, [:index1, :index2]).indexes
expect(indexes).to eql([:index1, :index2])
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/mongoid/giza_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Person

let(:search) do
search = double("search")
allow(Mongoid::Giza::Search).to receive(:new).with("localhost", 9132) { search }
allow(Mongoid::Giza::Search).to receive(:new).with("localhost", 9132, []) { search }
search
end

Expand Down Expand Up @@ -145,7 +145,7 @@ class Person
end

it "should create a search" do
expect(Mongoid::Giza::Search).to receive(:new).with("localhost", 9132, :Person, :Person_2) { double("search").as_null_object }
expect(Mongoid::Giza::Search).to receive(:new).with("localhost", 9132, [:Person, :Person_2]) { double("search").as_null_object }
Person.sphinx_index { }
Person.sphinx_index { name :Person_2 }
Person.search { }
Expand Down

0 comments on commit 196dff5

Please sign in to comment.