Skip to content

Commit

Permalink
mocking connection in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mwmitchell committed Feb 7, 2010
1 parent c60300b commit 8c5b6fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/rsolr-ext/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def map input_params

# remove the input :q params
output[:q] = input.delete :q
output[:fq] = input.delete :fq
output[:fq] = input.delete(:fq) if input[:fq]

if queries = input.delete(:queries)
output[:q] = append_to_param output[:q], build_query(queries, false)
Expand Down
29 changes: 25 additions & 4 deletions spec/rsolr-ext_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,44 @@
end

it 'should produce results from the #find method' do
response = connection.find :page=>3, :per_page=>10, :q=>'*:*'#, :page=>1, :per_page=>10
c = connection
c.should_receive(:request).
with('/select', {:rows=>10, :start=>20, :q=>"*:*"}).
and_return({'response'=>{'docs' => []}, 'responseHeader' => {}})
response = c.find :page=>3, :per_page=>10, :q=>'*:*'#, :page=>1, :per_page=>10
response.should be_a(Mash)
end

it 'the #find method with a custom request handler' do
response = connection.find '/select', :q=>'*:*'
c = connection
expected_response = {'response'=>{'docs' => []}, 'responseHeader' => {}}
# ok this is hacky... the raw method needs to go into a mixin dude
def expected_response.raw
{:path => '/select'}
end
c.should_receive(:request).
with('/select', {:q=>'*:*'}).
and_return(expected_response)
response = c.find '/select', :q=>'*:*'
response.raw[:path].should match(/\/select/)
end

it 'the response' do
response = connection.find :q=>'*:*'
c = connection
c.should_receive(:request).
with('/select', :q=>'*:*').
and_return({'response'=>{'docs' => []}, 'responseHeader' => {'status'=>0}})
response = c.find :q=>'*:*'
response.should respond_to(:ok?)
response.ok?.should == true
end

it 'the #luke method' do
info = connection.luke
c = connection
c.should_receive(:request).
with('/admin/luke', {"numTerms"=>0}).
and_return({"fields"=>nil, "index"=>nil, "info" => nil})
info = c.luke
info.should be_a(Mash)
info.should have_key('fields')
info.should have_key('index')
Expand Down

0 comments on commit 8c5b6fc

Please sign in to comment.