spec/session_spec.rb in patron-0.4.18 vs spec/session_spec.rb in patron-0.4.20

- old
+ new

@@ -54,25 +54,45 @@ response = @session.get("/test") body = YAML::load(response.body) body.request_method.should == "GET" end + it 'should ignore #base_url when a full URL is provided' do + @session.base_url = "http://example.com:123" + lambda { @session.get("http://localhost:9001/test") }.should_not raise_error(URI::InvalidURIError) + end + it "should download content with :get and a file path" do tmpfile = "/tmp/patron_test.yaml" response = @session.get_file "/test", tmpfile response.body.should be_nil body = YAML::load_file(tmpfile) body.request_method.should == "GET" FileUtils.rm tmpfile end + it "should download correctly(md5 ok) with get_file" do + tmpfile = "/tmp/picture" + response = @session.get_file "/picture", tmpfile + response.body.should be_nil + File.size(File.join(File.dirname(__FILE__),"../pic.png")).should == File.size(tmpfile) + FileUtils.rm tmpfile + end + it "should include custom headers in a request" do response = @session.get("/test", {"User-Agent" => "PatronTest"}) body = YAML::load(response.body) body.header["user-agent"].should == ["PatronTest"] end + it "should include default headers in a request, if they were defined" do + @session.headers = {"User-Agent" => "PatronTest"} + response = @session.get("/test") + body = YAML::load(response.body) + body.header["user-agent"].should == ["PatronTest"] + end + it "should merge custom headers with session headers" do @session.headers["X-Test"] = "Testing" response = @session.get("/test", {"User-Agent" => "PatronTest"}) body = YAML::load(response.body) body.header["user-agent"].should == ["PatronTest"] @@ -141,9 +161,17 @@ it "should upload data with :put" do data = "upload data" response = @session.put("/test", data) body = YAML::load(response.body) body.request_method.should == "PUT" + body.header['content-length'].should == [data.size.to_s] + end + + it "should upload data with :delete" do + data = "upload data" + response = @session.request(:delete, "/test", {}, :data => data) + body = YAML::load(response.body) + body.request_method.should == "DELETE" body.header['content-length'].should == [data.size.to_s] end it "should raise when no data is provided to :put" do lambda { @session.put("/test", nil) }.should raise_error(ArgumentError)