describe RSolr::Client do let(:client){ RSolr::Client.new('') } context :method_missing do it 'a non-existent method should be forwarded to #method_missing and then to #request' do client.should_receive(:request). with('/music', :q=>'Coltrane') client.music :q=>'Coltrane' end end context :update do it 'should forward /update to #request("/update")' do client.should_receive(:request)#. # with('/update', {:wt=>:ruby}, "my xml message") client.update "my xml message" end it 'should forward #add calls to #update' do client.should_receive(:update) {|value,params| value.should == "1" } client.add(:id=>1) end it 'should forward #commit calls to #update' do client.should_receive(:update). with("") client.commit end it 'should forward #commit calls with options to #update' do opts = {:waitFlush => false, :waitSearcher => false, :expungeDeletes => true} # when client.commit is called, it eventually calls update client.should_receive(:update). with(opts) # client.message is calls to create the xml client.message.should_receive(:commit). and_return(opts) client.commit(opts) end it 'should forward #optimize calls to #update' do client.should_receive(:update). with("") client.optimize end it 'should forward #optimize calls with options to #update' do opts = {:maxSegments => 5, :waitFlush => false} # when client.commit is called, it eventually calls update client.should_receive(:update). with(opts) # client.message is calls to create the xml client.message.should_receive(:optimize). and_return(opts) client.optimize(opts) end it 'should forward #rollback calls to #update' do client.should_receive(:update). with("") client.rollback end it 'should forward #delete_by_id calls to #update' do client.should_receive(:update). with("1") client.delete_by_id 1 end it 'should forward #delete_by_query calls to #update' do client.should_receive(:update). with("blah") client.delete_by_query 'blah' end end context :request do it 'should forward #request calls to the connection' do client.connection.should_receive(:request). with('/music', :q=>'Coltrane', :wt=>:ruby). # empty params so that Client doesn't try to evalulate to Ruby; # -- this happens if the :wt equal :ruby and_return(:params=>{}) client.request '/music', :q=>'Coltrane' end end context :adapt_response do it 'should not try to evaluate ruby when the :qt is not :ruby' do body = '{:time=>"NOW"}' result = client.send(:adapt_response, {:body=>body, :params=>{}}) result.should be_a(String) result.should == body end it 'should evaluate ruby responses when the :wt is :ruby' do body = '{:time=>"NOW"}' result = client.send(:adapt_response, {:body=>body, :params=>{:wt=>:ruby}}) result.should be_a(Hash) result.should == {:time=>"NOW"} end end end