the86-client 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,7 +32,10 @@ module The86
32
32
  end
33
33
 
34
34
  def patch(options)
35
- dispatch(:patch, options)
35
+ # TODO: extract HTTP method override into Faraday middleware.
36
+ options[:headers] ||= {}
37
+ options[:headers]["X-Http-Method-Override"] = "patch"
38
+ dispatch(:post, options)
36
39
  end
37
40
 
38
41
  def post(options)
@@ -42,7 +45,8 @@ module The86
42
45
  def dispatch(method, options)
43
46
  path = options.fetch(:path)
44
47
  data = options[:data]
45
- response = @faraday.run_request(method, path, data, @faraday.headers)
48
+ headers = @faraday.headers.merge(options[:headers] || {})
49
+ response = @faraday.run_request(method, path, data, headers)
46
50
  assert_http_status(response, options[:status])
47
51
  response.body
48
52
  end
@@ -1,5 +1,5 @@
1
1
  module The86
2
2
  module Client
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -19,6 +19,8 @@ module RequestExpectations
19
19
  end
20
20
 
21
21
  def expect_request(options)
22
+ rack_method_override!(options, :patch)
23
+
22
24
  url = options.fetch(:url)
23
25
  method = options.fetch(:method)
24
26
  request_body = options[:request_body]
@@ -36,6 +38,21 @@ module RequestExpectations
36
38
  with(request).
37
39
  to_return(response)
38
40
  end
41
+
42
+ private
43
+
44
+ # Rewrite the expectations for Rack::MethodOverride.
45
+ # See: https://github.com/rack/rack/blob/master/lib/rack/methodoverride.rb
46
+ # For example an expectation of a PATCH request maps to an actual
47
+ # expectation of a POST request with PATCH in an override header.
48
+ def rack_method_override!(options, *methods)
49
+ if methods.include?(options[:method])
50
+ options[:request_headers] ||= {}
51
+ options[:request_headers]["X-Http-Method-Override"] = options[:method]
52
+ options[:method] = :post
53
+ end
54
+ end
55
+
39
56
  end
40
57
 
41
58
  MiniTest::Spec.send(:include, RequestExpectations)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the86-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-01 00:00:00.000000000 Z
12
+ date: 2012-08-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday