patron 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -230,6 +230,8 @@ static void set_options_from_request(VALUE self, VALUE request) {
230
230
 
231
231
  state->upload_file = open_file(filename, "r");
232
232
  curl_easy_setopt(curl, CURLOPT_READDATA, state->upload_file);
233
+ } else {
234
+ rb_raise(rb_eArgError, "Must provide either data or a filename when doing a PUT or POST");
233
235
  }
234
236
  } else if (action == rb_intern("head")) {
235
237
  curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
@@ -391,14 +393,15 @@ VALUE session_handle_request(VALUE self, VALUE request) {
391
393
  }
392
394
 
393
395
  VALUE enable_cookie_session(VALUE self, VALUE file) {
394
- struct curl_state *state;
395
- Data_Get_Struct(self, struct curl_state, state);
396
- CURL* curl = state->handle;
397
- char *file_path = RSTRING_PTR(file);
398
- if (file_path != "")
399
- curl_easy_setopt(curl, CURLOPT_COOKIEJAR, file_path);
400
- curl_easy_setopt(curl, CURLOPT_COOKIEFILE, file_path);
401
- return Qnil;
396
+ struct curl_state *state;
397
+ Data_Get_Struct(self, struct curl_state, state);
398
+ CURL* curl = state->handle;
399
+ char* file_path = RSTRING_PTR(file);
400
+ if (file_path != NULL && strlen(file_path) != 0) {
401
+ curl_easy_setopt(curl, CURLOPT_COOKIEJAR, file_path);
402
+ }
403
+ curl_easy_setopt(curl, CURLOPT_COOKIEFILE, file_path);
404
+ return Qnil;
402
405
  }
403
406
 
404
407
  //------------------------------------------------------------------------------
@@ -26,15 +26,15 @@ require 'yaml'
26
26
  require 'pathname'
27
27
 
28
28
  cwd = Pathname(__FILE__).dirname
29
- $:.unshift(cwd) unless $:.include?(cwd) || $:.include?(cwd.expand_path)
29
+ $:.unshift(cwd.to_s) unless $:.include?(cwd.to_s) || $:.include?(cwd.expand_path.to_s)
30
30
 
31
31
  require 'patron/session'
32
32
 
33
33
  module Patron #:nodoc:
34
34
  # Returns the version number of the Patron library as a string
35
35
  def self.version
36
- cwd = Pathname(__FILE__).dirname
37
- yaml = YAML.load_file(cwd.expand_path + '../VERSION.yml')
36
+ cwd = Pathname(__FILE__).dirname.expand_path.to_s
37
+ yaml = YAML.load_file(cwd + '/../VERSION.yml')
38
38
  major = (yaml['major'] || yaml[:major]).to_i
39
39
  minor = (yaml['minor'] || yaml[:minor]).to_i
40
40
  patch = (yaml['patch'] || yaml[:patch]).to_i
@@ -137,12 +137,20 @@ describe Patron::Session do
137
137
  body.header['content-length'].should == [data.size.to_s]
138
138
  end
139
139
 
140
+ it "should raise when no data is provided to :put" do
141
+ lambda { @session.put("/test", nil) }.should raise_error(ArgumentError)
142
+ end
143
+
140
144
  it "should upload a file with :put" do
141
145
  response = @session.put_file("/test", "VERSION.yml")
142
146
  body = YAML::load(response.body)
143
147
  body.request_method.should == "PUT"
144
148
  end
145
149
 
150
+ it "should raise when no file is provided to :put" do
151
+ lambda { @session.put_file("/test", nil) }.should raise_error(ArgumentError)
152
+ end
153
+
146
154
  it "should use chunked encoding when uploading a file with :put" do
147
155
  response = @session.put_file("/test", "VERSION.yml")
148
156
  body = YAML::load(response.body)
@@ -157,12 +165,20 @@ describe Patron::Session do
157
165
  body.header['content-length'].should == [data.size.to_s]
158
166
  end
159
167
 
168
+ it "should raise when no data is provided to :post" do
169
+ lambda { @session.post("/test", nil) }.should raise_error(ArgumentError)
170
+ end
171
+
160
172
  it "should upload a file with :post" do
161
173
  response = @session.post_file("/test", "VERSION.yml")
162
174
  body = YAML::load(response.body)
163
175
  body.request_method.should == "POST"
164
176
  end
165
177
 
178
+ it "should raise when no file is provided to :post" do
179
+ lambda { @session.post_file("/test", nil) }.should raise_error(ArgumentError)
180
+ end
181
+
166
182
  it "should use chunked encoding when uploading a file with :post" do
167
183
  response = @session.post_file("/test", "VERSION.yml")
168
184
  body = YAML::load(response.body)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patron
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phillip Toland
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-30 00:00:00 -05:00
12
+ date: 2009-10-04 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15