spec/session_spec.rb in patron-0.5.0 vs spec/session_spec.rb in patron-0.5.1
- old
+ new
@@ -166,11 +166,18 @@
response = @session.request(:get, "/test", {}, :data => data)
body = YAML::load(response.body)
expect(body.request_method).to be == "GET"
expect(body.header['content-length']).to be == [data.size.to_s]
end
-
+
+ it "should call to_s on the data being uploaded via GET if it is not already a String" do
+ data = 12345
+ response = @session.request(:get, "/test", {}, :data => data)
+ body = YAML::load(response.body)
+ expect(body.request_method).to be == "GET"
+ end
+
it "should upload data with :put" do
data = "upload data"
response = @session.put("/test", data)
body = YAML::load(response.body)
expect(body.request_method).to be == "PUT"
@@ -202,11 +209,18 @@
it "should use chunked encoding when uploading a file with :put" do
response = @session.put_file("/test", "LICENSE")
body = YAML::load(response.body)
expect(body.header['transfer-encoding'].first).to be == "chunked"
end
-
+
+ it "should call to_s on the data being uploaded via POST if it is not already a String" do
+ data = 12345
+ response = @session.post("/testpost", data)
+ body = YAML::load(response.body)
+ expect(body['body']).to eq("12345")
+ end
+
it "should upload data with :post" do
data = "upload data"
response = @session.post("/test", data)
body = YAML::load(response.body)
expect(body.request_method).to be == "POST"
@@ -331,9 +345,34 @@
def encode_authz(user, passwd)
"Basic " + Base64.encode64("#{user}:#{passwd}").strip
end
+ describe 'when using a subclass with a custom Response' do
+
+ class CustomResponse
+ attr_reader :constructor_args
+ def initialize(*constructor_args)
+ @constructor_args = constructor_args
+ end
+ end
+
+ class CustomizedSession < Patron::Session
+ def response_class
+ CustomResponse
+ end
+ end
+
+ it 'instantiates the customized response object' do
+ @session = CustomizedSession.new
+ @session.base_url = "http://localhost:9001"
+ response = @session.request(:get, "/test", {}, :query => {:foo => "bar"})
+
+ expect(response).to be_kind_of(CustomResponse)
+ expect(response.constructor_args.length).to eq(6)
+ end
+ end
+
describe 'when instantiating with hash arguments' do
let(:args) { {
:timeout => 10,
:base_url => 'http://localhost:9001',