spec/lib/base_spec.rb in flexirest-1.5.4 vs spec/lib/base_spec.rb in flexirest-1.5.5

- old
+ new

@@ -309,9 +309,21 @@ it "should be able to directly call a URL" do expect_any_instance_of(Flexirest::Request).to receive(:do_request).with(any_args).and_return(::FaradayResponseMock.new(OpenStruct.new(status:200, response_headers:{}, body:"{\"first_name\":\"Billy\"}"))) EmptyExample._request("http://api.example.com/") end + it "allows already encoded bodies" do + Flexirest::ConnectionManager.reset! + connection = double("Connection") + allow(connection).to receive(:base_url).and_return("http://api.example.com") + expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://api.example.com/").and_return(connection) + expect(connection). + to receive(:post). + with("http://api.example.com/", "{\"test\":\"value\"}",an_instance_of(Hash)). + and_return(::FaradayResponseMock.new(OpenStruct.new(body:"{\"first_name\":\"John\", \"id\":1234}", response_headers:{}, status:200))) + EmptyExample._request("http://api.example.com/", :post, {test: "value"}.to_json, request_body_type: :json) + end + it "passes headers" do stub_request(:get, "http://api.example.com/v1"). with(headers: {'Accept'=>'application/hal+json, application/json;q=0.5', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Connection'=>'Keep-Alive', 'Content-Type'=>'application/x-www-form-urlencoded', 'X-Something'=>'foo/bar', 'User-Agent'=>/Flexirest\//}). to_return(status: 200, body: "", headers: {}) EmptyExample._request("http://api.example.com/v1", :get, {}, {headers: {"X-Something": "foo/bar"}})