Permalink
Browse files

Fixed RSolr::Connection::Httpable bug -> http://github.com/mwmitchell…

…/rsolr/issues#issue/6

updated specs to correctly check :path param in solr req/res context
  • Loading branch information...
1 parent cb988ac commit 560f9dfd2ab343669330e622cac5922b26e86882 @mwmitchell mwmitchell committed Apr 19, 2010
Showing with 8 additions and 10 deletions.
  1. +4 −6 lib/rsolr/connection/httpable.rb
  2. +4 −4 spec/api/connection/httpable_spec.rb
@@ -45,22 +45,20 @@ def request path, params={}, *extra
end
# -> should this stuff be in a "ReqResContext" class? ->
-
+
# creates a Hash based "context"
# that contains all of the information sent to Solr
# The keys are:
# :host, :path, :params, :query, :data, :headers
def create_http_context path, params, data=nil, opts={}
- context = {:host => base_url, :path => build_url(path), :params => params, :query => hash_to_query(params), :data => data}
+ context = {:host => base_url, :params => params, :query => hash_to_query(params), :data => data}
if opts[:method] == :post
raise "Don't send POST data when using :method => :post" unless data.to_s.empty?
# force a POST, use the query string as the POST body
- context.merge! :data => context[:query], :headers => {'Content-Type' => 'application/x-www-form-urlencoded'}
- elsif data
- # standard POST, using "data" as the POST body
- context.merge! :headers => {'Content-Type' => 'text/xml; charset=utf-8'}
+ context.merge! :path => build_url(path), :data => context[:query], :headers => {'Content-Type' => 'application/x-www-form-urlencoded'}
else
context.merge! :path => build_url(path, params)
+ context.merge!(:headers => {'Content-Type' => 'text/xml; charset=utf-8'}) if data
end
context
end
@@ -77,15 +77,15 @@ def self.included base
it "should build a POST context" do
r = httpable
- result = r.create_http_context('/select', {:wt => :xml}, '<commit/>')
- expected = {:path=>"/solr/select", :params=>{:wt=>:xml}, :headers=>{"Content-Type"=>"text/xml; charset=utf-8"}, :data=>"<commit/>", :query=>"wt=xml", :host=>"http://127.0.0.1:8983"}
+ result = r.create_http_context('/update', {:wt => :xml}, '<commit/>')
+ expected = {:path=>"/solr/update?wt=xml", :params=>{:wt=>:xml}, :headers=>{"Content-Type"=>"text/xml; charset=utf-8"}, :data=>"<commit/>", :query=>"wt=xml", :host=>"http://127.0.0.1:8983"}
result.should == expected
end
it "should raise an exception when trying to use POST data AND :method => :post" do
r = httpable
lambda{
- r.create_http_context('/select', {:wt => :xml}, '<commit/>', :method => :post)
+ r.create_http_context('/update', {:wt => :xml}, '<commit/>', :method => :post)
}.should raise_error("Don't send POST data when using :method => :post")
end
@@ -131,7 +131,7 @@ def self.included base
it 'should send a post to itself if data is supplied' do
httpable.should_receive(:post).
- with("/solr/blah", "<commit/>", {"Content-Type"=>"text/xml; charset=utf-8"}).
+ with("/solr/blah?id=1", "<commit/>", {"Content-Type"=>"text/xml; charset=utf-8"}).
and_return([200, "OK", ""])
httpable.request('/blah', {:id=>1}, "<commit/>")#.should == expected_response
end

0 comments on commit 560f9df

Please sign in to comment.