optionsful 0.1.8 → 0.2.3
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.
- data/MIT-LICENSE +1 -1
- data/README.textile +30 -20
- data/Rakefile +1 -1
- data/lib/baurets/optionsful/introspections.rb +11 -18
- data/lib/baurets/optionsful/server.rb +5 -0
- data/lib/baurets/optionsful/version.rb +2 -2
- data/lib/optionsful.rb +0 -1
- data/lib/tasks/optionsful.rake +8 -4
- data/rails/init.rb +7 -1
- data/samples/optionsful.yml +14 -0
- data/spec/optionsful_config_spec.rb +8 -12
- data/spec/optionsful_server_spec.rb +236 -70
- data/spec/spec_helper.rb +7 -22
- metadata +10 -31
- data/lib/baurets/optionsful/documentator.rb +0 -158
- data/spec/optionsful_documentator_spec.rb +0 -117
- data/spec/samples/app/controllers/comments_controller.rb +0 -86
- data/spec/samples/app/controllers/notes_controller.rb +0 -6
- data/spec/samples/app/controllers/posts_controller.rb +0 -185
- data/spec/samples/app/controllers/teams_controller.rb +0 -33
- data/spec/samples/app/controllers/trips_controller.rb +0 -82
@@ -1,117 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe Baurets::Optionsful::Documentator do
|
5
|
-
|
6
|
-
include Rack::Test::Methods
|
7
|
-
|
8
|
-
Baurets::Optionsful::Documentator.send(:remove_const, :RAILS_ROOT) if Baurets::Optionsful::Documentator.const_defined?(:RAILS_ROOT)
|
9
|
-
Baurets::Optionsful::Documentator.const_set(:RAILS_ROOT, File.join(File.dirname(__FILE__), 'samples' ) )
|
10
|
-
base_path = ::Baurets::Optionsful::Config.new.base_path
|
11
|
-
|
12
|
-
describe "as a Rack middleware" do
|
13
|
-
|
14
|
-
it "is a Ruby object that responds to call;" do
|
15
|
-
assert ::Baurets::Optionsful::Documentator.new(app).respond_to? :call
|
16
|
-
end
|
17
|
-
|
18
|
-
before do
|
19
|
-
ActionController::Routing::Routes.draw do |map|
|
20
|
-
map.resources :posts, :has_many => :comments
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it "takes exactly one argument, (the environment) and returns an Array;" do
|
25
|
-
response = ::Baurets::Optionsful::Documentator.new(app).call(mock_env({"REQUEST_METHOD" => "GET", "PATH_INFO" => (base_path + "/posts")}))
|
26
|
-
assert response.kind_of?(Array)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "the returned Array must have exactly three values: the status, the headers and the body;" do
|
30
|
-
response = ::Baurets::Optionsful::Documentator.new(app).call(mock_env({"REQUEST_METHOD" => "GET", "PATH_INFO" => (base_path + "/posts")}))
|
31
|
-
assert response.size.should == 3
|
32
|
-
assert response[0].kind_of? Fixnum
|
33
|
-
assert response[1].kind_of? Hash
|
34
|
-
assert response[2].kind_of? String
|
35
|
-
end
|
36
|
-
|
37
|
-
it "must be nice, acting somewhere on a Rack middleware stack." do
|
38
|
-
response = fake_docs_app.call(mock_env({"REQUEST_METHOD" => "GET", "PATH_INFO" => "/lobster"}))
|
39
|
-
assert response.size.should == 3
|
40
|
-
assert response[0].kind_of? Fixnum
|
41
|
-
assert response[0].should == 200
|
42
|
-
assert response[1].kind_of? Hash
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "extracts metadata information about a resource" do
|
48
|
-
|
49
|
-
describe "MUST override Rails routing recognition successfully" do
|
50
|
-
|
51
|
-
before(:all) do
|
52
|
-
ActionController::Routing::Routes.draw do |map|
|
53
|
-
map.resources :posts, :has_many => :comments
|
54
|
-
map.resources :notes
|
55
|
-
map.resources :stuff
|
56
|
-
map.resources :trips
|
57
|
-
map.resources :teams
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
it "may let the request go through if base path doesn't match" do
|
62
|
-
pending
|
63
|
-
# req_path = "/xyz"
|
64
|
-
# response = http_get_request(req_path)
|
65
|
-
# assert response[0].kind_of? Fixnum
|
66
|
-
# assert response[0].should_not == 500
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
it "MAY find proper structured information and build an html response" do
|
71
|
-
Baurets::Optionsful::Documentator.send(:remove_const, :RAILS_ROOT) if Baurets::Optionsful::Documentator.const_defined?(:RAILS_ROOT)
|
72
|
-
Baurets::Optionsful::Documentator.const_set(:RAILS_ROOT, File.join(File.dirname(__FILE__), 'samples' ) )
|
73
|
-
req_path = base_path + "/posts"
|
74
|
-
response = http_get_request(req_path)
|
75
|
-
|
76
|
-
assert response[0].kind_of? Fixnum
|
77
|
-
assert response[0].should == 200
|
78
|
-
end
|
79
|
-
|
80
|
-
it "MAY NOT find proper structured information and build an html response" do
|
81
|
-
req_path = base_path + "/notes"
|
82
|
-
response = http_get_request(req_path)
|
83
|
-
assert response.kind_of?(Array)
|
84
|
-
assert response[0].kind_of? Fixnum
|
85
|
-
end
|
86
|
-
|
87
|
-
it "MAY NOT find controller file and build an html response" do
|
88
|
-
req_path = base_path + "/stuff"
|
89
|
-
response = http_get_request(req_path)
|
90
|
-
assert response.kind_of?(Array)
|
91
|
-
assert response[0].kind_of? Fixnum
|
92
|
-
end
|
93
|
-
|
94
|
-
it "MAY NOT understand anything" do
|
95
|
-
req_path = base_path + "/trips"
|
96
|
-
response = http_get_request(req_path)
|
97
|
-
assert response.kind_of?(Array)
|
98
|
-
assert response[0].kind_of? Fixnum
|
99
|
-
end
|
100
|
-
|
101
|
-
it "MAY NOT understand anything" do
|
102
|
-
req_path = base_path + "/teams"
|
103
|
-
response = http_get_request(req_path)
|
104
|
-
assert response.kind_of?(Array)
|
105
|
-
assert response[0].kind_of? Fixnum
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
after(:all) do
|
110
|
-
ActionController::Routing::Routes.reload!
|
111
|
-
end
|
112
|
-
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
# ---
|
2
|
-
# service:
|
3
|
-
# title: Post comments controller
|
4
|
-
# entrypoint: /posts/:post/comments
|
5
|
-
# support: kayaman@baurets.net
|
6
|
-
# description: Comments Service allow you say shit about anything you dislike!
|
7
|
-
class CommentsController < ApplicationController
|
8
|
-
|
9
|
-
# ---
|
10
|
-
# resource:
|
11
|
-
# title: list
|
12
|
-
# identifier: /posts/{:post}/comments
|
13
|
-
# support: kayaman@baurets.net
|
14
|
-
# description: Create new comments over a post instance.
|
15
|
-
# source-link: research
|
16
|
-
# alternates:
|
17
|
-
# - one
|
18
|
-
# - two
|
19
|
-
# representation:
|
20
|
-
# media-types:
|
21
|
-
# - application/xml
|
22
|
-
# - application/json
|
23
|
-
# last-modified: 2010-07-23
|
24
|
-
# control:
|
25
|
-
# cache: no-cache
|
26
|
-
def index
|
27
|
-
end
|
28
|
-
|
29
|
-
# ---
|
30
|
-
# resource:
|
31
|
-
# title: create
|
32
|
-
# identifier: /
|
33
|
-
# support: kayaman@baurets.net
|
34
|
-
# description: Create new posts.
|
35
|
-
# source-link: research
|
36
|
-
# alternates:
|
37
|
-
# - one
|
38
|
-
# - two
|
39
|
-
# representation:
|
40
|
-
# media-types:
|
41
|
-
# - application/xml
|
42
|
-
# - application/json
|
43
|
-
# last-modified: 2010-07-23
|
44
|
-
# control:
|
45
|
-
# cache: no-cache
|
46
|
-
def show
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
def new
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
def update
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
def delete
|
59
|
-
end
|
60
|
-
|
61
|
-
# ---
|
62
|
-
# resource:
|
63
|
-
# title: create
|
64
|
-
# identifier: /
|
65
|
-
# support: kayaman@baurets.net
|
66
|
-
# description: Create new posts.
|
67
|
-
# source-link: research
|
68
|
-
# alternates:
|
69
|
-
# - one
|
70
|
-
# - two
|
71
|
-
# representation:
|
72
|
-
# media-types:
|
73
|
-
# - application/xml
|
74
|
-
# - application/json
|
75
|
-
# last-modified: 2010-07-23
|
76
|
-
# control:
|
77
|
-
# cache: no-cache
|
78
|
-
def create
|
79
|
-
@post = Post.find(params[:post_id])
|
80
|
-
@comment = @post.comments.create!(params[:comment])
|
81
|
-
respond_to do |format|
|
82
|
-
format.html { redirect_to @post }
|
83
|
-
format.js
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,185 +0,0 @@
|
|
1
|
-
# ---
|
2
|
-
# service:
|
3
|
-
# title: Posts front controller
|
4
|
-
# entrypoint: /posts
|
5
|
-
# support: kayaman@baurets.net
|
6
|
-
# description: The Posts sevices let you list, create, update, and delete Posts from our application.
|
7
|
-
class PostsController < ApplicationController
|
8
|
-
before_filter :authenticate, :except => [:index, :show]
|
9
|
-
|
10
|
-
# ---
|
11
|
-
# resource:
|
12
|
-
# title: Listing
|
13
|
-
# identifier: /
|
14
|
-
# support: kayaman@baurets.net
|
15
|
-
# description: List posts.
|
16
|
-
# source-link: research
|
17
|
-
# alternates:
|
18
|
-
# - one
|
19
|
-
# - two
|
20
|
-
# representation:
|
21
|
-
# media-types:
|
22
|
-
# - application/xml
|
23
|
-
# - application/json
|
24
|
-
# last-modified: 2010-07-23
|
25
|
-
# control:
|
26
|
-
# cache: cache-control
|
27
|
-
def index
|
28
|
-
@posts = Post.find(:all)
|
29
|
-
|
30
|
-
respond_to do |format|
|
31
|
-
format.html # index.html.erb
|
32
|
-
format.xml { render :xml => @posts }
|
33
|
-
format.json { render :json => @posts }
|
34
|
-
format.atom
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# ---
|
39
|
-
# resource:
|
40
|
-
# title: Posts front controller
|
41
|
-
# identifier: /posts
|
42
|
-
# support: kayaman@baurets.net
|
43
|
-
# description: Retuns all posts.
|
44
|
-
# representation:
|
45
|
-
# media-types:
|
46
|
-
# - application/xml
|
47
|
-
# - application/json
|
48
|
-
# last-modified: 2010-07-23
|
49
|
-
def show
|
50
|
-
@post = Post.find(params[:id])
|
51
|
-
|
52
|
-
respond_to do |format|
|
53
|
-
format.html # show.html.erb
|
54
|
-
format.xml { render :xml => @post }
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# ---
|
59
|
-
# resource:
|
60
|
-
# title: Posts front controller
|
61
|
-
# identifier: /posts
|
62
|
-
# support: kayaman@baurets.net
|
63
|
-
# description: Retuns all posts.
|
64
|
-
# representation:
|
65
|
-
# media-types:
|
66
|
-
# - application/xml
|
67
|
-
# - application/json
|
68
|
-
# last-modified: 2010-07-23
|
69
|
-
def new
|
70
|
-
@post = Post.new
|
71
|
-
|
72
|
-
respond_to do |format|
|
73
|
-
format.html # new.html.erb
|
74
|
-
format.xml { render :xml => @post }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# ---
|
79
|
-
# resource:
|
80
|
-
# title: create
|
81
|
-
# identifier: /
|
82
|
-
# support: kayaman@baurets.net
|
83
|
-
# description: Create new posts.
|
84
|
-
# source-link: research
|
85
|
-
# alternates:
|
86
|
-
# - one
|
87
|
-
# - two
|
88
|
-
# representation:
|
89
|
-
# media-types:
|
90
|
-
# - application/xml
|
91
|
-
# - application/json
|
92
|
-
# last-modified: 2010-07-23
|
93
|
-
# control:
|
94
|
-
# cache: no-cache
|
95
|
-
def edit
|
96
|
-
@post = Post.find(params[:id])
|
97
|
-
end
|
98
|
-
|
99
|
-
# ---
|
100
|
-
# resource:
|
101
|
-
# title: create
|
102
|
-
# identifier: /
|
103
|
-
# support: kayaman@baurets.net
|
104
|
-
# description: Create new posts.
|
105
|
-
# source-link: research
|
106
|
-
# alternates:
|
107
|
-
# - one
|
108
|
-
# - two
|
109
|
-
# representation:
|
110
|
-
# media-types:
|
111
|
-
# - application/xml
|
112
|
-
# - application/json
|
113
|
-
# last-modified: 2010-07-23
|
114
|
-
# control:
|
115
|
-
# cache: no-cache
|
116
|
-
def create
|
117
|
-
@post = Post.new(params[:post])
|
118
|
-
|
119
|
-
respond_to do |format|
|
120
|
-
if @post.save
|
121
|
-
flash[:notice] = 'Post was successfully created.'
|
122
|
-
format.html { redirect_to(@post) }
|
123
|
-
format.xml { render :xml => @post, :status => :created, :location => @post }
|
124
|
-
else
|
125
|
-
format.html { render :action => "new" }
|
126
|
-
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# ---
|
132
|
-
# resource:
|
133
|
-
# title: Posts front controller
|
134
|
-
# identifier: /posts
|
135
|
-
# support: kayaman@baurets.net
|
136
|
-
# description: Retuns all posts.
|
137
|
-
# representation:
|
138
|
-
# media-types:
|
139
|
-
# - application/xml
|
140
|
-
# - application/json
|
141
|
-
# last-modified: 2010-07-23
|
142
|
-
def update
|
143
|
-
@post = Post.find(params[:id])
|
144
|
-
|
145
|
-
respond_to do |format|
|
146
|
-
if @post.update_attributes(params[:post])
|
147
|
-
flash[:notice] = 'Post was successfully updated.'
|
148
|
-
format.html { redirect_to(@post) }
|
149
|
-
format.xml { head :ok }
|
150
|
-
else
|
151
|
-
format.html { render :action => "edit" }
|
152
|
-
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
# ---
|
158
|
-
# resource:
|
159
|
-
# title: Posts front controller
|
160
|
-
# identifier: /posts
|
161
|
-
# support: kayaman@baurets.net
|
162
|
-
# description: Retuns all posts.
|
163
|
-
# representation:
|
164
|
-
# media-types:
|
165
|
-
# - application/xml
|
166
|
-
# - application/json
|
167
|
-
# last-modified: 2010-07-23
|
168
|
-
def destroy
|
169
|
-
@post = Post.find(params[:id])
|
170
|
-
@post.destroy
|
171
|
-
|
172
|
-
respond_to do |format|
|
173
|
-
format.html { redirect_to(posts_url) }
|
174
|
-
format.xml { head :ok }
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
private
|
179
|
-
|
180
|
-
def authenticate
|
181
|
-
authenticate_or_request_with_http_basic do |name, password|
|
182
|
-
name == "admin" && password == "secret"
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# ---
|
2
|
-
# service:
|
3
|
-
# title: Teams controller
|
4
|
-
# entrypoint: /posts/:post/comments
|
5
|
-
# support: kayaman@baurets.net
|
6
|
-
# description: Comments Service allow you say shit about anything you dislike!
|
7
|
-
class TripsController < ApplicationController
|
8
|
-
|
9
|
-
# !! something wrong ? &
|
10
|
-
# & ^% !@#
|
11
|
-
def index
|
12
|
-
end
|
13
|
-
|
14
|
-
def show
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
def new
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
def update
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
def delete
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
def create
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# sjdhsdjhsdhhjdhjjdhsjhsdhsdjhjshdjhsdshd
|
3
|
-
class TripsController < ApplicationController
|
4
|
-
|
5
|
-
# ---
|
6
|
-
# resource:
|
7
|
-
# title: list
|
8
|
-
# identifier: /posts/{:post}/comments
|
9
|
-
# support: kayaman@baurets.net
|
10
|
-
# description: Create new comments over a post instance.
|
11
|
-
# source-link: research
|
12
|
-
# alternates:
|
13
|
-
# - one
|
14
|
-
# - two
|
15
|
-
# representation:
|
16
|
-
# media-types:
|
17
|
-
# - application/xml
|
18
|
-
# - application/json
|
19
|
-
# last-modified: 2010-07-23
|
20
|
-
# control:
|
21
|
-
# cache: no-cache
|
22
|
-
def index
|
23
|
-
end
|
24
|
-
|
25
|
-
# ---
|
26
|
-
# resource:
|
27
|
-
# title: create
|
28
|
-
# identifier: /
|
29
|
-
# support: kayaman@baurets.net
|
30
|
-
# description: Create new posts.
|
31
|
-
# source-link: research
|
32
|
-
# alternates:
|
33
|
-
# - one
|
34
|
-
# - two
|
35
|
-
# representation:
|
36
|
-
# media-types:
|
37
|
-
# - application/xml
|
38
|
-
# - application/json
|
39
|
-
# last-modified: 2010-07-23
|
40
|
-
# control:
|
41
|
-
# cache: no-cache
|
42
|
-
def show
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
def new
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
def update
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
def delete
|
55
|
-
end
|
56
|
-
|
57
|
-
# ---
|
58
|
-
# resource:
|
59
|
-
# title: create
|
60
|
-
# identifier: /
|
61
|
-
# support: kayaman@baurets.net
|
62
|
-
# description: Create new posts.
|
63
|
-
# source-link: research
|
64
|
-
# alternates:
|
65
|
-
# - one
|
66
|
-
# - two
|
67
|
-
# representation:
|
68
|
-
# media-types:
|
69
|
-
# - application/xml
|
70
|
-
# - application/json
|
71
|
-
# last-modified: 2010-07-23
|
72
|
-
# control:
|
73
|
-
# cache: no-cache
|
74
|
-
def create
|
75
|
-
@post = Post.find(params[:post_id])
|
76
|
-
@comment = @post.comments.create!(params[:comment])
|
77
|
-
respond_to do |format|
|
78
|
-
format.html { redirect_to @post }
|
79
|
-
format.js
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|