spec/api/client_spec.rb in rsolr-1.0.10.pre1 vs spec/api/client_spec.rb in rsolr-1.0.10
- old
+ new
@@ -210,17 +210,54 @@
body = '{:time=>"NOW"}'
result = client.adapt_response({:params=>{:wt=>:ruby}}, {:status => 200, :body => body, :headers => {}})
result.should == {:time=>"NOW"}
end
+ it 'should evaluate json responses when the :wt is :json' do
+ body = '{"time": "NOW"}'
+ result = client.adapt_response({:params=>{:wt=>:json}}, {:status => 200, :body => body, :headers => {}})
+ if defined? JSON
+ result.should == {:time=>"NOW"}
+ else
+ # ruby 1.8 without the JSON gem
+ result.should == '{"time": "NOW"}'
+ end
+ end
+
it "ought raise a RSolr::Error::InvalidRubyResponse when the ruby is indeed frugged, or even fruggified" do
lambda {
client.adapt_response({:params=>{:wt => :ruby}}, {:status => 200, :body => "<woops/>", :headers => {}})
}.should raise_error RSolr::Error::InvalidRubyResponse
end
end
+ context "indifferent access" do
+ include ClientHelper
+ it "should raise a NoMethodError if the #with_indifferent_access extension isn't loaded" do
+ # TODO: Find a less implmentation-tied way to test this
+ Hash.any_instance.should_receive(:respond_to?).with(:with_indifferent_access).and_return(false)
+ body = "{'foo'=>'bar'}"
+ result = client.adapt_response({:params=>{:wt=>:ruby}}, {:status => 200, :body => body, :headers => {}})
+ lambda { result.with_indifferent_access }.should raise_error NoMethodError
+ end
+
+ it "should provide indifferent access" do
+ require 'active_support/core_ext/hash/indifferent_access'
+ body = "{'foo'=>'bar'}"
+ result = client.adapt_response({:params=>{:wt=>:ruby}}, {:status => 200, :body => body, :headers => {}})
+ indifferent_result = result.with_indifferent_access
+
+ result.should be_a(RSolr::Response)
+ result['foo'].should == 'bar'
+ result[:foo].should be_nil
+
+ indifferent_result.should be_a(RSolr::Response)
+ indifferent_result['foo'].should == 'bar'
+ indifferent_result[:foo].should == 'bar'
+ end
+ end
+
context "build_request" do
include ClientHelper
it 'should return a request context array' do
result = client.build_request('select',
:method => :post,