sinatra-rabbit 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sinatra/rabbit/base.rb +0 -9
- data/sinatra-rabbit.gemspec +2 -1
- data/tests/app_test.rb +71 -0
- data/tests/docs_test.rb +73 -0
- data/tests/dsl_test.rb +260 -0
- data/tests/fixtures.rb +149 -0
- data/tests/params_test.rb +96 -0
- metadata +8 -3
data/lib/sinatra/rabbit/base.rb
CHANGED
@@ -356,15 +356,6 @@ module Sinatra
|
|
356
356
|
@options[:with_capability]
|
357
357
|
end
|
358
358
|
|
359
|
-
def self.has_capability?
|
360
|
-
@capability ||= Sinatra::Rabbit.configuration[:check_capability]
|
361
|
-
if @capability and required_capability
|
362
|
-
@capability.call(required_capability)
|
363
|
-
else
|
364
|
-
true
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
359
|
def self.description(text=nil)
|
369
360
|
@description ||= text
|
370
361
|
end
|
data/sinatra-rabbit.gemspec
CHANGED
@@ -29,12 +29,13 @@ Gem::Specification.new do |s|
|
|
29
29
|
a simple REST API using easy to undestand DSL.
|
30
30
|
EOF
|
31
31
|
|
32
|
-
s.version = '1.0.
|
32
|
+
s.version = '1.0.8'
|
33
33
|
s.date = Time.now
|
34
34
|
s.summary = %q{Sinatra REST API DSL}
|
35
35
|
s.files = FileList[
|
36
36
|
'lib/sinatra/*.rb',
|
37
37
|
'lib/sinatra/rabbit/*.rb',
|
38
|
+
'tests/*.rb',
|
38
39
|
'LICENSE',
|
39
40
|
'README.md',
|
40
41
|
'sinatra-rabbit.gemspec',
|
data/tests/app_test.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
|
3
|
+
include Rack::Test::Methods
|
4
|
+
|
5
|
+
def app
|
6
|
+
Sample
|
7
|
+
end
|
8
|
+
|
9
|
+
def status
|
10
|
+
last_response.status
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Sample do
|
14
|
+
|
15
|
+
it "should respond with status OK for root" do
|
16
|
+
get '/'
|
17
|
+
status.must_equal 200
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should respond 400 to index operation for sample collection without param" do
|
21
|
+
get '/sample'
|
22
|
+
status.must_equal 400
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should respond 200 to index operation for sample collection with param" do
|
26
|
+
get '/sample', { :id => :sample }
|
27
|
+
status.must_equal 200
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should respond 200 to HEAD request for index operation in sample collection" do
|
31
|
+
head '/sample/index'
|
32
|
+
status.must_equal 200
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should respond to OPTIONS request for index operation in sample collection" do
|
36
|
+
options '/sample/index'
|
37
|
+
status.must_equal 200
|
38
|
+
allow_header = last_response.headers['Allow'].split(',')
|
39
|
+
allow_header.wont_be_empty
|
40
|
+
allow_header.must_include 'feature_data:string:optional'
|
41
|
+
allow_header.must_include 'id:string:required'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should respond 200 to show operation for sample collection" do
|
45
|
+
get '/sample/100'
|
46
|
+
status.must_equal 200
|
47
|
+
last_response.body.must_equal '100'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should respond 201 to delete operation on sample collection" do
|
51
|
+
delete '/sample/100'
|
52
|
+
status.must_equal 201
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should respond 200 to stop operation with condition routes" do
|
56
|
+
get '/sample/100/stop'
|
57
|
+
status.must_equal 200
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should respond 200 to sample subcollection index operation" do
|
61
|
+
get '/sample/10/subsample/20'
|
62
|
+
status.must_equal 200
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should raise an exception when posting data with unknown values" do
|
66
|
+
post '/sample', { :id => '1', :arch => '3'}
|
67
|
+
last_response.status.must_equal 400
|
68
|
+
last_response.body.must_equal "Parameter 'arch' value '3' not found in list of allowed values [1,2]"
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
data/tests/docs_test.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
def app
|
7
|
+
Sample
|
8
|
+
end
|
9
|
+
|
10
|
+
def status
|
11
|
+
last_response.status
|
12
|
+
end
|
13
|
+
|
14
|
+
def html
|
15
|
+
Nokogiri::HTML(last_response.body)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'Documentation' do
|
19
|
+
|
20
|
+
it "should respond with status OK for root" do
|
21
|
+
get '/docs'
|
22
|
+
status.must_equal 200
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return list of collections in entrypoint" do
|
26
|
+
get '/docs'
|
27
|
+
html.css('html body > h1').text.must_equal 'Sample'
|
28
|
+
html.css('html body ul li').wont_be_empty
|
29
|
+
html.css('html body ul li a').wont_be_empty
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return valid collection name when query collection documentation" do
|
33
|
+
get '/docs/sample'
|
34
|
+
html.css('html body > h1').text.must_equal 'SampleCollection'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return valid collection description when query collection documentation" do
|
38
|
+
get '/docs/sample'
|
39
|
+
html.css('html body > blockquote').text.must_equal 'Test'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return valid collection url when query collection documentation" do
|
43
|
+
get '/docs/sample'
|
44
|
+
html.css('html body > .url').text.must_equal '/sample'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return list of features when query collection documentation" do
|
48
|
+
get '/docs/sample'
|
49
|
+
html.css('html body .features .feature').map { |f| f.text}.must_include 'user_data', 'user_name'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return complete list of operations when query collection documentation" do
|
53
|
+
get '/docs/sample'
|
54
|
+
html.css('html body .operations tr').size.must_equal 7
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should provide valid links from entrypoint to collection" do
|
58
|
+
get '/docs'
|
59
|
+
html.css('html body ul li a').each do |a|
|
60
|
+
get a[:href]
|
61
|
+
last_response.status.must_equal 200
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should provide valid links from collection to an operation" do
|
66
|
+
get '/docs/sample'
|
67
|
+
html.css('html body .operations tbody .name a').each do |a|
|
68
|
+
get a[:href]
|
69
|
+
last_response.status.must_equal 200
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/tests/dsl_test.rb
ADDED
@@ -0,0 +1,260 @@
|
|
1
|
+
describe Sinatra::Rabbit::DSL do
|
2
|
+
|
3
|
+
it "should allow to set configuration" do
|
4
|
+
Sinatra::Rabbit.configure do
|
5
|
+
enable :documentation
|
6
|
+
enable :head_routes
|
7
|
+
enable :options_routes
|
8
|
+
disable :sample_setting
|
9
|
+
end
|
10
|
+
Sinatra::Rabbit.enabled?(:documentation).must_equal true
|
11
|
+
Sinatra::Rabbit.disabled?(:documentation).must_equal false
|
12
|
+
Sinatra::Rabbit.enabled?(:sample_setting).must_equal false
|
13
|
+
Sinatra::Rabbit.disabled?(:sample_setting).must_equal true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should allow to set any property" do
|
17
|
+
Sinatra::Rabbit.set(:test_property, '1')
|
18
|
+
Sinatra::Rabbit.configuration[:test_property].must_equal '1'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have collection method" do
|
22
|
+
Sample.respond_to?(:collection).must_equal true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be Sinatra::Base class" do
|
26
|
+
Sample.respond_to?(:configure).must_equal true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return list of all collections" do
|
30
|
+
Sample.collections.wont_be_empty
|
31
|
+
Sample.collections.size.must_equal 3
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe Sinatra::Rabbit::Collection do
|
37
|
+
|
38
|
+
it "should include SampleCollection and SecondSampleCollection" do
|
39
|
+
Sample.collections.wont_be_empty
|
40
|
+
Sample.collections.must_include Sinatra::Rabbit::SampleCollection
|
41
|
+
Sample.collections.must_include Sinatra::Rabbit::SecondSampleCollection
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return SampleCollection using .collection method" do
|
45
|
+
Sample.collection(:sample).must_equal Sinatra::Rabbit::SampleCollection
|
46
|
+
Sample.collection(:non_existing_sample).must_be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should return SampleCollection using [] method' do
|
50
|
+
Sample[:sample].must_equal Sinatra::Rabbit::SampleCollection
|
51
|
+
Sample[:non_existing_sample].must_be_nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should allow to register new collection dynamically" do
|
55
|
+
Sample.collection(:dynamic) do
|
56
|
+
description 'DynamicTest'
|
57
|
+
operation :index do
|
58
|
+
control do
|
59
|
+
status 200
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
Sample.collection(:dynamic).must_equal Sinatra::Rabbit::DynamicCollection
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should raise exception when contain control block" do
|
67
|
+
lambda {
|
68
|
+
Sample.collection(:raise) do
|
69
|
+
description 'RaiseTest'
|
70
|
+
control do
|
71
|
+
status 200
|
72
|
+
end
|
73
|
+
end
|
74
|
+
}.must_raise RuntimeError
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should allow to return base class" do
|
78
|
+
Sample.collection(:second_sample).base_class.must_equal Sample
|
79
|
+
Sample.collection(:sample).collection(:subsample).base_class.must_equal Sample
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return correct collection name" do
|
83
|
+
Sample.collection(:sample).collection_name.must_equal :sample
|
84
|
+
Sample.collection(:second_sample).collection_name.must_equal :second_sample
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should have correct URI set" do
|
88
|
+
Sample.collection(:sample).full_path.must_equal '/sample'
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return correct collection description" do
|
92
|
+
Sample.collection(:sample).description.must_equal 'Test'
|
93
|
+
Sample.collection(:second_sample).description.must_equal 'SecondTest'
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should return operations and find index operation" do
|
97
|
+
Sample.collection(:sample).operations.wont_be_empty
|
98
|
+
Sample.collection(:sample).operations.must_include Sinatra::Rabbit::SampleCollection::IndexOperation
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return operation using [] syntax" do
|
102
|
+
Sample[:sample][:index].must_equal Sinatra::Rabbit::SampleCollection::IndexOperation
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should return subcollection using [] syntax" do
|
106
|
+
Sample[:sample][:subsample].must_equal Sinatra::Rabbit::SampleCollection::SubsampleCollection
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should return operation from subcollection using the [] syntax" do
|
110
|
+
Sample[:sample][:subsample][:start].must_equal Sinatra::Rabbit::SampleCollection::SubsampleCollection::StartOperation
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should allow to define subcollection" do
|
114
|
+
Sample.collection(:sample).collections.wont_be_empty
|
115
|
+
Sample.collection(:sample).collections.must_include Sinatra::Rabbit::SampleCollection::SubsampleCollection
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should allow to retrieve subcollection from collection" do
|
119
|
+
Sample.collection(:sample).collection(:subsample).must_equal Sinatra::Rabbit::SampleCollection::SubsampleCollection
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should allow to retrieve subcollection parent collection" do
|
123
|
+
Sample.collection(:sample).collection(:subsample).parent_collection.must_equal Sinatra::Rabbit::SampleCollection
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should allow to get all operations defined for subcollection" do
|
127
|
+
Sample.collection(:sample).collection(:subsample).operations.must_include Sinatra::Rabbit::SampleCollection::SubsampleCollection::ShowOperation
|
128
|
+
Sample.collection(:sample).collection(:subsample).operations.must_include Sinatra::Rabbit::SampleCollection::SubsampleCollection::StartOperation
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should have correct URI set for operations in subcollection" do
|
132
|
+
Sample.collection(:sample).collection(:subsample).operation(:show).full_path.must_equal '/sample/:id/subsample/:sub_id'
|
133
|
+
Sample.collection(:sample).collection(:subsample).operation(:start).full_path.must_equal '/sample/:id/subsample/:sub_id/start'
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should have correct URI set for subcollection" do
|
137
|
+
Sample.collection(:sample).collection(:subsample).full_path.must_equal '/sample/:id/subsample'
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should allow to have deeper subcollections" do
|
141
|
+
Sample.collection(:sample).collection(:subsample).collection(:secondsubsample).must_equal Sinatra::Rabbit::SampleCollection::SubsampleCollection::SecondsubsampleCollection
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
describe Sinatra::Rabbit::Collection::Operation do
|
147
|
+
|
148
|
+
it "should have the :restart action" do
|
149
|
+
Sample.collection(:second_sample).operation(:restart).must_equal Sinatra::Rabbit::SecondSampleCollection::RestartOperation
|
150
|
+
Sample.collection(:second_sample).operation(:restart).full_path.must_equal '/second_sample/:id/restart'
|
151
|
+
Sample.collection(:second_sample).operation(:restart).http_method.must_equal :post
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should return :index operation" do
|
155
|
+
Sample.collection(:sample).operation(:index).must_equal Sinatra::Rabbit::SampleCollection::IndexOperation
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should return correct name" do
|
159
|
+
Sample.collection(:sample).operation(:index).operation_name.must_equal :index
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should return correct description" do
|
163
|
+
Sample.collection(:sample).operation(:index).description.must_equal 'TestIndex'
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should have :id param defined" do
|
167
|
+
Sample.collection(:sample).operation(:index).param(:id).must_be_kind_of Sinatra::Rabbit::Param
|
168
|
+
Sample.collection(:sample).operation(:index).param(:id).name.must_equal :id
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should not return non-existing param" do
|
172
|
+
Sample.collection(:sample).operation(:index).param(:non_existing).must_be_nil
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should allow to add new param" do
|
176
|
+
Sample.collection(:sample).operation(:index).param(:next_id, :string)
|
177
|
+
Sample.collection(:sample).operation(:index).param(:next_id).must_be_kind_of Sinatra::Rabbit::Param
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should return all params" do
|
181
|
+
Sample.collection(:sample).operation(:index).params.wont_be_empty
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should have control block" do
|
185
|
+
Sample.collection(:sample).operation(:index).respond_to?(:control).must_equal true
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should have correct path for index operation" do
|
189
|
+
Sample.collection(:sample).operation(:index).full_path.must_equal '/sample'
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should have correct path for create operation" do
|
193
|
+
Sample.collection(:sample).operation(:create).full_path.must_equal '/sample'
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should have correct path for show operation" do
|
197
|
+
Sample.collection(:sample).operation(:show).full_path.must_equal '/sample/:id'
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should have correct path for destroy operation" do
|
201
|
+
Sample.collection(:sample).operation(:show).full_path.must_equal '/sample/:id'
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should have correct path for stop operation" do
|
205
|
+
Sample.collection(:sample).operation(:stop).full_path.must_equal '/sample/:id/stop'
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
describe Sinatra::Rabbit::Features do
|
211
|
+
|
212
|
+
it "should allow to be defined for Sample collection" do
|
213
|
+
Sample.features.wont_be_empty
|
214
|
+
Sample.features.size.must_equal 3
|
215
|
+
end
|
216
|
+
|
217
|
+
it "should allow to be retrieved by name" do
|
218
|
+
Sample.feature(:user_data).wont_be_nil
|
219
|
+
Sample.feature(:user_data).name.must_equal :user_data
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should allow to be defined more times" do
|
223
|
+
Sample.feature(:user_name).wont_be_nil
|
224
|
+
Sample.feature(:user_data).wont_be_nil
|
225
|
+
Sample.feature(:non_existing_one).must_be_nil
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should contain reference to collection" do
|
229
|
+
Sample.feature(:user_data).collection.wont_be_nil
|
230
|
+
Sample.feature(:user_data).collection.must_equal :sample
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should contain array of operations" do
|
234
|
+
Sample.feature(:user_data).operations.wont_be_empty
|
235
|
+
Sample.feature(:user_data).operations.map {|o| o.class }.must_include Sinatra::Rabbit::Feature::Operation
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should allow to return single operation by name" do
|
239
|
+
Sample.feature(:user_data).operation(:index).wont_be_nil
|
240
|
+
Sample.feature(:user_data).operation(:non_existing_one).must_be_nil
|
241
|
+
Sample.feature(:user_data).operation(:index).name.must_equal :index
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should be retrieved from collection" do
|
245
|
+
Sample.collection(:sample).features.wont_be_nil
|
246
|
+
Sample.collection(:sample).features.size.must_equal 2
|
247
|
+
Sample.collection(:second_sample).features.size.must_equal 1
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should add additionals parameters to given operations" do
|
251
|
+
Sample.collection(:sample).operation(:index).params.map { |p| p.name }.must_include :feature_name
|
252
|
+
Sample.collection(:sample).operation(:index).params.map { |p| p.name }.must_include :feature_data
|
253
|
+
Sample.collection(:second_sample).operation(:index).params.map { |p| p.name }.must_include :feature_second
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should not add additional parameters to other operations" do
|
257
|
+
Sample.collection(:sample).operation(:show).params.map { |p| p.name }.wont_include :feature_name
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
data/tests/fixtures.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
begin
|
3
|
+
require 'simplecov'
|
4
|
+
if ENV['COVERAGE']
|
5
|
+
SimpleCov.start
|
6
|
+
SimpleCov.command_name 'Minitest Tests'
|
7
|
+
end
|
8
|
+
rescue LoadError
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'minitest/autorun'
|
12
|
+
|
13
|
+
require 'sinatra/base'
|
14
|
+
$:.unshift File.join(File::dirname(__FILE__), '..')
|
15
|
+
require 'lib/sinatra/rabbit'
|
16
|
+
|
17
|
+
class Sample < Sinatra::Base
|
18
|
+
include Sinatra::Rabbit
|
19
|
+
include Sinatra::Rabbit::Features
|
20
|
+
|
21
|
+
get '/' do
|
22
|
+
halt 200
|
23
|
+
end
|
24
|
+
|
25
|
+
features do
|
26
|
+
feature :user_data, :for => :sample do
|
27
|
+
operation :index do
|
28
|
+
param :feature_data, :string
|
29
|
+
end
|
30
|
+
end
|
31
|
+
feature :user_name, :for => :sample do
|
32
|
+
operation :index do
|
33
|
+
param :feature_name, :string
|
34
|
+
end
|
35
|
+
end
|
36
|
+
feature :profile_sample, :for => :second_sample do
|
37
|
+
operation :index do
|
38
|
+
param :feature_second, :string
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
collection :sample do
|
44
|
+
|
45
|
+
collection :subsample, :with_id => :sub_id do
|
46
|
+
|
47
|
+
collection :secondsubsample do
|
48
|
+
description "SecondSubCollection"
|
49
|
+
operation :index do
|
50
|
+
control do
|
51
|
+
status 200
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
description "Subcollection"
|
58
|
+
|
59
|
+
operation :start do
|
60
|
+
param :id, :required
|
61
|
+
control do
|
62
|
+
status 200
|
63
|
+
end
|
64
|
+
end
|
65
|
+
operation :show do
|
66
|
+
control do
|
67
|
+
params[:id]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
description "Test"
|
73
|
+
|
74
|
+
operation :index do
|
75
|
+
description "TestIndex"
|
76
|
+
param :id, :string, :required, "TestParam"
|
77
|
+
control do
|
78
|
+
status 200
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
operation :rindex do
|
83
|
+
description "TestIndex"
|
84
|
+
param :r_string, :string, :required, "TestParam"
|
85
|
+
param :o_string, :string, :optional, "TestParam"
|
86
|
+
param :r_number, :number, :required, "TestParam"
|
87
|
+
param :o_number, :number, :optional, "TestParam"
|
88
|
+
param :free_param, :string
|
89
|
+
param :enum_param, :enum, [1,2,3]
|
90
|
+
param :r_enum_param, :enum, :required, [1,2,3]
|
91
|
+
control {}
|
92
|
+
end
|
93
|
+
|
94
|
+
operation :show do
|
95
|
+
description "TestIndex"
|
96
|
+
control do
|
97
|
+
[200, {}, params[:id]]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
operation :create do
|
102
|
+
description "TestIndex"
|
103
|
+
param :id, :string, :required, "TestParam"
|
104
|
+
param :arch, :enum, [1, 2]
|
105
|
+
control do
|
106
|
+
status 200
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
operation :destroy do
|
111
|
+
description "TestIndex"
|
112
|
+
control do
|
113
|
+
status 201
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
operation :stop, :if => (1==1) do
|
118
|
+
description "TestIndex"
|
119
|
+
param :id, :string, :required, "TestParam"
|
120
|
+
control do
|
121
|
+
status 200
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
collection :second_sample do
|
128
|
+
description "SecondTest"
|
129
|
+
|
130
|
+
action :restart do
|
131
|
+
description "Action operation"
|
132
|
+
param :id, :string, :required, "Test"
|
133
|
+
control do
|
134
|
+
status 200
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
operation :index do
|
139
|
+
description "SecondTestIndex"
|
140
|
+
param :second_id, :string, :required, "TestSecondParam"
|
141
|
+
control do
|
142
|
+
status 200
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
|
@@ -0,0 +1,96 @@
|
|
1
|
+
describe Sinatra::Rabbit::Param do
|
2
|
+
|
3
|
+
def index_operation
|
4
|
+
Sample.collection(:sample).operation(:rindex)
|
5
|
+
end
|
6
|
+
|
7
|
+
it "should return string representation of param" do
|
8
|
+
"#{index_operation.param(:r_string)}".must_equal 'r_string:string:required'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should allow define required string param with description" do
|
12
|
+
index_operation.param(:r_string).wont_be_nil
|
13
|
+
index_operation.param(:r_string).description.must_equal 'TestParam'
|
14
|
+
index_operation.param(:r_string).klass.must_equal :string
|
15
|
+
index_operation.param(:r_string).values
|
16
|
+
index_operation.param(:r_string).required?.must_equal true
|
17
|
+
index_operation.param(:r_string).string?.must_equal true
|
18
|
+
index_operation.param(:r_string).optional?.must_equal false
|
19
|
+
index_operation.param(:r_string).enum?.must_equal false
|
20
|
+
index_operation.param(:r_string).number?.must_equal false
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should allow define optional string param with description" do
|
24
|
+
index_operation.param(:o_string).wont_be_nil
|
25
|
+
index_operation.param(:o_string).description.must_equal 'TestParam'
|
26
|
+
index_operation.param(:o_string).klass.must_equal :string
|
27
|
+
index_operation.param(:o_string).values
|
28
|
+
index_operation.param(:o_string).required?.must_equal false
|
29
|
+
index_operation.param(:o_string).string?.must_equal true
|
30
|
+
index_operation.param(:o_string).optional?.must_equal true
|
31
|
+
index_operation.param(:o_string).enum?.must_equal false
|
32
|
+
index_operation.param(:o_string).number?.must_equal false
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should allow define required number param with description" do
|
36
|
+
index_operation.param(:r_number).wont_be_nil
|
37
|
+
index_operation.param(:r_number).description.must_equal 'TestParam'
|
38
|
+
index_operation.param(:r_number).klass.must_equal :number
|
39
|
+
index_operation.param(:r_number).values
|
40
|
+
index_operation.param(:r_number).required?.must_equal true
|
41
|
+
index_operation.param(:r_number).string?.must_equal false
|
42
|
+
index_operation.param(:r_number).optional?.must_equal false
|
43
|
+
index_operation.param(:r_number).enum?.must_equal false
|
44
|
+
index_operation.param(:r_number).number?.must_equal true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should allow define optional number param with description" do
|
48
|
+
index_operation.param(:o_number).wont_be_nil
|
49
|
+
index_operation.param(:o_number).description.must_equal 'TestParam'
|
50
|
+
index_operation.param(:o_number).klass.must_equal :number
|
51
|
+
index_operation.param(:o_number).required?.must_equal false
|
52
|
+
index_operation.param(:o_number).string?.must_equal false
|
53
|
+
index_operation.param(:o_number).optional?.must_equal true
|
54
|
+
index_operation.param(:o_number).enum?.must_equal false
|
55
|
+
index_operation.param(:o_number).number?.must_equal true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should allow define param just by name and type" do
|
59
|
+
index_operation.param(:free_param).wont_be_nil
|
60
|
+
index_operation.param(:free_param).description.must_equal 'Description not available'
|
61
|
+
index_operation.param(:free_param).klass.must_equal :string
|
62
|
+
index_operation.param(:free_param).values.must_be_nil
|
63
|
+
index_operation.param(:free_param).required?.must_equal false
|
64
|
+
index_operation.param(:free_param).string?.must_equal true
|
65
|
+
index_operation.param(:free_param).optional?.must_equal true
|
66
|
+
index_operation.param(:free_param).enum?.must_equal false
|
67
|
+
index_operation.param(:free_param).number?.must_equal false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should allow to define optional enum param" do
|
71
|
+
index_operation.param(:enum_param).wont_be_nil
|
72
|
+
index_operation.param(:enum_param).description.must_equal 'Description not available'
|
73
|
+
index_operation.param(:enum_param).klass.must_equal :enum
|
74
|
+
index_operation.param(:enum_param).values.wont_be_empty
|
75
|
+
index_operation.param(:enum_param).values.must_include 2
|
76
|
+
index_operation.param(:enum_param).required?.must_equal false
|
77
|
+
index_operation.param(:enum_param).string?.must_equal false
|
78
|
+
index_operation.param(:enum_param).optional?.must_equal true
|
79
|
+
index_operation.param(:enum_param).enum?.must_equal true
|
80
|
+
index_operation.param(:enum_param).number?.must_equal false
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should allow to define required enum param" do
|
84
|
+
index_operation.param(:r_enum_param).wont_be_nil
|
85
|
+
#index_operation.param(:r_enum_param).description.must_equal 'Description not available'
|
86
|
+
index_operation.param(:r_enum_param).klass.must_equal :enum
|
87
|
+
#index_operation.param(:r_enum_param).values.wont_be_empty
|
88
|
+
#index_operation.param(:r_enum_param).values.must_include 2
|
89
|
+
index_operation.param(:r_enum_param).required?.must_equal true
|
90
|
+
index_operation.param(:r_enum_param).string?.must_equal false
|
91
|
+
index_operation.param(:r_enum_param).optional?.must_equal false
|
92
|
+
#index_operation.param(:r_enum_param).enum?.must_equal true
|
93
|
+
index_operation.param(:r_enum_param).number?.must_equal false
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-rabbit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-07-10 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
16
|
-
requirement: &
|
16
|
+
requirement: &70194484049480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 1.3.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70194484049480
|
25
25
|
description: ! " Rabbit is a Sinatra extension which can help you writing\n a
|
26
26
|
simple REST API using easy to undestand DSL.\n"
|
27
27
|
email: dev@deltacloud.apache.org
|
@@ -37,6 +37,11 @@ files:
|
|
37
37
|
- lib/sinatra/rabbit/features.rb
|
38
38
|
- lib/sinatra/rabbit/param.rb
|
39
39
|
- lib/sinatra/rabbit/validator.rb
|
40
|
+
- tests/app_test.rb
|
41
|
+
- tests/docs_test.rb
|
42
|
+
- tests/dsl_test.rb
|
43
|
+
- tests/fixtures.rb
|
44
|
+
- tests/params_test.rb
|
40
45
|
- LICENSE
|
41
46
|
- README.md
|
42
47
|
- sinatra-rabbit.gemspec
|