Skip to content

Commit

Permalink
Merge pull request #875 from bricker/result-array
Browse files Browse the repository at this point in the history
Convert raw results to array
  • Loading branch information
pat committed Jan 1, 2015
2 parents c22d11b + 8673ab5 commit f71dc81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/thinking_sphinx/middlewares/inquirer.rb
Expand Up @@ -44,7 +44,7 @@ def initialize(context)
end

def call(raw_results, meta_results)
context[:results] = raw_results
context[:results] = raw_results.to_a
context[:raw] = raw_results
context[:meta] = meta_results.inject({}) { |hash, row|
hash[row['Variable_name']] = row['Value']
Expand Down
19 changes: 19 additions & 0 deletions spec/thinking_sphinx/middlewares/inquirer_spec.rb
Expand Up @@ -47,5 +47,24 @@ module Middlewares; end

context[:results].should == [:raw]
end

context "with mysql2 result" do
class FakeResult
include Enumerable
def each; [{"fake" => "value"}].each { |m| yield m }; end
end

let(:batch_inquirer) { double('batcher', :append_query => true,
:results => [
FakeResult.new, [{'Variable_name' => 'meta', 'Value' => 'value'}]
])
}

it "converts the results into an array" do
middleware.call [context]

context[:results].should be_a Array
end
end
end
end

0 comments on commit f71dc81

Please sign in to comment.