vayacondios-server 0.2.11 → 0.3.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.
- data/.gitignore +3 -1
- data/.travis.yml +2 -0
- data/Gemfile +15 -9
- data/LICENSE.md +2 -6
- data/Procfile +1 -1
- data/README.md +656 -111
- data/Rakefile +89 -6
- data/bin/vcd +10 -0
- data/bin/vcd-server +8 -0
- data/config/database.yml +6 -0
- data/config/spec.example.yml +18 -0
- data/config/vayacondios.example.yml +15 -0
- data/config/vcd-server.rb +37 -0
- data/examples/configuration.rb +56 -0
- data/examples/event_stream.rb +19 -0
- data/examples/simple.rb +61 -0
- data/features/event.feature +319 -0
- data/features/events.feature +208 -0
- data/features/stash.feature +840 -0
- data/features/stashes.feature +492 -0
- data/features/step_definitions/stash_steps.rb +113 -0
- data/features/stream.feature +30 -0
- data/features/support/em.rb +14 -0
- data/features/support/env.rb +13 -0
- data/lib/vayacondios/configuration.rb +63 -0
- data/lib/vayacondios/server/api.rb +126 -0
- data/lib/vayacondios/server/api_options.rb +56 -0
- data/lib/vayacondios/server/configuration.rb +23 -0
- data/lib/vayacondios/server/driver.rb +71 -0
- data/lib/vayacondios/server/drivers/mongo.rb +126 -0
- data/lib/vayacondios/server/handlers/document_handler.rb +81 -0
- data/lib/vayacondios/server/handlers/event_handler.rb +31 -26
- data/lib/vayacondios/server/handlers/events_handler.rb +31 -0
- data/lib/vayacondios/server/handlers/stash_handler.rb +69 -0
- data/lib/vayacondios/server/handlers/stashes_handler.rb +49 -0
- data/lib/vayacondios/server/handlers/stream_handler.rb +39 -0
- data/lib/vayacondios/server/models/document.rb +87 -0
- data/lib/vayacondios/server/models/event.rb +198 -0
- data/lib/vayacondios/server/models/stash.rb +100 -0
- data/lib/vayacondios/server.rb +35 -0
- data/lib/vayacondios-server.rb +19 -13
- data/lib/vayacondios.rb +22 -0
- data/pom.xml +124 -4
- data/spec/configuration_spec.rb +41 -0
- data/spec/server/api_options_spec.rb +32 -0
- data/spec/server/api_spec.rb +279 -0
- data/spec/server/configuration_spec.rb +27 -0
- data/spec/server/drivers/mongo_spec.rb +107 -0
- data/spec/server/handlers/event_handler_spec.rb +62 -0
- data/spec/server/handlers/events_handler_spec.rb +51 -0
- data/spec/server/handlers/stash_handler_spec.rb +68 -0
- data/spec/server/handlers/stashes_handler_spec.rb +50 -0
- data/spec/server/handlers/stream_handler_spec.rb +5 -0
- data/spec/server/models/document_spec.rb +9 -0
- data/spec/server/models/event_spec.rb +185 -0
- data/spec/server/models/stash_spec.rb +95 -0
- data/spec/spec_helper.rb +23 -3
- data/spec/support/database_helper.rb +42 -0
- data/spec/support/log_helper.rb +19 -0
- data/spec/support/shared_context_for_events.rb +22 -0
- data/spec/support/shared_context_for_stashes.rb +24 -0
- data/spec/support/shared_examples_for_handlers.rb +32 -0
- data/src/main/java/com/infochimps/vayacondios/BaseClient.java +342 -0
- data/src/main/java/com/infochimps/vayacondios/HTTPClient.java +426 -0
- data/src/main/java/com/infochimps/vayacondios/VayacondiosClient.java +487 -65
- data/src/main/java/com/infochimps/vayacondios/test/IntegrationTest.java +3 -0
- data/src/test/java/com/infochimps/vayacondios/BaseClientTest.java +50 -0
- data/src/test/java/com/infochimps/vayacondios/HTTPClientIT.java +267 -0
- data/vayacondios-server.gemspec +9 -9
- metadata +127 -122
- checksums.yaml +0 -15
- data/.rspec +0 -2
- data/.yardopts +0 -10
- data/Guardfile +0 -41
- data/app/http_shim.rb +0 -71
- data/bin/vcd.sh +0 -27
- data/config/http_shim.rb +0 -43
- data/config/vayacondios.example.yaml +0 -7
- data/config/vayacondios.yaml +0 -7
- data/examples/java/ItemSetTest.java +0 -76
- data/lib/tasks/publish.rake +0 -23
- data/lib/tasks/spec.rake +0 -11
- data/lib/tasks/yard.rake +0 -2
- data/lib/vayacondios/client/config.rb +0 -7
- data/lib/vayacondios/client/configliere.rb +0 -38
- data/lib/vayacondios/client/cube_client.rb +0 -39
- data/lib/vayacondios/client/http_client.rb +0 -49
- data/lib/vayacondios/client/itemset.rb +0 -130
- data/lib/vayacondios/client/legacy_switch.rb +0 -43
- data/lib/vayacondios/client/notifier.rb +0 -123
- data/lib/vayacondios/client/zabbix_client.rb +0 -148
- data/lib/vayacondios/legacy_switch.rb +0 -43
- data/lib/vayacondios/server/errors/bad_request.rb +0 -6
- data/lib/vayacondios/server/errors/not_found.rb +0 -6
- data/lib/vayacondios/server/handlers/config_handler.rb +0 -32
- data/lib/vayacondios/server/handlers/itemset_handler.rb +0 -60
- data/lib/vayacondios/server/legacy_switch.rb +0 -43
- data/lib/vayacondios/server/model/config_document.rb +0 -89
- data/lib/vayacondios/server/model/document.rb +0 -25
- data/lib/vayacondios/server/model/event_document.rb +0 -94
- data/lib/vayacondios/server/model/itemset_document.rb +0 -126
- data/lib/vayacondios/server/rack/extract_methods.rb +0 -35
- data/lib/vayacondios/server/rack/jsonize.rb +0 -43
- data/lib/vayacondios/server/rack/params.rb +0 -50
- data/lib/vayacondios/server/rack/path.rb +0 -23
- data/lib/vayacondios/server/rack/path_validation.rb +0 -22
- data/lib/vayacondios/version.rb +0 -3
- data/lib/vayacondios-client.rb +0 -22
- data/scripts/hadoop_monitor/configurable.rb +0 -66
- data/scripts/hadoop_monitor/hadoop_attempt_scraper.rb +0 -45
- data/scripts/hadoop_monitor/hadoop_client.rb +0 -273
- data/scripts/hadoop_monitor/hadoop_monitor.rb +0 -101
- data/scripts/hadoop_monitor/hadoopable.rb +0 -65
- data/scripts/hadoop_monitor/machine_monitor.rb +0 -115
- data/scripts/s3_cataloger/buckets +0 -33
- data/scripts/s3_cataloger/foreach_bucket +0 -88
- data/scripts/s3_cataloger/parse_ls.py +0 -391
- data/spec/client/itemset_legacy_spec.rb +0 -55
- data/spec/client/itemset_spec.rb +0 -60
- data/spec/client/notifier_spec.rb +0 -120
- data/spec/server/config_spec.rb +0 -113
- data/spec/server/event_spec.rb +0 -103
- data/spec/server/itemset_legacy_spec.rb +0 -320
- data/spec/server/itemset_spec.rb +0 -317
- data/spec/server/rack/extract_methods_spec.rb +0 -60
- data/spec/server/rack/path_spec.rb +0 -36
- data/spec/server/rack/path_validation_spec.rb +0 -22
- data/spec/server/server_spec.rb +0 -20
- data/spec/support/mongo_cleaner.rb +0 -32
- data/src/main/java/ItemSetTest.java +0 -76
- data/src/main/java/com/infochimps/util/CurrentClass.java +0 -26
- data/src/main/java/com/infochimps/util/DebugUtil.java +0 -38
- data/src/main/java/com/infochimps/util/HttpHelper.java +0 -181
- data/src/main/java/com/infochimps/vayacondios/ItemSets.java +0 -373
- data/src/main/java/com/infochimps/vayacondios/LinkToVCD.java +0 -18
- data/src/main/java/com/infochimps/vayacondios/MemoryVCDShim.java +0 -84
- data/src/main/java/com/infochimps/vayacondios/Organization.java +0 -62
- data/src/main/java/com/infochimps/vayacondios/PathBuilder.java +0 -13
- data/src/main/java/com/infochimps/vayacondios/StandardVCDLink.java +0 -218
- data/src/main/java/com/infochimps/vayacondios/VCDIntegrationTest.java +0 -108
- data/src/test/java/com/infochimps/vayacondios/TestVayacondiosInMemory.java +0 -78
- data/vayacondios-client.gemspec +0 -25
@@ -1,320 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'multi_json'
|
4
|
-
|
5
|
-
require File.join(File.dirname(__FILE__), '../../', 'app/http_shim')
|
6
|
-
|
7
|
-
describe HttpShim do
|
8
|
-
include Goliath::TestHelper
|
9
|
-
|
10
|
-
let(:err) { Proc.new{ |c| fail "HTTP Request Failed #{c.response}" } }
|
11
|
-
|
12
|
-
context 'Basic requirements' do
|
13
|
-
it 'requires a topic' do
|
14
|
-
Vayacondios.force_legacy_mode(true)
|
15
|
-
with_api(HttpShim) do |api|
|
16
|
-
put_request({
|
17
|
-
:path => '/v1/infochimps/itemset/',
|
18
|
-
:body => MultiJson.dump(["foo"]),
|
19
|
-
:head => { :content_type => 'application/json' }
|
20
|
-
}, err) do |c|
|
21
|
-
c.response_header.status.should == 400
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'requires an id' do
|
27
|
-
with_api(HttpShim) do |api|
|
28
|
-
put_request({
|
29
|
-
:path => '/v1/infochimps/itemset/power',
|
30
|
-
:body => MultiJson.dump(["foo"]),
|
31
|
-
:head => { :content_type => 'application/json' }
|
32
|
-
}, err) do |c|
|
33
|
-
c.response_header.status.should == 400
|
34
|
-
end
|
35
|
-
|
36
|
-
get_mongo_db do |db|
|
37
|
-
db.collection("infochimps.power.itemset").find_one().should be_nil
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'rejects deep IDs' do
|
43
|
-
with_api(HttpShim) do |api|
|
44
|
-
put_request({
|
45
|
-
:path => '/v1/infochimps/itemset/power/level/is/invalid',
|
46
|
-
:body => MultiJson.dump(["foo"]),
|
47
|
-
:head => { :content_type => 'application/json' }
|
48
|
-
}, err) do |c|
|
49
|
-
c.response_header.status.should == 400
|
50
|
-
end
|
51
|
-
|
52
|
-
get_mongo_db do |db|
|
53
|
-
db.collection("infochimps.power.itemset").find_one({:_id => "level"}).should be_nil
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
context 'can handle GET requests' do
|
61
|
-
Vayacondios.force_legacy_mode(true)
|
62
|
-
|
63
|
-
it 'and return 404 for missing resources' do
|
64
|
-
with_api(HttpShim) do |api|
|
65
|
-
Vayacondios.force_legacy_mode(true)
|
66
|
-
|
67
|
-
get_request({:path => '/v1/infochimps/itemset/missing/resource'}, err) do |c|
|
68
|
-
c.response_header.status.should == 404
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'and return an array for valid resources' do
|
74
|
-
|
75
|
-
with_api(HttpShim) do |api|
|
76
|
-
put_request({
|
77
|
-
:path => '/v1/infochimps/itemset/power/level',
|
78
|
-
:body => MultiJson.dump(["foo", "bar"]),
|
79
|
-
:head => { :content_type => 'application/json' }
|
80
|
-
}, err)
|
81
|
-
end
|
82
|
-
with_api(HttpShim) do |api|
|
83
|
-
get_request({:path => '/v1/infochimps/itemset/power/level'}, err) do |c|
|
84
|
-
c.response_header.status.should == 200
|
85
|
-
MultiJson.load(c.response).should eql(["foo", "bar"])
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "will not handle POST requests" do
|
92
|
-
it 'fails on POST' do
|
93
|
-
with_api(HttpShim) do |api|
|
94
|
-
post_request({
|
95
|
-
:path => '/v1/infochimps/itemset/post/unsupported',
|
96
|
-
:body => MultiJson.dump({ :totally => :ignored }),
|
97
|
-
:head => { :content_type => 'application/json' }
|
98
|
-
}, err) do |c|
|
99
|
-
c.response_header.status.should eql 405
|
100
|
-
c.response_header["ALLOW"].should_not be_nil
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
context 'handles PUT requests in legacy mode' do
|
107
|
-
Vayacondios.force_legacy_mode(true)
|
108
|
-
it 'only accepts arrays' do
|
109
|
-
with_api(HttpShim) do |api|
|
110
|
-
put_request({
|
111
|
-
:path => '/v1/infochimps/itemset/power/level',
|
112
|
-
:body => MultiJson.dump({'foo' => 'bar'}),
|
113
|
-
:head => { :content_type => 'application/json' }
|
114
|
-
}, err) do |c|
|
115
|
-
c.response_header.status.should == 400 # geometrid: changed from 500
|
116
|
-
end
|
117
|
-
|
118
|
-
get_mongo_db do |db|
|
119
|
-
db.collection("infochimps.itemset").find_one({:_id => "power"}).should be_nil
|
120
|
-
end
|
121
|
-
end
|
122
|
-
with_api(HttpShim) do |api|
|
123
|
-
put_request({
|
124
|
-
:path => '/v1/infochimps/itemset/power/level',
|
125
|
-
:body => "foo",
|
126
|
-
:head => { :content_type => 'application/json' }
|
127
|
-
}, err) do |c|
|
128
|
-
c.response_header.status.should == 400
|
129
|
-
end
|
130
|
-
|
131
|
-
get_mongo_db do |db|
|
132
|
-
db.collection("infochimps.itemset").find_one({:_id => "power"}).should be_nil
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
it "stores the array when the resource doesn't exist" do
|
137
|
-
with_api(HttpShim) do |api|
|
138
|
-
put_request({
|
139
|
-
:path => '/v1/infochimps/itemset/power/level',
|
140
|
-
:body => MultiJson.dump(["foo", "bar"]),
|
141
|
-
:head => { :content_type => 'application/json' }
|
142
|
-
}, err) do |c|
|
143
|
-
c.response_header.status.should == 200 # TODO Make this 201 Created
|
144
|
-
c.response.should eql ""
|
145
|
-
end
|
146
|
-
|
147
|
-
get_mongo_db do |db|
|
148
|
-
db.collection("infochimps.power.itemset").find_one({:_id => "level"})["d"].should eql ["foo", "bar"]
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
it "clobbers the previous array when the resource does exist" do
|
153
|
-
with_api(HttpShim) do |api|
|
154
|
-
put_request({
|
155
|
-
:path => '/v1/infochimps/itemset/power/level',
|
156
|
-
:body => MultiJson.dump(["chimpanzee", "bonobo"]),
|
157
|
-
:head => { :content_type => 'application/json' }
|
158
|
-
}, err) do |c|
|
159
|
-
c.response_header.status.should == 200 # TODO Make this 204 No content
|
160
|
-
c.response.should eql ""
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
# Verify the first was created
|
165
|
-
get_mongo_db do |db|
|
166
|
-
db.collection("infochimps.power.itemset").find_one({:_id => "level"})["d"].should eql ["chimpanzee", "bonobo"]
|
167
|
-
end
|
168
|
-
|
169
|
-
with_api(HttpShim) do |api|
|
170
|
-
put_request({
|
171
|
-
:path => '/v1/infochimps/itemset/power/level',
|
172
|
-
:body => MultiJson.dump(["foo", "bar"]),
|
173
|
-
:head => { :content_type => 'application/json' }
|
174
|
-
}, err) do |c|
|
175
|
-
c.response_header.status.should == 200
|
176
|
-
c.response.should eql ""
|
177
|
-
end
|
178
|
-
|
179
|
-
# Verify the first was clobbered
|
180
|
-
get_mongo_db do |db|
|
181
|
-
db.collection("infochimps.power.itemset").find_one({:_id => "level"})["d"].should eql ["foo", "bar"]
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
context "handles PATCH requests in legacy mode" do
|
188
|
-
Vayacondios.force_legacy_mode(true)
|
189
|
-
it 'creates a missing resource' do
|
190
|
-
with_api(HttpShim) do |api|
|
191
|
-
put_request({
|
192
|
-
:path => '/v1/infochimps/itemset/power/level',
|
193
|
-
:head => ({'X-Method' => 'PATCH', :content_type => 'application/json' }),
|
194
|
-
:body => MultiJson.dump(["bar"])
|
195
|
-
}, err) do |c|
|
196
|
-
c.response_header.status.should eql 200 # TODO Make this 201 Created
|
197
|
-
c.response.should eql ""
|
198
|
-
end
|
199
|
-
|
200
|
-
# Verify the resource was created
|
201
|
-
get_mongo_db do |db|
|
202
|
-
db.collection("infochimps.power.itemset").find_one({:_id => "level"})["d"].should eql ["bar"]
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
it 'merges with PATCH' do
|
208
|
-
with_api(HttpShim) do |api|
|
209
|
-
put_request({
|
210
|
-
:path => '/v1/infochimps/itemset/merge/test',
|
211
|
-
:body => MultiJson.dump(["foo"]),
|
212
|
-
:head => { :content_type => 'application/json' }
|
213
|
-
}, err)
|
214
|
-
end
|
215
|
-
with_api(HttpShim) do |api|
|
216
|
-
put_request({
|
217
|
-
:path => '/v1/infochimps/itemset/merge/test',
|
218
|
-
:head => ({'X-Method' => 'PATCH', :content_type => 'application/json' }),
|
219
|
-
:body => MultiJson.dump(["bar"])
|
220
|
-
}, err)
|
221
|
-
end
|
222
|
-
with_api(HttpShim) do |api|
|
223
|
-
get_request({:path => '/v1/infochimps/itemset/merge/test'}, err) do |c|
|
224
|
-
c.response_header.status.should == 200
|
225
|
-
MultiJson.load(c.response).should eql(["foo", "bar"])
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
context "will handle DELETE requests in legacy mode" do
|
232
|
-
Vayacondios.force_legacy_mode(true)
|
233
|
-
it 'will not delete a missing resource' do
|
234
|
-
with_api(HttpShim) do |api|
|
235
|
-
delete_request({
|
236
|
-
:path => '/v1/infochimps/itemset/merge/test',
|
237
|
-
:body => MultiJson.dump(["bar"]),
|
238
|
-
:head => { :content_type => 'application/json' }
|
239
|
-
}, err) do |c|
|
240
|
-
c.response_header.status.should == 404
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
it "will be ok to delete items that don't exist" do
|
246
|
-
with_api(HttpShim) do |api|
|
247
|
-
put_request({
|
248
|
-
:path => '/v1/infochimps/itemset/power/level',
|
249
|
-
:body => MultiJson.dump(["foo"]),
|
250
|
-
:head => { :content_type => 'application/json' }
|
251
|
-
}, err) do |c|
|
252
|
-
c.response_header.status.should == 200 # TODO Make this 201 Created
|
253
|
-
end
|
254
|
-
end
|
255
|
-
with_api(HttpShim) do |api|
|
256
|
-
delete_request({
|
257
|
-
:path => '/v1/infochimps/itemset/power/level',
|
258
|
-
:body => MultiJson.dump(["bar"]),
|
259
|
-
:head => { :content_type => 'application/json' }
|
260
|
-
}, err) do |c|
|
261
|
-
c.response_header.status.should == 200 # TODO Make this 204 No content
|
262
|
-
end
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
it "will delete items that do exist" do
|
267
|
-
with_api(HttpShim) do |api|
|
268
|
-
put_request({
|
269
|
-
:path => '/v1/infochimps/itemset/power/level',
|
270
|
-
:body => MultiJson.dump(["foo", "bar"]),
|
271
|
-
:head => { :content_type => 'application/json' }
|
272
|
-
}, err) do |c|
|
273
|
-
c.response_header.status.should == 200 # TODO Makes this 201 Created
|
274
|
-
end
|
275
|
-
end
|
276
|
-
with_api(HttpShim) do |api|
|
277
|
-
delete_request({
|
278
|
-
:path => '/v1/infochimps/itemset/power/level',
|
279
|
-
:body => MultiJson.dump(["bar"]),
|
280
|
-
:head => { :content_type => 'application/json' }
|
281
|
-
}, err) do |c|
|
282
|
-
c.response_header.status.should == 200 # TODO Make this 204 No content
|
283
|
-
end
|
284
|
-
end
|
285
|
-
with_api(HttpShim) do |api|
|
286
|
-
get_request({:path => '/v1/infochimps/itemset/power/level'}, err) do |c|
|
287
|
-
c.response_header.status.should == 200
|
288
|
-
MultiJson.load(c.response).should eql(["foo"])
|
289
|
-
end
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
it "leaves behind an empty array if everything is deleted" do
|
294
|
-
with_api(HttpShim) do |api|
|
295
|
-
put_request({
|
296
|
-
:path => '/v1/infochimps/itemset/power/level',
|
297
|
-
:body => MultiJson.dump(["foo", "bar"]),
|
298
|
-
:head => { :content_type => 'application/json' }
|
299
|
-
}, err) do |c|
|
300
|
-
c.response_header.status.should == 200 # TODO Makes this 201 Created
|
301
|
-
end
|
302
|
-
end
|
303
|
-
with_api(HttpShim) do |api|
|
304
|
-
delete_request({
|
305
|
-
:path => '/v1/infochimps/itemset/power/level',
|
306
|
-
:body => MultiJson.dump(["foo", "bar"]),
|
307
|
-
:head => { :content_type => 'application/json' }
|
308
|
-
}, err) do |c|
|
309
|
-
c.response_header.status.should == 200 # TODO Make this 204 No content
|
310
|
-
end
|
311
|
-
end
|
312
|
-
with_api(HttpShim) do |api|
|
313
|
-
get_request({:path => '/v1/infochimps/itemset/power/level'}, err) do |c|
|
314
|
-
c.response_header.status.should == 200
|
315
|
-
MultiJson.load(c.response).should eql([])
|
316
|
-
end
|
317
|
-
end
|
318
|
-
end
|
319
|
-
end
|
320
|
-
end
|
data/spec/server/itemset_spec.rb
DELETED
@@ -1,317 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'multi_json'
|
4
|
-
|
5
|
-
require File.join(File.dirname(__FILE__), '../../', 'app/http_shim')
|
6
|
-
|
7
|
-
describe HttpShim do
|
8
|
-
include Goliath::TestHelper
|
9
|
-
|
10
|
-
let(:err) { Proc.new{ |c| fail "HTTP Request Failed #{c.response}" } }
|
11
|
-
|
12
|
-
context 'Basic requirements' do
|
13
|
-
it 'requires a topic' do
|
14
|
-
with_api(HttpShim) do |api|
|
15
|
-
put_request({
|
16
|
-
:path => '/v1/infochimps/itemset/',
|
17
|
-
:body => MultiJson.dump({:contents =>["foo"]}),
|
18
|
-
:head => { :content_type => 'application/json' }
|
19
|
-
}, err) do |c|
|
20
|
-
c.response_header.status.should == 400
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'requires an id' do
|
26
|
-
with_api(HttpShim) do |api|
|
27
|
-
put_request({
|
28
|
-
:path => '/v1/infochimps/itemset/power',
|
29
|
-
:body => MultiJson.dump({:contents =>["foo"]}),
|
30
|
-
:head => { :content_type => 'application/json' }
|
31
|
-
}, err) do |c|
|
32
|
-
c.response_header.status.should == 400
|
33
|
-
end
|
34
|
-
|
35
|
-
get_mongo_db do |db|
|
36
|
-
db.collection("infochimps.power.itemset").find_one().should be_nil
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'rejects deep IDs' do
|
42
|
-
with_api(HttpShim) do |api|
|
43
|
-
put_request({
|
44
|
-
:path => '/v1/infochimps/itemset/power/level/is/invalid',
|
45
|
-
:body => MultiJson.dump({:contents =>["foo"]}),
|
46
|
-
:head => { :content_type => 'application/json' }
|
47
|
-
}, err) do |c|
|
48
|
-
c.response_header.status.should == 400
|
49
|
-
end
|
50
|
-
|
51
|
-
get_mongo_db do |db|
|
52
|
-
db.collection("infochimps.power.itemset").find_one({:_id => "level"}).should be_nil
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'handles PUT requests' do
|
59
|
-
it 'only accepts hashes' do
|
60
|
-
# note: due to unknown class variable handling by rspec,
|
61
|
-
# force_legacy_mode must be set inside the it block to
|
62
|
-
# get all tests to pass at once
|
63
|
-
Vayacondios.force_legacy_mode(false)
|
64
|
-
with_api(HttpShim) do |api|
|
65
|
-
put_request({
|
66
|
-
:path => '/v1/infochimps/itemset/power/level',
|
67
|
-
:body => MultiJson.dump(['foo', 'bar']),
|
68
|
-
:head => { :content_type => 'application/json' }
|
69
|
-
}, err) do |c|
|
70
|
-
c.response_header.status.should == 400 # geometrid: changed from 500
|
71
|
-
end
|
72
|
-
|
73
|
-
get_mongo_db do |db|
|
74
|
-
db.collection("infochimps.itemset").find_one({:_id => "power"}).should be_nil
|
75
|
-
end
|
76
|
-
end
|
77
|
-
with_api(HttpShim) do |api|
|
78
|
-
put_request({
|
79
|
-
:path => '/v1/infochimps/itemset/power/level',
|
80
|
-
:body => "foo",
|
81
|
-
:head => { :content_type => 'application/json' }
|
82
|
-
}, err) do |c|
|
83
|
-
c.response_header.status.should == 400
|
84
|
-
end
|
85
|
-
|
86
|
-
get_mongo_db do |db|
|
87
|
-
db.collection("infochimps.itemset").find_one({:_id => "power"}).should be_nil
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
it "stores the array when the resource doesn't exist" do
|
93
|
-
with_api(HttpShim) do |api|
|
94
|
-
put_request({
|
95
|
-
:path => '/v1/infochimps/itemset/power/level',
|
96
|
-
:body => MultiJson.dump({:contents =>["foo", "bar"]}),
|
97
|
-
:head => { :content_type => 'application/json' }
|
98
|
-
}, err) do |c|
|
99
|
-
c.response_header.status.should == 200 # TODO Make this 201 Created
|
100
|
-
c.response.should eql ""
|
101
|
-
end
|
102
|
-
|
103
|
-
get_mongo_db do |db|
|
104
|
-
db.collection("infochimps.power.itemset").find_one({:_id => "level"})["d"].should eql ["foo", "bar"]
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
it "clobbers the previous array when the resource does exist" do
|
110
|
-
with_api(HttpShim) do |api|
|
111
|
-
put_request({
|
112
|
-
:path => '/v1/infochimps/itemset/power/level',
|
113
|
-
:body => MultiJson.dump({:contents =>["chimpanzee", "bonobo"]}),
|
114
|
-
:head => { :content_type => 'application/json' }
|
115
|
-
}, err) do |c|
|
116
|
-
c.response_header.status.should == 200 # TODO Make this 204 No content
|
117
|
-
c.response.should eql ""
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# Verify the first was created
|
122
|
-
get_mongo_db do |db|
|
123
|
-
db.collection("infochimps.power.itemset").find_one({:_id => "level"})["d"].should eql ["chimpanzee", "bonobo"]
|
124
|
-
end
|
125
|
-
|
126
|
-
with_api(HttpShim) do |api|
|
127
|
-
put_request({
|
128
|
-
:path => '/v1/infochimps/itemset/power/level',
|
129
|
-
:body => MultiJson.dump({:contents =>["foo", "bar"]}),
|
130
|
-
:head => { :content_type => 'application/json' }
|
131
|
-
}, err) do |c|
|
132
|
-
c.response_header.status.should == 200
|
133
|
-
c.response.should eql ""
|
134
|
-
end
|
135
|
-
|
136
|
-
# Verify the first was clobbered
|
137
|
-
get_mongo_db do |db|
|
138
|
-
db.collection("infochimps.power.itemset").find_one({:_id => "level"})["d"].should eql ["foo", "bar"]
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
context 'can handle GET requests' do
|
145
|
-
it 'and return 404 for missing resources' do
|
146
|
-
with_api(HttpShim) do |api|
|
147
|
-
get_request({:path => '/v1/infochimps/itemset/missing/resource'}, err) do |c|
|
148
|
-
c.response_header.status.should == 404
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'and return an array for valid resources' do
|
154
|
-
with_api(HttpShim) do |api|
|
155
|
-
put_request({
|
156
|
-
:path => '/v1/infochimps/itemset/power/level',
|
157
|
-
:body => MultiJson.dump({:contents =>["foo", "bar"]}),
|
158
|
-
:head => { :content_type => 'application/json' }
|
159
|
-
}, err)
|
160
|
-
end
|
161
|
-
with_api(HttpShim) do |api|
|
162
|
-
get_request({:path => '/v1/infochimps/itemset/power/level'}, err) do |c|
|
163
|
-
c.response_header.status.should == 200
|
164
|
-
MultiJson.load(c.response).should eql({"contents" => ["foo", "bar"]})
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context "will not handle POST requests" do
|
171
|
-
it 'fails on POST' do
|
172
|
-
with_api(HttpShim) do |api|
|
173
|
-
post_request({
|
174
|
-
:path => '/v1/infochimps/itemset/post/unsupported',
|
175
|
-
:body => MultiJson.dump({ :totally => :ignored }),
|
176
|
-
:head => { :content_type => 'application/json' }
|
177
|
-
}, err) do |c|
|
178
|
-
c.response_header.status.should eql 405
|
179
|
-
c.response_header["ALLOW"].should_not be_nil
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
context "handles PATCH requests" do
|
186
|
-
it 'creates a missing resource' do
|
187
|
-
with_api(HttpShim) do |api|
|
188
|
-
put_request({
|
189
|
-
:path => '/v1/infochimps/itemset/power/level',
|
190
|
-
:head => ({'X-Method' => 'PATCH', :content_type => 'application/json' }),
|
191
|
-
:body => MultiJson.dump({:contents =>["bar"]})
|
192
|
-
}, err) do |c|
|
193
|
-
c.response_header.status.should eql 200 # TODO Make this 201 Created
|
194
|
-
c.response.should eql ""
|
195
|
-
end
|
196
|
-
|
197
|
-
# Verify the resource was created
|
198
|
-
get_mongo_db do |db|
|
199
|
-
db.collection("infochimps.power.itemset").find_one({:_id => "level"})["d"].should eql ["bar"]
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
it 'merges with PATCH' do
|
205
|
-
with_api(HttpShim) do |api|
|
206
|
-
put_request({
|
207
|
-
:path => '/v1/infochimps/itemset/merge/test',
|
208
|
-
:body => MultiJson.dump({:contents =>["foo"]}),
|
209
|
-
:head => { :content_type => 'application/json' }
|
210
|
-
}, err)
|
211
|
-
end
|
212
|
-
with_api(HttpShim) do |api|
|
213
|
-
put_request({
|
214
|
-
:path => '/v1/infochimps/itemset/merge/test',
|
215
|
-
:head => ({'X-Method' => 'PATCH', :content_type => 'application/json' }),
|
216
|
-
:body => MultiJson.dump({:contents =>["bar"]})
|
217
|
-
}, err)
|
218
|
-
end
|
219
|
-
with_api(HttpShim) do |api|
|
220
|
-
get_request({:path => '/v1/infochimps/itemset/merge/test'}, err) do |c|
|
221
|
-
c.response_header.status.should == 200
|
222
|
-
MultiJson.load(c.response).should eql({"contents" => ["foo", "bar"]})
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
context "will handle DELETE requests" do
|
229
|
-
Vayacondios.force_legacy_mode(false)
|
230
|
-
it 'will not delete a missing resource' do
|
231
|
-
with_api(HttpShim) do |api|
|
232
|
-
delete_request({
|
233
|
-
:path => '/v1/infochimps/itemset/merge/test',
|
234
|
-
:body => MultiJson.dump({:contents =>["bar"]}),
|
235
|
-
:head => { :content_type => 'application/json' }
|
236
|
-
}, err) do |c|
|
237
|
-
c.response_header.status.should == 404
|
238
|
-
end
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
it "will be ok to delete items that don't exist" do
|
243
|
-
with_api(HttpShim) do |api|
|
244
|
-
put_request({
|
245
|
-
:path => '/v1/infochimps/itemset/power/level',
|
246
|
-
:body => MultiJson.dump({:contents =>["foo"]}),
|
247
|
-
:head => { :content_type => 'application/json' }
|
248
|
-
}, err) do |c|
|
249
|
-
c.response_header.status.should == 200 # TODO Make this 201 Created
|
250
|
-
end
|
251
|
-
end
|
252
|
-
with_api(HttpShim) do |api|
|
253
|
-
delete_request({
|
254
|
-
:path => '/v1/infochimps/itemset/power/level',
|
255
|
-
:body => MultiJson.dump({:contents =>["bar"]}),
|
256
|
-
:head => { :content_type => 'application/json' }
|
257
|
-
}, err) do |c|
|
258
|
-
c.response_header.status.should == 200 # TODO Make this 204 No content
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
it "will delete items that do exist" do
|
264
|
-
with_api(HttpShim) do |api|
|
265
|
-
put_request({
|
266
|
-
:path => '/v1/infochimps/itemset/power/level',
|
267
|
-
:body => MultiJson.dump({:contents =>["foo", "bar"]}),
|
268
|
-
:head => { :content_type => 'application/json' }
|
269
|
-
}, err) do |c|
|
270
|
-
c.response_header.status.should == 200 # TODO Makes this 201 Created
|
271
|
-
end
|
272
|
-
end
|
273
|
-
with_api(HttpShim) do |api|
|
274
|
-
delete_request({
|
275
|
-
:path => '/v1/infochimps/itemset/power/level',
|
276
|
-
:body => MultiJson.dump({:contents =>["bar"]}),
|
277
|
-
:head => { :content_type => 'application/json' }
|
278
|
-
}, err) do |c|
|
279
|
-
c.response_header.status.should == 200 # TODO Make this 204 No content
|
280
|
-
end
|
281
|
-
end
|
282
|
-
with_api(HttpShim) do |api|
|
283
|
-
get_request({:path => '/v1/infochimps/itemset/power/level'}, err) do |c|
|
284
|
-
c.response_header.status.should == 200
|
285
|
-
MultiJson.load(c.response).should eql({"contents" => ["foo"]})
|
286
|
-
end
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
it "leaves behind an empty array if everything is deleted" do
|
291
|
-
with_api(HttpShim) do |api|
|
292
|
-
put_request({
|
293
|
-
:path => '/v1/infochimps/itemset/power/level',
|
294
|
-
:body => MultiJson.dump({:contents =>["foo", "bar"]}),
|
295
|
-
:head => { :content_type => 'application/json' }
|
296
|
-
}, err) do |c|
|
297
|
-
c.response_header.status.should == 200 # TODO Makes this 201 Created
|
298
|
-
end
|
299
|
-
end
|
300
|
-
with_api(HttpShim) do |api|
|
301
|
-
delete_request({
|
302
|
-
:path => '/v1/infochimps/itemset/power/level',
|
303
|
-
:body => MultiJson.dump({:contents =>["foo", "bar"]}),
|
304
|
-
:head => { :content_type => 'application/json' }
|
305
|
-
}, err) do |c|
|
306
|
-
c.response_header.status.should == 200 # TODO Make this 204 No content
|
307
|
-
end
|
308
|
-
end
|
309
|
-
with_api(HttpShim) do |api|
|
310
|
-
get_request({:path => '/v1/infochimps/itemset/power/level'}, err) do |c|
|
311
|
-
c.response_header.status.should == 200
|
312
|
-
MultiJson.load(c.response).should eql({"contents" => []})
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
end
|
317
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'vayacondios/server/rack/extract_methods'
|
3
|
-
|
4
|
-
describe Vayacondios::Rack::ExtractMethods do
|
5
|
-
let(:env){ { 'CONTENT_TYPE' => 'application/x-www-form-urlencoded; charset=utf-8' } }
|
6
|
-
let(:app){ mock('app').as_null_object }
|
7
|
-
subject { described_class.new(app) }
|
8
|
-
|
9
|
-
it 'adds a key in env for :vayacondios_method' do
|
10
|
-
app.should_receive(:call).with do |app_env|
|
11
|
-
app_env.keys.should include(:vayacondios_method)
|
12
|
-
end
|
13
|
-
subject.call(env)
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'PUT' do
|
17
|
-
context 'without http_x_method' do
|
18
|
-
it 'correctly extracts :update' do
|
19
|
-
env.merge!('REQUEST_METHOD' => 'PUT')
|
20
|
-
subject.extract_method(env).should == :update
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'with http_x_method' do
|
25
|
-
it 'correctly extracts :patch' do
|
26
|
-
env.merge!('REQUEST_METHOD' => 'PUT', 'HTTP_X_METHOD' => 'PATCH')
|
27
|
-
subject.extract_method(env).should == :patch
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'GET' do
|
33
|
-
it 'correctly extracts :show' do
|
34
|
-
env.merge!('REQUEST_METHOD' => 'GET')
|
35
|
-
subject.extract_method(env).should == :show
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'POST' do
|
40
|
-
it 'correctly extracts :create' do
|
41
|
-
env.merge!('REQUEST_METHOD' => 'POST')
|
42
|
-
subject.extract_method(env).should == :create
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'PATCH' do
|
48
|
-
it 'correctly extracts :patch' do
|
49
|
-
env.merge!('REQUEST_METHOD' => 'PATCH')
|
50
|
-
subject.extract_method(env).should == :patch
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'DELETE' do
|
55
|
-
it 'correctly extracts :delete' do
|
56
|
-
env.merge!('REQUEST_METHOD' => 'DELETE')
|
57
|
-
subject.extract_method(env).should == :delete
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|