api_docs 1.0.5 → 1.0.6

This diff has not been reviewed by any users.
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ .bundle
2
+ .DS_Store
3
+ .rvmrc
4
+ .rbenv-gemsets
5
+ .rbenv-version
6
+ pkg
7
+ Gemfile.lock
8
+ /test/dummy/log/
9
+ /test/dummy/tmp/
10
+ /test/dummy/doc/
data/Gemfile CHANGED
@@ -1,8 +1,3 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'rails', '>=3.1.0'
4
- gem 'jquery-rails'
5
-
6
- group :development do
7
- gem 'jeweler'
8
- end
3
+ gemspec
data/Rakefile CHANGED
@@ -1,31 +1,10 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
1
+ require 'rubygems'
2
+ require 'rake/testtask'
6
3
 
7
- begin
8
- require 'jeweler'
9
- Jeweler::Tasks.new do |gem|
10
- gem.name = 'api_docs'
11
- gem.homepage = 'http://github.com/twg/api_docs'
12
- gem.license = 'MIT'
13
- gem.summary = 'Generate API documentation using integration tests in Ruby on Rails 3'
14
- gem.description = 'Generate API documentation using integration tests in Ruby on Rails 3'
15
- gem.email = 'jack@twg.ca'
16
- gem.authors = ['Oleg Khabarov', 'Jack Neto', 'The Working Group Inc.']
17
- end
18
- Jeweler::RubygemsDotOrgTasks.new
19
- rescue LoadError
20
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/*_test.rb'
7
+ test.verbose = true
21
8
  end
22
9
 
23
-
24
- require 'rake/testtask'
25
- Rake::TestTask.new(:test) do |t|
26
- t.libs << 'lib'
27
- t.libs << 'test'
28
- t.pattern = 'test/**/*_test.rb'
29
- t.verbose = false
30
- end
31
10
  task :default => :test
@@ -1,104 +1,20 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ # encoding: utf-8
5
2
 
6
- Gem::Specification.new do |s|
7
- s.name = "api_docs"
8
- s.version = "1.0.5"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Oleg Khabarov", "Jack Neto", "The Working Group Inc."]
12
- s.date = "2013-02-28"
13
- s.description = "Generate API documentation using integration tests in Ruby on Rails 3"
14
- s.email = "jack@twg.ca"
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.md"
18
- ]
19
- s.files = [
20
- "Gemfile",
21
- "LICENSE",
22
- "README.md",
23
- "Rakefile",
24
- "VERSION",
25
- "api_docs.gemspec",
26
- "app/assets/javascripts/api_docs.js",
27
- "app/assets/stylesheets/api_docs.css",
28
- "app/controllers/api_docs/docs_controller.rb",
29
- "app/views/api_docs/docs/_action.html.erb",
30
- "app/views/api_docs/docs/_request_params.html.erb",
31
- "app/views/api_docs/docs/index.html.erb",
32
- "config/routes.rb",
33
- "doc/screenshot.png",
34
- "lib/api_docs.rb",
35
- "lib/api_docs/configuration.rb",
36
- "lib/api_docs/engine.rb",
37
- "lib/api_docs/test_helper.rb",
38
- "lib/tasks/api_docs.rake",
39
- "script/rails",
40
- "test/api_docs_test.rb",
41
- "test/docs_controller_test.rb",
42
- "test/dummy/README.rdoc",
43
- "test/dummy/Rakefile",
44
- "test/dummy/app/assets/images/glyphicons-halflings-white.png",
45
- "test/dummy/app/assets/images/glyphicons-halflings.png",
46
- "test/dummy/app/assets/javascripts/application.js",
47
- "test/dummy/app/assets/javascripts/bootstrap.min.js",
48
- "test/dummy/app/assets/stylesheets/application.css",
49
- "test/dummy/app/assets/stylesheets/bootstrap.min.css",
50
- "test/dummy/app/controllers/application_controller.rb",
51
- "test/dummy/app/helpers/application_helper.rb",
52
- "test/dummy/app/mailers/.gitkeep",
53
- "test/dummy/app/models/.gitkeep",
54
- "test/dummy/app/views/layouts/application.html.erb",
55
- "test/dummy/config.ru",
56
- "test/dummy/config/application.rb",
57
- "test/dummy/config/boot.rb",
58
- "test/dummy/config/environment.rb",
59
- "test/dummy/config/environments/development.rb",
60
- "test/dummy/config/environments/production.rb",
61
- "test/dummy/config/environments/test.rb",
62
- "test/dummy/config/initializers/backtrace_silencers.rb",
63
- "test/dummy/config/initializers/inflections.rb",
64
- "test/dummy/config/initializers/mime_types.rb",
65
- "test/dummy/config/initializers/secret_token.rb",
66
- "test/dummy/config/initializers/session_store.rb",
67
- "test/dummy/config/initializers/wrap_parameters.rb",
68
- "test/dummy/config/locales/en.yml",
69
- "test/dummy/config/routes.rb",
70
- "test/dummy/lib/assets/.gitkeep",
71
- "test/dummy/log/.gitkeep",
72
- "test/dummy/public/404.html",
73
- "test/dummy/public/422.html",
74
- "test/dummy/public/500.html",
75
- "test/dummy/public/favicon.ico",
76
- "test/dummy/script/rails",
77
- "test/test_helper.rb",
78
- "test/test_helper_test.rb"
79
- ]
80
- s.homepage = "http://github.com/twg/api_docs"
81
- s.licenses = ["MIT"]
82
- s.require_paths = ["lib"]
83
- s.rubygems_version = "1.8.23"
84
- s.summary = "Generate API documentation using integration tests in Ruby on Rails 3"
85
-
86
- if s.respond_to? :specification_version then
87
- s.specification_version = 3
88
-
89
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
90
- s.add_runtime_dependency(%q<rails>, [">= 3.1.0"])
91
- s.add_runtime_dependency(%q<jquery-rails>, [">= 0"])
92
- s.add_development_dependency(%q<jeweler>, [">= 0"])
93
- else
94
- s.add_dependency(%q<rails>, [">= 3.1.0"])
95
- s.add_dependency(%q<jquery-rails>, [">= 0"])
96
- s.add_dependency(%q<jeweler>, [">= 0"])
97
- end
98
- else
99
- s.add_dependency(%q<rails>, [">= 3.1.0"])
100
- s.add_dependency(%q<jquery-rails>, [">= 0"])
101
- s.add_dependency(%q<jeweler>, [">= 0"])
102
- end
103
- end
3
+ $:.unshift File.expand_path('../lib', __FILE__)
4
+ require 'api_docs/version'
104
5
 
6
+ Gem::Specification.new do |s|
7
+ s.name = "api_docs"
8
+ s.version = ApiDocs::VERSION
9
+ s.authors = ["Oleg Khabarov"]
10
+ s.email = ["oleg@khabarov.ca"]
11
+ s.homepage = "http://github.com/twg/api_docs"
12
+ s.summary = "Generate API documentation using integration tests in Ruby on Rails"
13
+ s.description = "Generate API documentation using integration tests in Ruby on Rails"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.platform = Gem::Platform::RUBY
17
+ s.require_paths = ['lib']
18
+
19
+ s.add_dependency 'rails', '>=3.1.0'
20
+ end
@@ -1,3 +1,4 @@
1
+ require 'api_docs/version'
1
2
  require 'api_docs/engine'
2
3
  require 'api_docs/configuration'
3
4
  require 'api_docs/test_helper'
@@ -1,68 +1,74 @@
1
1
  module ApiDocs::TestHelper
2
2
 
3
- # Method that allows test creation and will document results in a YAML file
4
- # Example usage:
5
- # api_call(:get, '/users/:id', :id => 12345) do |doc|
6
- # doc.description = 'Something for the docs'
7
- # ... regular test code
8
- # end
9
- def api_call(method, path, params = { })
10
- parsed_params = params.dup
11
- parsed_path = path.dup
3
+ module InstanceMethods
4
+ # Method that allows test creation and will document results in a YAML file
5
+ # Example usage:
6
+ # api_call(:get, '/users/:id', :id => 12345) do |doc|
7
+ # doc.description = 'Something for the docs'
8
+ # ... regular test code
9
+ # end
10
+ def api_call(method, path, params = { })
11
+ parsed_params = params.dup
12
+ parsed_path = path.dup
12
13
 
13
- parsed_params.each do |k, v|
14
- parsed_params.delete(k) if parsed_path.gsub!(":#{k}", v.to_s)
15
- end
14
+ parsed_params.each do |k, v|
15
+ parsed_params.delete(k) if parsed_path.gsub!(":#{k}", v.to_s)
16
+ end
17
+
18
+ if credentials = parsed_params.delete('HTTP_AUTHORIZATION')
19
+ auth = {'HTTP_AUTHORIZATION' => credentials}
20
+ end
16
21
 
17
- # Making actual test request. Based on the example above:
18
- # get '/users/12345'
19
- doc = OpenStruct.new
20
- send(method, parsed_path, parsed_params)
22
+ # Making actual test request. Based on the example above:
23
+ # get '/users/12345'
24
+ doc = OpenStruct.new
25
+ send(method, parsed_path, parsed_params, auth)
21
26
 
22
- yield doc if block_given?
27
+ yield doc if block_given?
23
28
 
24
- # Assertions inside test block didn't fail. Preparing file
25
- # content to be written
26
- c = request.filtered_parameters['controller']
27
- a = request.filtered_parameters['action']
29
+ # Assertions inside test block didn't fail. Preparing file
30
+ # content to be written
31
+ c = request.filtered_parameters['controller']
32
+ a = request.filtered_parameters['action']
28
33
 
29
- file_path = File.expand_path("#{c.gsub('/', ':')}.yml", ApiDocs.config.docs_path)
30
- params = api_deep_clean_params(params)
34
+ file_path = File.expand_path("#{c.gsub('/', ':')}.yml", ApiDocs.config.docs_path)
35
+ params = ApiDocs::TestHelper.api_deep_clean_params(params)
31
36
 
32
- # Marking response as an unique
33
- key = 'ID-' + Digest::MD5.hexdigest("
34
- #{method}#{path}#{doc.description}#{params}#{response.status}}
35
- ")
37
+ # Marking response as an unique
38
+ key = 'ID-' + Digest::MD5.hexdigest("
39
+ #{method}#{path}#{doc.description}#{params}#{response.status}}
40
+ ")
36
41
 
37
- data = if File.exists?(file_path)
38
- YAML.load_file(file_path) rescue Hash.new
39
- else
40
- Hash.new
41
- end
42
+ data = if File.exists?(file_path)
43
+ YAML.load_file(file_path) rescue Hash.new
44
+ else
45
+ Hash.new
46
+ end
42
47
 
43
- data[a] ||= { }
44
- data[a][key] = {
45
- 'description' => doc.description,
46
- 'method' => request.method,
47
- 'path' => path,
48
- 'params' => api_deep_clean_params(params),
49
- 'status' => response.status,
50
- 'body' => response.body
51
- }
52
- FileUtils.mkdir_p(File.dirname(file_path))
53
- File.open(file_path, 'w'){|f| f.write(data.to_yaml)}
48
+ data[a] ||= { }
49
+ data[a][key] = {
50
+ 'description' => doc.description,
51
+ 'method' => request.method,
52
+ 'path' => path,
53
+ 'params' => ApiDocs::TestHelper.api_deep_clean_params(params),
54
+ 'status' => response.status,
55
+ 'body' => response.body
56
+ }
57
+ FileUtils.mkdir_p(File.dirname(file_path))
58
+ File.open(file_path, 'w'){|f| f.write(data.to_yaml)}
59
+ end
54
60
  end
55
61
 
56
62
  # Cleans up params. Removes things like File object handlers
57
63
  # Sets up ignored values so we don't generate new keys for same data
58
- def api_deep_clean_params(params)
64
+ def self.api_deep_clean_params(params)
59
65
  case params
60
66
  when Hash
61
67
  params.each_with_object({}) do |(key, value), res|
62
- res[key.to_s] = api_deep_clean_params(value)
68
+ res[key.to_s] = ApiDocs::TestHelper.api_deep_clean_params(value)
63
69
  end
64
70
  when Array
65
- params.collect{|value| api_deep_clean_params(value)}
71
+ params.collect{|value| ApiDocs::TestHelper.api_deep_clean_params(value)}
66
72
  else
67
73
  case params
68
74
  when Rack::Test::UploadedFile
@@ -74,4 +80,4 @@ module ApiDocs::TestHelper
74
80
  end
75
81
  end
76
82
 
77
- ActionDispatch::IntegrationTest.send :include, ApiDocs::TestHelper
83
+ ActionDispatch::IntegrationTest.send :include, ApiDocs::TestHelper::InstanceMethods
@@ -0,0 +1,3 @@
1
+ module ApiDocs
2
+ VERSION = "1.0.6"
3
+ end
@@ -1,24 +1,6 @@
1
1
  class ApplicationController < ActionController::Base
2
- protect_from_forgery
3
2
 
4
- def index
5
- respond_to do |format|
6
- format.json {
7
- render :text => [{
8
- :id => 1,
9
- :name => 'Test User',
10
- :created_at => 1.day.ago
11
- }].to_json
12
- }
13
- format.xml {
14
- render :text => [{
15
- :id => 1,
16
- :name => 'Test User',
17
- :created_at => 1.day.ago
18
- }].to_xml(:root => 'users')
19
- }
20
- end
21
- end
3
+ http_basic_authenticate_with :name => 'user', :password => 'secret', :only => :authenticate
22
4
 
23
5
  def show
24
6
  status = :ok
@@ -41,4 +23,8 @@ class ApplicationController < ActionController::Base
41
23
  end
42
24
  end
43
25
  end
26
+
27
+ def authenticate
28
+ render :text => {:message => 'Authenticated'}.to_json
29
+ end
44
30
  end
@@ -1,4 +1,5 @@
1
1
  Rails.application.routes.draw do
2
2
  mount ApiDocs::Engine => '/'
3
- match '/users/:id' => 'application#show'
3
+ match '/users/:id' => 'application#show'
4
+ match '/authenticate' => 'application#authenticate'
4
5
  end
@@ -11,21 +11,21 @@ class TestHelperTest < ActionDispatch::IntegrationTest
11
11
 
12
12
  def test_api_deep_clean_params
13
13
  assert_equal ({'a' => 'b'}),
14
- api_deep_clean_params({:a => 'b'})
14
+ ApiDocs::TestHelper.api_deep_clean_params({:a => 'b'})
15
15
 
16
16
  assert_equal ({'a' => {'b' => 'c'}}),
17
- api_deep_clean_params({:a => {:b => 'c'}})
17
+ ApiDocs::TestHelper.api_deep_clean_params({:a => {:b => 'c'}})
18
18
 
19
19
  assert_equal ([{'a' => 'b'}, {'c' => 'd'}]),
20
- api_deep_clean_params([{:a => 'b'}, {:c => 'd'}])
20
+ ApiDocs::TestHelper.api_deep_clean_params([{:a => 'b'}, {:c => 'd'}])
21
21
 
22
22
  assert_equal ({'a'=>[{'b'=>'c'}]}),
23
- api_deep_clean_params({:a => [{:b => 'c'}]})
23
+ ApiDocs::TestHelper.api_deep_clean_params({:a => [{:b => 'c'}]})
24
24
  end
25
25
 
26
26
  def test_api_deep_clean_params_with_file_handler
27
27
  assert_equal ({'a' => 'BINARY'}),
28
- api_deep_clean_params({:a => Rack::Test::UploadedFile.new(__FILE__)})
28
+ ApiDocs::TestHelper.api_deep_clean_params({:a => Rack::Test::UploadedFile.new(__FILE__)})
29
29
  end
30
30
 
31
31
  def test_api_call
@@ -110,4 +110,18 @@ eoxml
110
110
  assert_equal 1, output['show'].keys.size
111
111
  end
112
112
 
113
+ def test_api_call_with_httpauth
114
+ auth = ActionController::HttpAuthentication::Basic.encode_credentials('user', 'secret')
115
+ api_call(:get, '/authenticate', :random => 1, :format => 'json', 'HTTP_AUTHORIZATION' => auth) do
116
+ assert_response :success
117
+ assert_equal ({'message' => 'Authenticated'}), JSON.parse(response.body)
118
+ end
119
+ end
120
+
121
+ def test_api_call_with_httpauth_failure
122
+ api_call(:get, '/authenticate', :random => 1, :format => 'json') do
123
+ assert_response :unauthorized
124
+ end
125
+ end
126
+
113
127
  end
metadata CHANGED
@@ -1,17 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Oleg Khabarov
9
- - Jack Neto
10
- - The Working Group Inc.
11
9
  autorequire:
12
10
  bindir: bin
13
11
  cert_chain: []
14
- date: 2013-02-28 00:00:00.000000000 Z
12
+ date: 2013-05-23 00:00:00.000000000 Z
15
13
  dependencies:
16
14
  - !ruby/object:Gem::Dependency
17
15
  name: rails
@@ -29,46 +27,14 @@ dependencies:
29
27
  - - ! '>='
30
28
  - !ruby/object:Gem::Version
31
29
  version: 3.1.0
32
- - !ruby/object:Gem::Dependency
33
- name: jquery-rails
34
- requirement: !ruby/object:Gem::Requirement
35
- none: false
36
- requirements:
37
- - - ! '>='
38
- - !ruby/object:Gem::Version
39
- version: '0'
40
- type: :runtime
41
- prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
- requirements:
45
- - - ! '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- - !ruby/object:Gem::Dependency
49
- name: jeweler
50
- requirement: !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ! '>='
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
- type: :development
57
- prerelease: false
58
- version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
- requirements:
61
- - - ! '>='
62
- - !ruby/object:Gem::Version
63
- version: '0'
64
- description: Generate API documentation using integration tests in Ruby on Rails 3
65
- email: jack@twg.ca
30
+ description: Generate API documentation using integration tests in Ruby on Rails
31
+ email:
32
+ - oleg@khabarov.ca
66
33
  executables: []
67
34
  extensions: []
68
- extra_rdoc_files:
69
- - LICENSE
70
- - README.md
35
+ extra_rdoc_files: []
71
36
  files:
37
+ - .gitignore
72
38
  - Gemfile
73
39
  - LICENSE
74
40
  - README.md
@@ -87,6 +53,7 @@ files:
87
53
  - lib/api_docs/configuration.rb
88
54
  - lib/api_docs/engine.rb
89
55
  - lib/api_docs/test_helper.rb
56
+ - lib/api_docs/version.rb
90
57
  - lib/tasks/api_docs.rake
91
58
  - script/rails
92
59
  - test/api_docs_test.rb
@@ -129,8 +96,7 @@ files:
129
96
  - test/test_helper.rb
130
97
  - test/test_helper_test.rb
131
98
  homepage: http://github.com/twg/api_docs
132
- licenses:
133
- - MIT
99
+ licenses: []
134
100
  post_install_message:
135
101
  rdoc_options: []
136
102
  require_paths:
@@ -141,9 +107,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
107
  - - ! '>='
142
108
  - !ruby/object:Gem::Version
143
109
  version: '0'
144
- segments:
145
- - 0
146
- hash: -620307920657419595
147
110
  required_rubygems_version: !ruby/object:Gem::Requirement
148
111
  none: false
149
112
  requirements:
@@ -155,5 +118,5 @@ rubyforge_project:
155
118
  rubygems_version: 1.8.23
156
119
  signing_key:
157
120
  specification_version: 3
158
- summary: Generate API documentation using integration tests in Ruby on Rails 3
121
+ summary: Generate API documentation using integration tests in Ruby on Rails
159
122
  test_files: []