spec/riak/http_backend_spec.rb in riak-client-1.0.5 vs spec/riak/http_backend_spec.rb in riak-client-1.1.0

- old
+ new

@@ -181,20 +181,21 @@ before do @mr = Riak::MapReduce.new(@client).map("Riak.mapValues", :keep => true) end it "should issue POST request to the mapred endpoint" do - @backend.should_receive(:post).with(200, @backend.mapred_path, @mr.to_json, hash_including("Content-Type" => "application/json")).and_return({:headers => {'content-type' => ["application/json"]}, :body => "[]"}) + @backend.should_receive(:post).with(200, @backend.mapred_path(:chunked => true), @mr.to_json, hash_including("Content-Type" => "application/json")).and_yield(%Q|--foo\r\nContent-Type: application/json\r\n\r\n{"phase":0,"data":[]}\r\n--foo--\r\n|) @backend.mapred(@mr) end it "should vivify JSON responses" do - @backend.stub!(:post).and_return(:headers => {'content-type' => ["application/json"]}, :body => '[{"key":"value"}]') + @backend.stub!(:post).and_yield(%Q|--foo\r\nContent-Type: application/json\r\n\r\n{"phase":0,"data":[{"key":"value"}]}\r\n--foo--\r\n|) @backend.mapred(@mr).should == [{"key" => "value"}] end it "should return the full response hash for non-JSON responses" do + pending "It is not clear when Riak would ever return a non-JSON or non-multipart response for mapred." response = {:code => 200, :headers => {'content-type' => ["text/plain"]}, :body => 'This is some text.'} @backend.stub!(:post).and_return(response) @backend.mapred(@mr).should == response end @@ -270,12 +271,12 @@ with(200, @backend.solr_select_path(nil, 'foo', {'wt' => 'json'})). and_return(:code => 200, :headers => {"content-type" => ['application/json']}, :body => '{}') @backend.search(nil, 'foo') end - it "should vivify JSON responses" do - @backend.should_receive(:get).and_return({:code => 200, :headers => {"content-type"=>["application/json"]}, :body => '{"response":{"docs":["foo"]}}'}) - @backend.search(nil, "foo").should == {"response" => {"docs" => ["foo"]}} + it "should vivify and normalize JSON responses" do + @backend.should_receive(:get).and_return({:code => 200, :headers => {"content-type"=>["application/json"]}, :body => '{"response":{"docs":[{"id":"foo","fields":{},"props":{}}],"maxScore":"0.0345","numFound":1}}'}) + @backend.search(nil, "foo").should == {"docs" => [{"id" => "foo"}], "max_score" => 0.0345, "num_found" => 1} end it "should return non-JSON responses raw" do @backend.should_receive(:get).and_return({:code => 200, :headers => {"content-type"=>["text/plain"]}, :body => '{"response":{"docs":["foo"]}}'}) @backend.search(nil, "foo").should == '{"response":{"docs":["foo"]}}'