crohr-restfully 0.1.1 → 0.2.1

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.
@@ -0,0 +1,489 @@
1
+ {
2
+ "lille": {
3
+ "name": "Lille",
4
+ "latitude": 50.65,
5
+ "location": "Lille, France",
6
+ "security_contact": null,
7
+ "uid": "lille",
8
+ "type": "site",
9
+ "user_support_contact": null,
10
+ "version": "747d2af24c5f3c2578a96626e0b00413c8484f04",
11
+ "links": [
12
+ {
13
+ "href": "\/grid5000\/sites\/lille",
14
+ "rel": "self"
15
+ },
16
+ {
17
+ "href": "\/grid5000\/sites\/lille\/versions\/747d2af24c5f3c2578a96626e0b00413c8484f04",
18
+ "title": "version",
19
+ "rel": "member"
20
+ },
21
+ {
22
+ "href": "\/grid5000\/sites\/lille\/versions",
23
+ "title": "versions",
24
+ "rel": "collection"
25
+ },
26
+ {
27
+ "href": "\/grid5000\/sites\/lille\/clusters",
28
+ "resolvable": true,
29
+ "title": "clusters",
30
+ "rel": "collection",
31
+ "resolved": false
32
+ },
33
+ {
34
+ "href": "\/grid5000\/sites\/lille\/environments",
35
+ "resolvable": true,
36
+ "title": "environments",
37
+ "rel": "collection",
38
+ "resolved": false
39
+ },
40
+ {
41
+ "href": "\/grid5000",
42
+ "rel": "parent"
43
+ },
44
+ {
45
+ "href": "\/grid5000\/sites\/lille\/status",
46
+ "title": "status",
47
+ "rel": "collection"
48
+ }
49
+ ],
50
+ "description": "",
51
+ "longitude": 3.0833,
52
+ "email_contact": null,
53
+ "web": null,
54
+ "sys_admin_contact": null
55
+ },
56
+ "grenoble": {
57
+ "name": "Grenoble",
58
+ "latitude": 45.1833,
59
+ "location": "Grenoble, France",
60
+ "security_contact": null,
61
+ "uid": "grenoble",
62
+ "type": "site",
63
+ "user_support_contact": null,
64
+ "version": "747d2af24c5f3c2578a96626e0b00413c8484f04",
65
+ "links": [
66
+ {
67
+ "href": "\/grid5000\/sites\/grenoble",
68
+ "rel": "self"
69
+ },
70
+ {
71
+ "href": "\/grid5000\/sites\/grenoble\/versions\/747d2af24c5f3c2578a96626e0b00413c8484f04",
72
+ "title": "version",
73
+ "rel": "member"
74
+ },
75
+ {
76
+ "href": "\/grid5000\/sites\/grenoble\/versions",
77
+ "title": "versions",
78
+ "rel": "collection"
79
+ },
80
+ {
81
+ "href": "\/grid5000\/sites\/grenoble\/clusters",
82
+ "resolvable": true,
83
+ "title": "clusters",
84
+ "rel": "collection",
85
+ "resolved": false
86
+ },
87
+ {
88
+ "href": "\/grid5000\/sites\/grenoble\/environments",
89
+ "resolvable": true,
90
+ "title": "environments",
91
+ "rel": "collection",
92
+ "resolved": false
93
+ },
94
+ {
95
+ "href": "\/grid5000",
96
+ "rel": "parent"
97
+ },
98
+ {
99
+ "href": "\/grid5000\/sites\/grenoble\/status",
100
+ "title": "status",
101
+ "rel": "collection"
102
+ }
103
+ ],
104
+ "description": "",
105
+ "longitude": 5.7167,
106
+ "email_contact": null,
107
+ "web": null,
108
+ "sys_admin_contact": null
109
+ },
110
+ "toulouse": {
111
+ "name": "Toulouse",
112
+ "latitude": 43.6167,
113
+ "location": "Toulouse, France",
114
+ "security_contact": null,
115
+ "uid": "toulouse",
116
+ "type": "site",
117
+ "user_support_contact": null,
118
+ "version": "747d2af24c5f3c2578a96626e0b00413c8484f04",
119
+ "links": [
120
+ {
121
+ "href": "\/grid5000\/sites\/toulouse",
122
+ "rel": "self"
123
+ },
124
+ {
125
+ "href": "\/grid5000\/sites\/toulouse\/versions\/747d2af24c5f3c2578a96626e0b00413c8484f04",
126
+ "title": "version",
127
+ "rel": "member"
128
+ },
129
+ {
130
+ "href": "\/grid5000\/sites\/toulouse\/versions",
131
+ "title": "versions",
132
+ "rel": "collection"
133
+ },
134
+ {
135
+ "href": "\/grid5000\/sites\/toulouse\/clusters",
136
+ "resolvable": true,
137
+ "title": "clusters",
138
+ "rel": "collection",
139
+ "resolved": false
140
+ },
141
+ {
142
+ "href": "\/grid5000\/sites\/toulouse\/environments",
143
+ "resolvable": true,
144
+ "title": "environments",
145
+ "rel": "collection",
146
+ "resolved": false
147
+ },
148
+ {
149
+ "href": "\/grid5000",
150
+ "rel": "parent"
151
+ },
152
+ {
153
+ "href": "\/grid5000\/sites\/toulouse\/status",
154
+ "title": "status",
155
+ "rel": "collection"
156
+ }
157
+ ],
158
+ "description": "",
159
+ "longitude": 1.4333,
160
+ "email_contact": null,
161
+ "web": null,
162
+ "sys_admin_contact": null
163
+ },
164
+ "sophia": {
165
+ "name": "Sophia-Antipolis",
166
+ "latitude": 43.6161,
167
+ "location": "Sophia-Antipolis, France",
168
+ "security_contact": "sophia-staff@lists.grid5000.fr",
169
+ "uid": "sophia",
170
+ "type": "site",
171
+ "user_support_contact": "sophia-staff@lists.grid5000.fr",
172
+ "version": "747d2af24c5f3c2578a96626e0b00413c8484f04",
173
+ "links": [
174
+ {
175
+ "href": "\/grid5000\/sites\/sophia",
176
+ "rel": "self"
177
+ },
178
+ {
179
+ "href": "\/grid5000\/sites\/sophia\/versions\/747d2af24c5f3c2578a96626e0b00413c8484f04",
180
+ "title": "version",
181
+ "rel": "member"
182
+ },
183
+ {
184
+ "href": "\/grid5000\/sites\/sophia\/versions",
185
+ "title": "versions",
186
+ "rel": "collection"
187
+ },
188
+ {
189
+ "href": "\/grid5000\/sites\/sophia\/clusters",
190
+ "resolvable": true,
191
+ "title": "clusters",
192
+ "rel": "collection",
193
+ "resolved": false
194
+ },
195
+ {
196
+ "href": "\/grid5000\/sites\/sophia\/environments",
197
+ "resolvable": true,
198
+ "title": "environments",
199
+ "rel": "collection",
200
+ "resolved": false
201
+ },
202
+ {
203
+ "href": "\/grid5000",
204
+ "rel": "parent"
205
+ },
206
+ {
207
+ "href": "\/grid5000\/sites\/sophia\/status",
208
+ "title": "status",
209
+ "rel": "collection"
210
+ }
211
+ ],
212
+ "description": "",
213
+ "longitude": 7.0678,
214
+ "compilation_server": true,
215
+ "email_contact": "sophia-staff@lists.grid5000.fr",
216
+ "web": null,
217
+ "sys_admin_contact": "sophia-staff@lists.grid5000.fr"
218
+ },
219
+ "rennes": {
220
+ "name": "Rennes",
221
+ "latitude": 48.1,
222
+ "location": "Rennes, France",
223
+ "security_contact": "rennes-staff@lists.grid5000.fr",
224
+ "uid": "rennes",
225
+ "type": "site",
226
+ "user_support_contact": "rennes-staff@lists.grid5000.fr",
227
+ "version": "747d2af24c5f3c2578a96626e0b00413c8484f04",
228
+ "links": [
229
+ {
230
+ "href": "\/grid5000\/sites\/rennes",
231
+ "rel": "self"
232
+ },
233
+ {
234
+ "href": "\/grid5000\/sites\/rennes\/versions\/747d2af24c5f3c2578a96626e0b00413c8484f04",
235
+ "title": "version",
236
+ "rel": "member"
237
+ },
238
+ {
239
+ "href": "\/grid5000\/sites\/rennes\/versions",
240
+ "title": "versions",
241
+ "rel": "collection"
242
+ },
243
+ {
244
+ "href": "\/grid5000\/sites\/rennes\/clusters",
245
+ "resolvable": true,
246
+ "title": "clusters",
247
+ "rel": "collection",
248
+ "resolved": false
249
+ },
250
+ {
251
+ "href": "\/grid5000\/sites\/rennes\/environments",
252
+ "resolvable": true,
253
+ "title": "environments",
254
+ "rel": "collection",
255
+ "resolved": false
256
+ },
257
+ {
258
+ "href": "\/grid5000",
259
+ "rel": "parent"
260
+ },
261
+ {
262
+ "href": "\/grid5000\/sites\/rennes\/status",
263
+ "title": "status",
264
+ "rel": "collection"
265
+ }
266
+ ],
267
+ "description": "",
268
+ "longitude": -1.6667,
269
+ "compilation_server": false,
270
+ "email_contact": "rennes-staff@lists.grid5000.fr",
271
+ "web": "http:\/\/www.irisa.fr",
272
+ "sys_admin_contact": "rennes-staff@lists.grid5000.fr"
273
+ },
274
+ "lyon": {
275
+ "name": "Lyon",
276
+ "latitude": 45.7667,
277
+ "location": "Lyon, France",
278
+ "security_contact": null,
279
+ "uid": "lyon",
280
+ "type": "site",
281
+ "user_support_contact": null,
282
+ "version": "747d2af24c5f3c2578a96626e0b00413c8484f04",
283
+ "links": [
284
+ {
285
+ "href": "\/grid5000\/sites\/lyon",
286
+ "rel": "self"
287
+ },
288
+ {
289
+ "href": "\/grid5000\/sites\/lyon\/versions\/747d2af24c5f3c2578a96626e0b00413c8484f04",
290
+ "title": "version",
291
+ "rel": "member"
292
+ },
293
+ {
294
+ "href": "\/grid5000\/sites\/lyon\/versions",
295
+ "title": "versions",
296
+ "rel": "collection"
297
+ },
298
+ {
299
+ "href": "\/grid5000\/sites\/lyon\/clusters",
300
+ "resolvable": true,
301
+ "title": "clusters",
302
+ "rel": "collection",
303
+ "resolved": false
304
+ },
305
+ {
306
+ "href": "\/grid5000\/sites\/lyon\/environments",
307
+ "resolvable": true,
308
+ "title": "environments",
309
+ "rel": "collection",
310
+ "resolved": false
311
+ },
312
+ {
313
+ "href": "\/grid5000",
314
+ "rel": "parent"
315
+ },
316
+ {
317
+ "href": "\/grid5000\/sites\/lyon\/status",
318
+ "title": "status",
319
+ "rel": "collection"
320
+ }
321
+ ],
322
+ "description": "",
323
+ "longitude": 4.8333,
324
+ "email_contact": null,
325
+ "web": null,
326
+ "sys_admin_contact": null
327
+ },
328
+ "nancy": {
329
+ "name": "Nancy",
330
+ "latitude": 48.7,
331
+ "location": "Nancy, France",
332
+ "security_contact": null,
333
+ "uid": "nancy",
334
+ "type": "site",
335
+ "user_support_contact": null,
336
+ "version": "747d2af24c5f3c2578a96626e0b00413c8484f04",
337
+ "links": [
338
+ {
339
+ "href": "\/grid5000\/sites\/nancy",
340
+ "rel": "self"
341
+ },
342
+ {
343
+ "href": "\/grid5000\/sites\/nancy\/versions\/747d2af24c5f3c2578a96626e0b00413c8484f04",
344
+ "title": "version",
345
+ "rel": "member"
346
+ },
347
+ {
348
+ "href": "\/grid5000\/sites\/nancy\/versions",
349
+ "title": "versions",
350
+ "rel": "collection"
351
+ },
352
+ {
353
+ "href": "\/grid5000\/sites\/nancy\/clusters",
354
+ "resolvable": true,
355
+ "title": "clusters",
356
+ "rel": "collection",
357
+ "resolved": false
358
+ },
359
+ {
360
+ "href": "\/grid5000\/sites\/nancy\/environments",
361
+ "resolvable": true,
362
+ "title": "environments",
363
+ "rel": "collection",
364
+ "resolved": false
365
+ },
366
+ {
367
+ "href": "\/grid5000",
368
+ "rel": "parent"
369
+ },
370
+ {
371
+ "href": "\/grid5000\/sites\/nancy\/status",
372
+ "title": "status",
373
+ "rel": "collection"
374
+ }
375
+ ],
376
+ "description": "",
377
+ "longitude": 6.2,
378
+ "web": null,
379
+ "sys_admin_contact": null
380
+ },
381
+ "bordeaux": {
382
+ "name": "Bordeaux",
383
+ "latitude": 44.833333,
384
+ "location": "Bordeaux, France",
385
+ "security_contact": "bordeaux-staff@lists.grid5000.fr",
386
+ "uid": "bordeaux",
387
+ "type": "site",
388
+ "user_support_contact": "bordeaux-staff@lists.grid5000.fr",
389
+ "version": "747d2af24c5f3c2578a96626e0b00413c8484f04",
390
+ "links": [
391
+ {
392
+ "href": "\/grid5000\/sites\/bordeaux",
393
+ "rel": "self"
394
+ },
395
+ {
396
+ "href": "\/grid5000\/sites\/bordeaux\/versions\/747d2af24c5f3c2578a96626e0b00413c8484f04",
397
+ "title": "version",
398
+ "rel": "member"
399
+ },
400
+ {
401
+ "href": "\/grid5000\/sites\/bordeaux\/versions",
402
+ "title": "versions",
403
+ "rel": "collection"
404
+ },
405
+ {
406
+ "href": "\/grid5000\/sites\/bordeaux\/clusters",
407
+ "resolvable": true,
408
+ "title": "clusters",
409
+ "rel": "collection",
410
+ "resolved": false
411
+ },
412
+ {
413
+ "href": "\/grid5000\/sites\/bordeaux\/environments",
414
+ "resolvable": true,
415
+ "title": "environments",
416
+ "rel": "collection",
417
+ "resolved": false
418
+ },
419
+ {
420
+ "href": "\/grid5000",
421
+ "rel": "parent"
422
+ },
423
+ {
424
+ "href": "\/grid5000\/sites\/bordeaux\/status",
425
+ "title": "status",
426
+ "rel": "collection"
427
+ }
428
+ ],
429
+ "description": "Grid5000 Bordeaux site",
430
+ "longitude": -0.566667,
431
+ "email_contact": "bordeaux-staff@lists.grid5000.fr",
432
+ "web": "http:\/\/www.grid5000.fr\/mediawiki\/index.php\/Bordeaux:Home",
433
+ "sys_admin_contact": "bordeaux-staff@lists.grid5000.fr"
434
+ },
435
+ "orsay": {
436
+ "name": "Orsay",
437
+ "latitude": 48.7,
438
+ "location": "Orsay, France",
439
+ "security_contact": null,
440
+ "uid": "orsay",
441
+ "type": "site",
442
+ "user_support_contact": null,
443
+ "version": "747d2af24c5f3c2578a96626e0b00413c8484f04",
444
+ "links": [
445
+ {
446
+ "href": "\/grid5000\/sites\/orsay",
447
+ "rel": "self"
448
+ },
449
+ {
450
+ "href": "\/grid5000\/sites\/orsay\/versions\/747d2af24c5f3c2578a96626e0b00413c8484f04",
451
+ "title": "version",
452
+ "rel": "member"
453
+ },
454
+ {
455
+ "href": "\/grid5000\/sites\/orsay\/versions",
456
+ "title": "versions",
457
+ "rel": "collection"
458
+ },
459
+ {
460
+ "href": "\/grid5000\/sites\/orsay\/clusters",
461
+ "resolvable": true,
462
+ "title": "clusters",
463
+ "rel": "collection",
464
+ "resolved": false
465
+ },
466
+ {
467
+ "href": "\/grid5000\/sites\/orsay\/environments",
468
+ "resolvable": true,
469
+ "title": "environments",
470
+ "rel": "collection",
471
+ "resolved": false
472
+ },
473
+ {
474
+ "href": "\/grid5000",
475
+ "rel": "parent"
476
+ },
477
+ {
478
+ "href": "\/grid5000\/sites\/orsay\/status",
479
+ "title": "status",
480
+ "rel": "collection"
481
+ }
482
+ ],
483
+ "description": "",
484
+ "longitude": 2.2,
485
+ "email_contact": null,
486
+ "web": null,
487
+ "sys_admin_contact": null
488
+ }
489
+ }
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__)+'/../spec_helper'
2
+ describe Restfully::HTTP::Error do
3
+ it "should have a response reader" do
4
+ response = mock("restfully response", :status => 404, :body => {'title' => 'Not Found', 'message' => 'The requested resource cannot be found.', 'code' => 404})
5
+ error = Restfully::HTTP::Error.new(response)
6
+ error.response.should == response
7
+ end
8
+ it "should work properly" do
9
+ response = mock("restfully response", :status => 404, :body => {'title' => 'Not Found', 'message' => 'The requested resource cannot be found.', 'code' => 404})
10
+ begin
11
+ raise Restfully::HTTP::Error.new(response)
12
+ rescue Restfully::HTTP::Error => e
13
+ e.response.should == response
14
+ e.message.should == "404 Not Found. The requested resource cannot be found."
15
+ e.backtrace.should_not be_empty
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__)+'/../spec_helper'
2
+ describe Restfully::HTTP::Headers do
3
+ class IncludeHeadersModule
4
+ include Restfully::HTTP::Headers
5
+ end
6
+
7
+ it "should correctly parse headers" do
8
+ sanitized_headers = IncludeHeadersModule.new.sanitize_http_headers('accept' => 'application/json', :x_remote_ident => 'crohr', 'X_GVI' => 'sid', 'CACHE-CONTROL' => ['max-age=0', 'no-cache'], 'Content-Length' => 22)
9
+ sanitized_headers.should == {
10
+ 'Accept' => 'application/json',
11
+ 'X-Remote-Ident' => 'crohr',
12
+ 'X-Gvi' => 'sid',
13
+ 'Cache-Control' => 'max-age=0, no-cache',
14
+ 'Content-Length' => 22
15
+ }
16
+ end
17
+ end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__)+'/../spec_helper'
2
+ describe Restfully::HTTP::Request do
3
+
4
+ it "should correctly initialize the attributes" do
5
+ request = Restfully::HTTP::Request.new(
6
+ 'https://api.grid5000.fr/sid/grid5000?q1=v1&q2=v2',
7
+ :headers => {'accept' => 'application/json', :cache_control => 'max-age=0'},
8
+ :query => {'custom_param1' => [3, 4, 5, 6], 'custom_param2' => 'value_custom_param2'}
9
+ )
10
+ request.uri.should be_a URI
11
+ request.uri.to_s.should == 'https://api.grid5000.fr/sid/grid5000?q1=v1&q2=v2&custom_param1=3,4,5,6&custom_param2=value_custom_param2'
12
+ request.uri.query.should == "q1=v1&q2=v2&custom_param1=3,4,5,6&custom_param2=value_custom_param2"
13
+ request.headers.should == {
14
+ 'Accept' => 'application/json',
15
+ 'Cache-Control' => 'max-age=0'
16
+ }
17
+ request.retries.should == 0
18
+ end
19
+
20
+ it "should accept a URI object as url" do
21
+ request = Restfully::HTTP::Request.new(uri=URI.parse('https://api.grid5000.fr/sid/grid5000'))
22
+ request.uri.to_s.should == 'https://api.grid5000.fr/sid/grid5000'
23
+ end
24
+
25
+ it "should not fail if there are query parameters but no query string in the given URL" do
26
+ request = Restfully::HTTP::Request.new('https://api.grid5000.fr/grid5000', :query => {:q1 => 'v1'})
27
+ request.uri.query.should == "q1=v1"
28
+ end
29
+
30
+ it "should not change the query string if none is given as an option" do
31
+ request = Restfully::HTTP::Request.new('https://api.grid5000.fr/grid5000?q1=v1&q2=v2')
32
+ request.uri.to_s.should == 'https://api.grid5000.fr/grid5000?q1=v1&q2=v2'
33
+ request.headers.should == {}
34
+ end
35
+
36
+ it "should offer a function to add headers" do
37
+ request = Restfully::HTTP::Request.new('https://api.grid5000.fr/grid5000?q1=v1&q2=v2', :headers => {:accept => 'application/json'})
38
+ expected_headers = {
39
+ 'Accept' => 'application/json',
40
+ 'Cache-Control' => 'max-age=0'
41
+ }
42
+ request.add_headers(:cache_control => 'max-age=0').should == expected_headers
43
+ request.headers.should == expected_headers
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__)+'/../spec_helper'
2
+ describe Restfully::HTTP::Response do
3
+
4
+ it "should correctly initialize the attributes" do
5
+ response = Restfully::HTTP::Response.new(404, {:content_type => 'application/json;charset=utf-8'}, '{"property1": "value1", "property2": "value2"}')
6
+ response.status.should == 404
7
+ response.headers.should == {
8
+ 'Content-Type' => 'application/json;charset=utf-8'
9
+ }
10
+ response.body.should == {
11
+ 'property1' => 'value1',
12
+ 'property2' => 'value2'
13
+ }
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__)+'/../spec_helper'
2
+ describe Restfully::HTTP::Adapters::RestClientAdapter do
3
+ it "should correctly get the resource corresponding to the request" do
4
+ adapter = Restfully::HTTP::Adapters::RestClientAdapter.new("https://api.grid5000.fr", :username => 'crohr', :password => 'password')
5
+ request = Restfully::HTTP::Request.new('http://api.local/sid/grid5000', :headers => {:accept => 'application/json'}, :query => {:q1 => 'v1'})
6
+ RestClient::Resource.should_receive(:new).with('http://api.local/sid/grid5000?q1=v1', :password => 'password', :user => 'crohr').and_return(resource = mock("restclient resource"))
7
+ resource.should_receive(:get).with(request.headers).and_return(mock("restclient response", :headers => {:content_type => 'application/json;charset=utf-8'}, :to_s => "", :code => 200))
8
+ response = adapter.get(request)
9
+ response.status.should == 200
10
+ response.body.should be_nil
11
+ response.headers.should == {
12
+ 'Content-Type' => 'application/json;charset=utf-8'
13
+ }
14
+ end
15
+ it "should transform the username option into a user option" do
16
+ adapter = Restfully::HTTP::Adapters::RestClientAdapter.new("https://api.grid5000.fr", :username => 'crohr', :password => 'password')
17
+ adapter.options[:user].should == 'crohr'
18
+ adapter.options[:username].should be_nil
19
+ end
20
+ it "should raise a not implemented error when trying to use functions not implemented yet" do
21
+ adapter = Restfully::HTTP::Adapters::RestClientAdapter.new("https://api.grid5000.fr")
22
+ lambda{adapter.post(mock("restfully request"))}.should raise_error NotImplementedError, "POST is not supported by your adapter."
23
+ end
24
+ it "should rescue any RestClient::Exception and correctly populate the response" do
25
+ res = mock(Net::HTTPResponse, :code => 404, :body => '{"message":"whatever"}', :to_hash => {'Content-Type' => 'application/json;charset=utf-8', 'Content-Length' => 22}, :[] => '')
26
+ RestClient::Resource.should_receive(:new).and_raise RestClient::ResourceNotFound.new(res)
27
+ adapter = Restfully::HTTP::Adapters::RestClientAdapter.new("https://api.grid5000.fr", :username => 'crohr', :password => 'password')
28
+ response = adapter.get(mock("request", :uri => "uri"))
29
+ response.status.should == 404
30
+ response.headers.should == {'Content-Type' => 'application/json;charset=utf-8', 'Content-Length' => 22}
31
+ response.body.should == {'message' => 'whatever'}
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__)+'/spec_helper'
2
+
3
+ include Restfully::Parsing
4
+
5
+ describe Restfully::Parsing do
6
+ class IncludesParsingModule
7
+ include Restfully::Parsing
8
+ end
9
+ it "should make available the serialize and unserialize methods" do
10
+ klass = IncludesParsingModule.new
11
+ klass.should respond_to(:unserialize)
12
+ klass.should respond_to(:serialize)
13
+ end
14
+ it "should raise a ParserNotFound error if the object cannot be parsed" do
15
+ lambda{unserialize("whatever", :content_type => 'unknown')}.should raise_error(Restfully::Parsing::ParserNotFound, "Content-Type 'unknown' is not supported. Cannot parse the given object.")
16
+ end
17
+ it "should correctly unserialize json content" do
18
+ object = {'p1' => 'v1'}
19
+ unserialize(object.to_json, :content_type => 'application/json;charset=utf-8').should == object
20
+ end
21
+ it "should correctly serialize an object into json" do
22
+ object = {'p1' => 'v1'}
23
+ serialize(object, :content_type => 'application/json;charset=utf-8').should == object.to_json
24
+ end
25
+ end