Skip to content

Commit

Permalink
Merge a432fc1 into 85518d9
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieniebieski committed Aug 28, 2014
2 parents 85518d9 + a432fc1 commit 7ac071f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/searchlight/search.rb
Expand Up @@ -13,7 +13,14 @@ def initialize(options = {})
end

def search
@search ||= self.class.search_target
@search ||= begin
target = self.class.search_target
if target.respond_to?(:call)
target.call
else
target
end
end
end

def results
Expand Down
11 changes: 11 additions & 0 deletions spec/searchlight/search_spec.rb
Expand Up @@ -329,6 +329,17 @@ def search_age; end
expect(search.search).to eq(MockModel)
end

context "when target is a proc" do
let(:proc_result) { 'some string' }
let(:proc_search_target) { -> { proc_result } }
let(:search_class) { AccountSearch }
let(:search) { search_class.new }

it "returns proc result" do
search_class.search_on proc_search_target
expect(search.search).to eq(proc_result)
end
end
end

describe "results" do
Expand Down

0 comments on commit 7ac071f

Please sign in to comment.