rspec_api_documentation 0.8.0 → 0.9.0

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.
@@ -21,6 +21,14 @@ module RspecApiDocumentation
21
21
  process :delete, *args
22
22
  end
23
23
 
24
+ def head(*args)
25
+ process :head, *args
26
+ end
27
+
28
+ def patch(*args)
29
+ process :patch, *args
30
+ end
31
+
24
32
  def response_status
25
33
  status
26
34
  end
@@ -62,7 +70,7 @@ module RspecApiDocumentation
62
70
  strings = query_string.split("&")
63
71
  arrays = strings.map do |segment|
64
72
  k,v = segment.split("=")
65
- [k, CGI.unescape(v)]
73
+ [k, v && CGI.unescape(v)]
66
74
  end
67
75
  Hash[arrays]
68
76
  end
@@ -40,7 +40,8 @@ module RspecApiDocumentation
40
40
  end
41
41
 
42
42
  def post_data
43
- "-d \"#{data}\""
43
+ escaped_data = data.to_s.gsub("'", "\\u0027")
44
+ "-d '#{escaped_data}'"
44
45
  end
45
46
 
46
47
  private
@@ -1,8 +1,11 @@
1
1
  require 'rspec/core/formatters/base_formatter'
2
+ require 'rack/utils'
3
+ require 'rack/test/utils'
2
4
 
3
5
  module RspecApiDocumentation::DSL
4
6
  module Endpoint
5
7
  extend ActiveSupport::Concern
8
+ include Rack::Test::Utils
6
9
 
7
10
  delegate :response_headers, :status, :response_status, :response_body, :to => :client
8
11
 
@@ -36,7 +39,7 @@ module RspecApiDocumentation::DSL
36
39
  path_or_query = path
37
40
 
38
41
  if method == :get && !query_string.blank?
39
- path_or_query = path + "?#{query_string}"
42
+ path_or_query += "?#{query_string}"
40
43
  else
41
44
  params_or_body = respond_to?(:raw_post) ? raw_post : params
42
45
  end
@@ -45,11 +48,7 @@ module RspecApiDocumentation::DSL
45
48
  end
46
49
 
47
50
  def query_string
48
- query = params.to_a.map do |param|
49
- param.map! { |a| CGI.escape(a.to_s) }
50
- param.join("=")
51
- end
52
- query.join("&")
51
+ build_nested_query(params || {})
53
52
  end
54
53
 
55
54
  def params
@@ -62,7 +61,15 @@ module RspecApiDocumentation::DSL
62
61
  end
63
62
 
64
63
  def headers
65
- example.metadata[:headers]
64
+ return unless example.metadata[:headers]
65
+ example.metadata[:headers].inject({}) do |hash, (header, value)|
66
+ if value.is_a?(Symbol)
67
+ hash[header] = send(value) if respond_to?(value)
68
+ else
69
+ hash[header] = value
70
+ end
71
+ hash
72
+ end
66
73
  end
67
74
 
68
75
  def method
@@ -19,6 +19,8 @@ module RspecApiDocumentation::DSL
19
19
  define_action :post
20
20
  define_action :put
21
21
  define_action :delete
22
+ define_action :head
23
+ define_action :patch
22
24
 
23
25
  def callback(*args, &block)
24
26
  require 'webmock'
@@ -81,14 +81,20 @@ module RspecApiDocumentation
81
81
  "#{basename}.json"
82
82
  end
83
83
 
84
- def to_json
84
+ def as_json
85
85
  {
86
86
  :resource => resource_name,
87
+ :http_method => http_method,
88
+ :route => route,
87
89
  :description => description,
88
90
  :explanation => explanation,
89
91
  :parameters => respond_to?(:parameters) ? parameters : [],
90
92
  :requests => requests
91
- }.to_json
93
+ }
94
+ end
95
+
96
+ def to_json
97
+ as_json.to_json
92
98
  end
93
99
 
94
100
  def requests
@@ -48,9 +48,15 @@ module RspecApiDocumentation
48
48
 
49
49
  class ProxyApp < Struct.new(:client, :app)
50
50
  def call(env)
51
+ env["QUERY_STRING"] = query_string_hack(env)
51
52
  client.last_request = Struct.new(:env, :content_type).new(env, env["CONTENT_TYPE"])
52
53
  app.call(env.merge("SCRIPT_NAME" => ""))
53
54
  end
55
+
56
+ private
57
+ def query_string_hack(env)
58
+ env["QUERY_STRING"].gsub('%5B', '[').gsub('%5D', ']').gsub(/\[\d+/) { |s| "#{$1}[" }
59
+ end
54
60
  end
55
61
 
56
62
  def access_token
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_api_documentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-08-10 00:00:00.000000000 Z
14
+ date: 2013-04-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
@@ -196,7 +196,7 @@ dependencies:
196
196
  requirements:
197
197
  - - ! '>='
198
198
  - !ruby/object:Gem::Version
199
- version: 0.5.5
199
+ version: 0.6.2
200
200
  type: :development
201
201
  prerelease: false
202
202
  version_requirements: !ruby/object:Gem::Requirement
@@ -204,7 +204,7 @@ dependencies:
204
204
  requirements:
205
205
  - - ! '>='
206
206
  - !ruby/object:Gem::Version
207
- version: 0.5.5
207
+ version: 0.6.2
208
208
  - !ruby/object:Gem::Dependency
209
209
  name: rack-oauth2
210
210
  requirement: !ruby/object:Gem::Requirement
@@ -230,51 +230,51 @@ executables: []
230
230
  extensions: []
231
231
  extra_rdoc_files: []
232
232
  files:
233
- - lib/rspec_api_documentation/api_documentation.rb
233
+ - lib/rspec_api_documentation.rb
234
+ - lib/tasks/docs.rake
235
+ - lib/rspec_api_documentation/rack_test_client.rb
234
236
  - lib/rspec_api_documentation/api_formatter.rb
235
- - lib/rspec_api_documentation/client_base.rb
236
- - lib/rspec_api_documentation/combined_json_writer.rb
237
- - lib/rspec_api_documentation/combined_text_writer.rb
238
- - lib/rspec_api_documentation/configuration.rb
237
+ - lib/rspec_api_documentation/html_writer.rb
239
238
  - lib/rspec_api_documentation/curl.rb
239
+ - lib/rspec_api_documentation/json_iodocs_writer.rb
240
+ - lib/rspec_api_documentation/index.rb
241
+ - lib/rspec_api_documentation/headers.rb
242
+ - lib/rspec_api_documentation/wurl_writer.rb
243
+ - lib/rspec_api_documentation/oauth2_mac_client.rb
240
244
  - lib/rspec_api_documentation/dsl/callback.rb
241
245
  - lib/rspec_api_documentation/dsl/endpoint.rb
242
246
  - lib/rspec_api_documentation/dsl/resource.rb
247
+ - lib/rspec_api_documentation/json_writer.rb
243
248
  - lib/rspec_api_documentation/dsl.rb
249
+ - lib/rspec_api_documentation/configuration.rb
250
+ - lib/rspec_api_documentation/combined_json_writer.rb
244
251
  - lib/rspec_api_documentation/example.rb
245
- - lib/rspec_api_documentation/headers.rb
246
- - lib/rspec_api_documentation/html_writer.rb
247
- - lib/rspec_api_documentation/index.rb
248
- - lib/rspec_api_documentation/index_writer.rb
249
- - lib/rspec_api_documentation/json_iodocs_writer.rb
250
- - lib/rspec_api_documentation/json_writer.rb
251
- - lib/rspec_api_documentation/oauth2_mac_client.rb
252
- - lib/rspec_api_documentation/rack_test_client.rb
253
- - lib/rspec_api_documentation/railtie.rb
252
+ - lib/rspec_api_documentation/api_documentation.rb
254
253
  - lib/rspec_api_documentation/test_server.rb
255
- - lib/rspec_api_documentation/wurl_writer.rb
256
- - lib/rspec_api_documentation.rb
257
- - lib/tasks/docs.rake
258
- - templates/assets/img/glyphicons-halflings-white.png
259
- - templates/assets/img/glyphicons-halflings.png
260
- - templates/assets/javascripts/application.js
261
- - templates/assets/javascripts/codemirror.js
254
+ - lib/rspec_api_documentation/railtie.rb
255
+ - lib/rspec_api_documentation/index_writer.rb
256
+ - lib/rspec_api_documentation/combined_text_writer.rb
257
+ - lib/rspec_api_documentation/client_base.rb
262
258
  - templates/assets/javascripts/jquery-1-7-2.js
259
+ - templates/assets/javascripts/codemirror.js
263
260
  - templates/assets/javascripts/jquery-base64.js
264
- - templates/assets/javascripts/jquery-livequery.js
265
261
  - templates/assets/javascripts/jquery-ui-1-8-16-min.js
266
- - templates/assets/javascripts/mode/css/css.js
267
- - templates/assets/javascripts/mode/htmlmixed/htmlmixed.js
268
262
  - templates/assets/javascripts/mode/javascript/javascript.js
263
+ - templates/assets/javascripts/mode/css/css.js
269
264
  - templates/assets/javascripts/mode/xml/xml.js
265
+ - templates/assets/javascripts/mode/htmlmixed/htmlmixed.js
266
+ - templates/assets/javascripts/jquery-livequery.js
267
+ - templates/assets/javascripts/application.js
268
+ - templates/assets/img/glyphicons-halflings-white.png
269
+ - templates/assets/img/glyphicons-halflings.png
270
270
  - templates/assets/stylesheets/application.css
271
- - templates/assets/stylesheets/bootstrap.css
272
271
  - templates/assets/stylesheets/codemirror.css
273
- - templates/rspec_api_documentation/example.json
274
- - templates/rspec_api_documentation/html_example.mustache
272
+ - templates/assets/stylesheets/bootstrap.css
275
273
  - templates/rspec_api_documentation/html_index.mustache
276
274
  - templates/rspec_api_documentation/index.json
277
275
  - templates/rspec_api_documentation/wurl_example.mustache
276
+ - templates/rspec_api_documentation/html_example.mustache
277
+ - templates/rspec_api_documentation/example.json
278
278
  - templates/rspec_api_documentation/wurl_index.mustache
279
279
  homepage: http://smartlogicsolutions.com
280
280
  licenses: []
@@ -296,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
296
296
  version: 1.3.6
297
297
  requirements: []
298
298
  rubyforge_project:
299
- rubygems_version: 1.8.24
299
+ rubygems_version: 1.8.23
300
300
  signing_key:
301
301
  specification_version: 3
302
302
  summary: A double black belt for your docs