autodoc 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/lib/autodoc.rb +3 -1
- data/lib/autodoc/collector.rb +2 -2
- data/lib/autodoc/document.rb +9 -18
- data/lib/autodoc/transaction.rb +45 -0
- data/lib/autodoc/version.rb +1 -1
- data/spec/autodoc/document_spec.rb +5 -1
- data/spec/dummy/app/controllers/recipes_controller.rb +1 -1
- data/spec/dummy/app/models/recipe.rb +1 -0
- data/spec/dummy/config/application.rb +0 -8
- data/spec/dummy/config/environments/development.rb +0 -16
- data/spec/dummy/config/environments/production.rb +4 -0
- data/spec/dummy/config/environments/test.rb +2 -11
- data/spec/dummy/config/initializers/secret_token.rb +1 -0
- data/spec/dummy/doc/recipes.md +35 -4
- data/spec/requests/recipes_spec.rb +12 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4091505d95ad9fee545f12914131cc4ffb5d0bb8
|
4
|
+
data.tar.gz: 4d2ee5af70e47de188b1f1cda129a729124b7f87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14b86765ab33b40aabcc5b0626d6cdd3bf787d09ef867aecbca2ca992a8a4daa350d59442cbf0af3e75303e215d794a28441aee077278c177740d698c7eb19e9
|
7
|
+
data.tar.gz: ad652164ef57957aeff23ac715879d688a7cf3c73a11c891ee93bf8a265764a7019221e9ca921a323fab2b5d04332bc2ec2476b320972abb3ba876868bb7097d
|
data/Gemfile
CHANGED
data/lib/autodoc.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "autodoc/collector"
|
2
2
|
require "autodoc/configuration"
|
3
3
|
require "autodoc/document"
|
4
|
+
require "autodoc/transaction"
|
4
5
|
require "autodoc/version"
|
5
6
|
|
6
7
|
module Autodoc
|
@@ -19,7 +20,8 @@ if ENV["AUTODOC"] && defined?(RSpec)
|
|
19
20
|
RSpec.configure do |config|
|
20
21
|
config.after(:each, type: :request) do
|
21
22
|
if example.metadata[:autodoc]
|
22
|
-
Autodoc.
|
23
|
+
txn = Autodoc::Transaction.build(self)
|
24
|
+
Autodoc.collector.collect(example, txn)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
data/lib/autodoc/collector.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Autodoc
|
2
2
|
class Collector
|
3
|
-
def collect(example,
|
4
|
-
documents[example.file_path] << Autodoc::Document.render(example,
|
3
|
+
def collect(example, txn)
|
4
|
+
documents[example.file_path] << Autodoc::Document.render(example, txn)
|
5
5
|
end
|
6
6
|
|
7
7
|
def documents
|
data/lib/autodoc/document.rb
CHANGED
@@ -7,10 +7,13 @@ module Autodoc
|
|
7
7
|
new(*args).render
|
8
8
|
end
|
9
9
|
|
10
|
-
attr_reader :example, :
|
10
|
+
attr_reader :example, :transaction
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
delegate :method, :request_body, :response_status, :response_header, :response_body_raw, :controller, :action,
|
13
|
+
to: :transaction
|
14
|
+
|
15
|
+
def initialize(example, txn)
|
16
|
+
@example, @transaction = example, txn
|
14
17
|
end
|
15
18
|
|
16
19
|
def render
|
@@ -23,16 +26,12 @@ module Autodoc
|
|
23
26
|
"#{example.description.capitalize}."
|
24
27
|
end
|
25
28
|
|
26
|
-
def method
|
27
|
-
request.method
|
28
|
-
end
|
29
|
-
|
30
29
|
def path
|
31
30
|
example.full_description[%r<(GET|POST|PUT|DELETE) ([^ ]+)>, 2]
|
32
31
|
end
|
33
32
|
|
34
33
|
def response_body
|
35
|
-
"\n" + JSON.pretty_generate(JSON.parse(
|
34
|
+
"\n" + JSON.pretty_generate(JSON.parse(response_body_raw))
|
36
35
|
rescue JSON::ParserError
|
37
36
|
end
|
38
37
|
|
@@ -48,18 +47,10 @@ module Autodoc
|
|
48
47
|
end
|
49
48
|
end
|
50
49
|
|
51
|
-
def response_status
|
52
|
-
response.status
|
53
|
-
end
|
54
|
-
|
55
50
|
def parameters
|
56
51
|
validators.map {|validator| Parameter.new(validator) }.join("\n")
|
57
52
|
end
|
58
53
|
|
59
|
-
def request_body
|
60
|
-
request.body.string
|
61
|
-
end
|
62
|
-
|
63
54
|
def has_request_body?
|
64
55
|
request_body.present?
|
65
56
|
end
|
@@ -69,12 +60,12 @@ module Autodoc
|
|
69
60
|
end
|
70
61
|
|
71
62
|
def validators
|
72
|
-
WeakParameters.stats[
|
63
|
+
WeakParameters.stats[controller][action].try(:validators)
|
73
64
|
end
|
74
65
|
|
75
66
|
def response_headers
|
76
67
|
Autodoc.configuration.headers.map do |header|
|
77
|
-
"\n#{header}: #{
|
68
|
+
"\n#{header}: #{response_header(header)}" if response_header(header)
|
78
69
|
end.compact.join
|
79
70
|
end
|
80
71
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Autodoc
|
2
|
+
class Transaction
|
3
|
+
def self.build(context)
|
4
|
+
if defined?(Rack::Test::Methods) && context.class.ancestors.include?(Rack::Test::Methods)
|
5
|
+
self.new(ActionDispatch::Request.new(context.last_request.env), context.last_response)
|
6
|
+
else
|
7
|
+
self.new(context.request, context.response)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :request, :response
|
12
|
+
|
13
|
+
def initialize(*args)
|
14
|
+
@request, @response = *args
|
15
|
+
end
|
16
|
+
|
17
|
+
def method
|
18
|
+
request.method
|
19
|
+
end
|
20
|
+
|
21
|
+
def request_body
|
22
|
+
request.body.string
|
23
|
+
end
|
24
|
+
|
25
|
+
def response_status
|
26
|
+
response.status
|
27
|
+
end
|
28
|
+
|
29
|
+
def response_header(header)
|
30
|
+
response.headers[header]
|
31
|
+
end
|
32
|
+
|
33
|
+
def response_body_raw
|
34
|
+
response.body
|
35
|
+
end
|
36
|
+
|
37
|
+
def controller
|
38
|
+
request.params[:controller]
|
39
|
+
end
|
40
|
+
|
41
|
+
def action
|
42
|
+
request.params[:action]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/autodoc/version.rb
CHANGED
@@ -3,7 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Autodoc::Document do
|
4
4
|
describe ".render" do
|
5
5
|
subject do
|
6
|
-
described_class.render(example,
|
6
|
+
described_class.render(example, transaction)
|
7
7
|
end
|
8
8
|
|
9
9
|
let(:example) do
|
@@ -34,6 +34,10 @@ describe Autodoc::Document do
|
|
34
34
|
)
|
35
35
|
end
|
36
36
|
|
37
|
+
let(:transaction) do
|
38
|
+
Autodoc::Transaction.new(request, response)
|
39
|
+
end
|
40
|
+
|
37
41
|
let(:method) do
|
38
42
|
"GET"
|
39
43
|
end
|
@@ -1,12 +1,7 @@
|
|
1
1
|
require File.expand_path('../boot', __FILE__)
|
2
2
|
|
3
|
-
# Pick the frameworks you want:
|
4
3
|
require "active_record/railtie"
|
5
4
|
require "action_controller/railtie"
|
6
|
-
require "action_mailer/railtie"
|
7
|
-
require "active_resource/railtie"
|
8
|
-
require "sprockets/railtie"
|
9
|
-
# require "rails/test_unit/railtie"
|
10
5
|
|
11
6
|
Bundler.require(*Rails.groups)
|
12
7
|
require "autodoc"
|
@@ -55,9 +50,6 @@ module Dummy
|
|
55
50
|
# parameters by using an attr_accessible or attr_protected declaration.
|
56
51
|
config.active_record.whitelist_attributes = true
|
57
52
|
|
58
|
-
# Enable the asset pipeline
|
59
|
-
config.assets.enabled = true
|
60
|
-
|
61
53
|
# Version of your assets, change this if you want to expire all your assets
|
62
54
|
config.assets.version = '1.0'
|
63
55
|
end
|
@@ -6,9 +6,6 @@ Dummy::Application.configure do
|
|
6
6
|
# since you don't have to restart the web server when you make code changes.
|
7
7
|
config.cache_classes = false
|
8
8
|
|
9
|
-
# Log error messages when you accidentally call methods on nil.
|
10
|
-
config.whiny_nils = true
|
11
|
-
|
12
9
|
# Show full error reports and disable caching
|
13
10
|
config.consider_all_requests_local = true
|
14
11
|
config.action_controller.perform_caching = false
|
@@ -19,19 +16,6 @@ Dummy::Application.configure do
|
|
19
16
|
# Print deprecation notices to the Rails logger
|
20
17
|
config.active_support.deprecation = :log
|
21
18
|
|
22
|
-
# Only use best-standards-support built into browsers
|
23
|
-
config.action_dispatch.best_standards_support = :builtin
|
24
|
-
|
25
|
-
# Raise exception on mass assignment protection for Active Record models
|
26
|
-
config.active_record.mass_assignment_sanitizer = :strict
|
27
|
-
|
28
|
-
# Log the query plan for queries taking more than this (works
|
29
|
-
# with SQLite, MySQL, and PostgreSQL)
|
30
|
-
config.active_record.auto_explain_threshold_in_seconds = 0.5
|
31
|
-
|
32
|
-
# Do not compress assets
|
33
|
-
config.assets.compress = false
|
34
|
-
|
35
19
|
# Expands the lines which load the assets
|
36
20
|
config.assets.debug = true
|
37
21
|
end
|
@@ -64,4 +64,8 @@ Dummy::Application.configure do
|
|
64
64
|
# Log the query plan for queries taking more than this (works
|
65
65
|
# with SQLite, MySQL, and PostgreSQL)
|
66
66
|
# config.active_record.auto_explain_threshold_in_seconds = 0.5
|
67
|
+
|
68
|
+
config.eager_load = true
|
69
|
+
|
70
|
+
config.assets.js_compressor = :uglifier
|
67
71
|
end
|
@@ -11,9 +11,6 @@ Dummy::Application.configure do
|
|
11
11
|
config.serve_static_assets = true
|
12
12
|
config.static_cache_control = "public, max-age=3600"
|
13
13
|
|
14
|
-
# Log error messages when you accidentally call methods on nil
|
15
|
-
config.whiny_nils = true
|
16
|
-
|
17
14
|
# Show full error reports and disable caching
|
18
15
|
config.consider_all_requests_local = true
|
19
16
|
config.action_controller.perform_caching = false
|
@@ -24,14 +21,8 @@ Dummy::Application.configure do
|
|
24
21
|
# Disable request forgery protection in test environment
|
25
22
|
config.action_controller.allow_forgery_protection = false
|
26
23
|
|
27
|
-
# Tell Action Mailer not to deliver emails to the real world.
|
28
|
-
# The :test delivery method accumulates sent emails in the
|
29
|
-
# ActionMailer::Base.deliveries array.
|
30
|
-
config.action_mailer.delivery_method = :test
|
31
|
-
|
32
|
-
# Raise exception on mass assignment protection for Active Record models
|
33
|
-
config.active_record.mass_assignment_sanitizer = :strict
|
34
|
-
|
35
24
|
# Print deprecation notices to the stderr
|
36
25
|
config.active_support.deprecation = :stderr
|
26
|
+
|
27
|
+
config.eager_load = false
|
37
28
|
end
|
@@ -5,3 +5,4 @@
|
|
5
5
|
# Make sure the secret is at least 30 characters and all random,
|
6
6
|
# no regular words or you'll be exposed to dictionary attacks.
|
7
7
|
Dummy::Application.config.secret_token = '2da8e59639e7c92b0da46798ed97a45be5834c72cdd9a4ad141dadc5b1175f991b05ef02dde00f9c27cadb3790311e642010b89ed1dad598539980a1ae88be61'
|
8
|
+
Dummy::Application.config.secret_key_base = '7bea42a7812ad8da2fa753be701ed39a8b35f014c0cfcc876ad08180f2b25504e67ed24fc4470c51b229bbbc4731454c912e4609902e1c0bba65fb86037f7f1a'
|
data/spec/dummy/doc/recipes.md
CHANGED
@@ -3,7 +3,7 @@ Creates a new recipe.
|
|
3
3
|
|
4
4
|
### parameters
|
5
5
|
* `name` string (required, except: `["alice", "bob"]`)
|
6
|
-
* `type` integer (only: `
|
6
|
+
* `type` integer (only: `1..3`)
|
7
7
|
|
8
8
|
### request
|
9
9
|
```
|
@@ -17,12 +17,43 @@ name=name&type=1
|
|
17
17
|
### response
|
18
18
|
```ruby
|
19
19
|
Status: 201
|
20
|
-
location: http://www.example.com/recipes/1
|
21
20
|
response:
|
22
21
|
{
|
23
|
-
"created_at": "2013-10-08T07:24:05Z",
|
24
22
|
"id": 1,
|
25
23
|
"name": "name",
|
26
|
-
"
|
24
|
+
"type": 1,
|
25
|
+
"created_at": "2013-10-22T22:41:07.886Z",
|
26
|
+
"updated_at": "2013-10-22T22:41:07.886Z"
|
27
|
+
}
|
28
|
+
```
|
29
|
+
|
30
|
+
|
31
|
+
## POST /recipes
|
32
|
+
Creates a new recipe.
|
33
|
+
|
34
|
+
### parameters
|
35
|
+
* `name` string (required, except: `["alice", "bob"]`)
|
36
|
+
* `type` integer (only: `1..3`)
|
37
|
+
|
38
|
+
### request
|
39
|
+
```
|
40
|
+
POST /recipes
|
41
|
+
```
|
42
|
+
|
43
|
+
```
|
44
|
+
name=name&type=1
|
45
|
+
```
|
46
|
+
|
47
|
+
### response
|
48
|
+
```ruby
|
49
|
+
Status: 201
|
50
|
+
location: http://example.org/recipes/1
|
51
|
+
response:
|
52
|
+
{
|
53
|
+
"id": 1,
|
54
|
+
"name": "name",
|
55
|
+
"type": 1,
|
56
|
+
"created_at": "2013-10-22T22:41:07.900Z",
|
57
|
+
"updated_at": "2013-10-22T22:41:07.900Z"
|
27
58
|
}
|
28
59
|
```
|
@@ -52,5 +52,17 @@ describe "Recipes" do
|
|
52
52
|
response.status.should == 201
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
context "with valid condition (client using Rack::Test)", :autodoc do
|
57
|
+
include Rack::Test::Methods
|
58
|
+
before do
|
59
|
+
header 'Accept', 'application/json'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "creates a new recipe" do
|
63
|
+
post "/recipes", params
|
64
|
+
last_response.status.should == 201
|
65
|
+
end
|
66
|
+
end
|
55
67
|
end
|
56
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autodoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/autodoc/collector.rb
|
112
112
|
- lib/autodoc/configuration.rb
|
113
113
|
- lib/autodoc/document.rb
|
114
|
+
- lib/autodoc/transaction.rb
|
114
115
|
- lib/autodoc/version.rb
|
115
116
|
- spec/autodoc/document_spec.rb
|
116
117
|
- spec/dummy/Rakefile
|