samflores-couchrest 0.2.1 → 0.12.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -34
- data/Rakefile +5 -2
- data/bin/couchdir +20 -0
- data/examples/model/example.rb +13 -19
- data/examples/word_count/word_count.rb +24 -3
- data/examples/word_count/word_count_query.rb +6 -7
- data/lib/couchrest/core/database.rb +49 -126
- data/lib/couchrest/core/document.rb +25 -58
- data/lib/couchrest/core/model.rb +612 -0
- data/lib/couchrest/core/server.rb +10 -47
- data/lib/couchrest/core/validations.rb +328 -0
- data/lib/couchrest/monkeypatches.rb +0 -95
- data/lib/couchrest.rb +10 -57
- data/spec/couchrest/core/database_spec.rb +68 -183
- data/spec/couchrest/core/design_spec.rb +1 -1
- data/spec/couchrest/core/document_spec.rb +104 -285
- data/spec/couchrest/core/model_spec.rb +855 -0
- data/spec/couchrest/helpers/pager_spec.rb +1 -1
- data/spec/spec_helper.rb +7 -13
- metadata +17 -83
- data/examples/word_count/word_count_views.rb +0 -26
- data/lib/couchrest/core/response.rb +0 -16
- data/lib/couchrest/mixins/attachments.rb +0 -31
- data/lib/couchrest/mixins/callbacks.rb +0 -483
- data/lib/couchrest/mixins/design_doc.rb +0 -64
- data/lib/couchrest/mixins/document_queries.rb +0 -48
- data/lib/couchrest/mixins/extended_attachments.rb +0 -68
- data/lib/couchrest/mixins/extended_document_mixins.rb +0 -6
- data/lib/couchrest/mixins/properties.rb +0 -125
- data/lib/couchrest/mixins/validation.rb +0 -234
- data/lib/couchrest/mixins/views.rb +0 -168
- data/lib/couchrest/mixins.rb +0 -4
- data/lib/couchrest/more/casted_model.rb +0 -28
- data/lib/couchrest/more/extended_document.rb +0 -217
- data/lib/couchrest/more/property.rb +0 -40
- data/lib/couchrest/support/blank.rb +0 -42
- data/lib/couchrest/support/class.rb +0 -191
- data/lib/couchrest/validation/auto_validate.rb +0 -163
- data/lib/couchrest/validation/contextual_validators.rb +0 -78
- data/lib/couchrest/validation/validation_errors.rb +0 -118
- data/lib/couchrest/validation/validators/absent_field_validator.rb +0 -74
- data/lib/couchrest/validation/validators/confirmation_validator.rb +0 -99
- data/lib/couchrest/validation/validators/format_validator.rb +0 -117
- data/lib/couchrest/validation/validators/formats/email.rb +0 -66
- data/lib/couchrest/validation/validators/formats/url.rb +0 -43
- data/lib/couchrest/validation/validators/generic_validator.rb +0 -120
- data/lib/couchrest/validation/validators/length_validator.rb +0 -134
- data/lib/couchrest/validation/validators/method_validator.rb +0 -89
- data/lib/couchrest/validation/validators/numeric_validator.rb +0 -104
- data/lib/couchrest/validation/validators/required_field_validator.rb +0 -109
- data/spec/couchrest/core/server_spec.rb +0 -35
- data/spec/couchrest/more/casted_extended_doc_spec.rb +0 -40
- data/spec/couchrest/more/casted_model_spec.rb +0 -98
- data/spec/couchrest/more/extended_doc_attachment_spec.rb +0 -130
- data/spec/couchrest/more/extended_doc_spec.rb +0 -509
- data/spec/couchrest/more/extended_doc_view_spec.rb +0 -207
- data/spec/couchrest/more/property_spec.rb +0 -130
- data/spec/couchrest/support/class_spec.rb +0 -59
- data/spec/fixtures/more/article.rb +0 -34
- data/spec/fixtures/more/card.rb +0 -20
- data/spec/fixtures/more/course.rb +0 -14
- data/spec/fixtures/more/event.rb +0 -6
- data/spec/fixtures/more/invoice.rb +0 -17
- data/spec/fixtures/more/person.rb +0 -8
- data/spec/fixtures/more/question.rb +0 -6
- data/spec/fixtures/more/service.rb +0 -12
@@ -61,7 +61,7 @@ describe CouchRest::Database do
|
|
61
61
|
emit(doc.word,null);
|
62
62
|
}
|
63
63
|
}'}}
|
64
|
-
@db.
|
64
|
+
@db.save({
|
65
65
|
"_id" => "_design/test",
|
66
66
|
:views => @view
|
67
67
|
})
|
@@ -80,7 +80,7 @@ describe CouchRest::Database do
|
|
80
80
|
|
81
81
|
describe "select from an existing view" do
|
82
82
|
before(:each) do
|
83
|
-
r = @db.
|
83
|
+
r = @db.save({
|
84
84
|
"_id" => "_design/first",
|
85
85
|
:views => {
|
86
86
|
:test => {
|
@@ -129,9 +129,9 @@ describe CouchRest::Database do
|
|
129
129
|
|
130
130
|
describe "GET (document by id) when the doc exists" do
|
131
131
|
before(:each) do
|
132
|
-
@r = @db.
|
132
|
+
@r = @db.save({'lemons' => 'from texas', 'and' => 'spain'})
|
133
133
|
@docid = "http://example.com/stuff.cgi?things=and%20stuff"
|
134
|
-
@db.
|
134
|
+
@db.save({'_id' => @docid, 'will-exist' => 'here'})
|
135
135
|
end
|
136
136
|
it "should get the document" do
|
137
137
|
doc = @db.get(@r['id'])
|
@@ -176,7 +176,7 @@ describe CouchRest::Database do
|
|
176
176
|
end
|
177
177
|
|
178
178
|
it "in the case of an id conflict should not insert anything" do
|
179
|
-
@r = @db.
|
179
|
+
@r = @db.save({'lemons' => 'from texas', 'and' => 'how', "_id" => "oneB"})
|
180
180
|
|
181
181
|
lambda do
|
182
182
|
rs = @db.bulk_save([
|
@@ -192,7 +192,7 @@ describe CouchRest::Database do
|
|
192
192
|
end
|
193
193
|
|
194
194
|
it "should empty the bulk save cache if no documents are given" do
|
195
|
-
@db.
|
195
|
+
@db.save({"_id" => "bulk_cache_1", "val" => "test"}, true)
|
196
196
|
lambda do
|
197
197
|
@db.get('bulk_cache_1')
|
198
198
|
end.should raise_error(RestClient::ResourceNotFound)
|
@@ -201,7 +201,7 @@ describe CouchRest::Database do
|
|
201
201
|
end
|
202
202
|
|
203
203
|
it "should raise an error that is useful for recovery" do
|
204
|
-
@r = @db.
|
204
|
+
@r = @db.save({"_id" => "taken", "field" => "stuff"})
|
205
205
|
begin
|
206
206
|
rs = @db.bulk_save([
|
207
207
|
{"_id" => "taken", "wild" => "and random"},
|
@@ -220,43 +220,17 @@ describe CouchRest::Database do
|
|
220
220
|
@db.documents["total_rows"].should == 0
|
221
221
|
end
|
222
222
|
it "should create the document and return the id" do
|
223
|
-
r = @db.
|
223
|
+
r = @db.save({'lemons' => 'from texas', 'and' => 'spain'})
|
224
224
|
r2 = @db.get(r['id'])
|
225
225
|
r2["lemons"].should == "from texas"
|
226
226
|
end
|
227
227
|
it "should use PUT with UUIDs" do
|
228
228
|
CouchRest.should_receive(:put).and_return({"ok" => true, "id" => "100", "rev" => "55"})
|
229
|
-
r = @db.
|
229
|
+
r = @db.save({'just' => ['another document']})
|
230
230
|
end
|
231
231
|
|
232
232
|
end
|
233
|
-
|
234
|
-
describe "fetch_attachment" do
|
235
|
-
before do
|
236
|
-
@attach = "<html><head><title>My Doc</title></head><body><p>Has words.</p></body></html>"
|
237
|
-
@doc = {
|
238
|
-
"_id" => "mydocwithattachment",
|
239
|
-
"field" => ["some value"],
|
240
|
-
"_attachments" => {
|
241
|
-
"test.html" => {
|
242
|
-
"type" => "text/html",
|
243
|
-
"data" => @attach
|
244
|
-
}
|
245
|
-
}
|
246
|
-
}
|
247
|
-
@db.save_doc(@doc)
|
248
|
-
end
|
249
|
-
|
250
|
-
# Depreacated
|
251
|
-
# it "should get the attachment with the doc's _id" do
|
252
|
-
# @db.fetch_attachment("mydocwithattachment", "test.html").should == @attach
|
253
|
-
# end
|
254
|
-
|
255
|
-
it "should get the attachment with the doc itself" do
|
256
|
-
@db.fetch_attachment(@db.get('mydocwithattachment'), 'test.html').should == @attach
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
233
|
+
|
260
234
|
describe "PUT attachment from file" do
|
261
235
|
before(:each) do
|
262
236
|
filename = FIXTURE_PATH + '/attachments/couchdb.png'
|
@@ -268,8 +242,7 @@ describe CouchRest::Database do
|
|
268
242
|
it "should save the attachment to a new doc" do
|
269
243
|
r = @db.put_attachment({'_id' => 'attach-this'}, 'couchdb.png', image = @file.read, {:content_type => 'image/png'})
|
270
244
|
r['ok'].should == true
|
271
|
-
|
272
|
-
attachment = @db.fetch_attachment(doc,"couchdb.png")
|
245
|
+
attachment = @db.fetch_attachment("attach-this","couchdb.png")
|
273
246
|
attachment.should == image
|
274
247
|
end
|
275
248
|
end
|
@@ -277,7 +250,7 @@ describe CouchRest::Database do
|
|
277
250
|
describe "PUT document with attachment" do
|
278
251
|
before(:each) do
|
279
252
|
@attach = "<html><head><title>My Doc</title></head><body><p>Has words.</p></body></html>"
|
280
|
-
doc = {
|
253
|
+
@doc = {
|
281
254
|
"_id" => "mydocwithattachment",
|
282
255
|
"field" => ["some value"],
|
283
256
|
"_attachments" => {
|
@@ -287,14 +260,14 @@ describe CouchRest::Database do
|
|
287
260
|
}
|
288
261
|
}
|
289
262
|
}
|
290
|
-
@db.
|
291
|
-
@doc = @db.get("mydocwithattachment")
|
263
|
+
@db.save(@doc)
|
292
264
|
end
|
293
265
|
it "should save and be indicated" do
|
294
|
-
|
266
|
+
doc = @db.get("mydocwithattachment")
|
267
|
+
doc['_attachments']['test.html']['length'].should == @attach.length
|
295
268
|
end
|
296
269
|
it "should be there" do
|
297
|
-
attachment = @db.fetch_attachment(
|
270
|
+
attachment = @db.fetch_attachment("mydocwithattachment","test.html")
|
298
271
|
attachment.should == @attach
|
299
272
|
end
|
300
273
|
end
|
@@ -311,16 +284,15 @@ describe CouchRest::Database do
|
|
311
284
|
}
|
312
285
|
}
|
313
286
|
}
|
314
|
-
@db.
|
315
|
-
doc
|
287
|
+
@db.save(doc)
|
288
|
+
doc = @db.get('mydocwithattachment')
|
316
289
|
doc['field'] << 'another value'
|
317
|
-
@db.
|
290
|
+
@db.save(doc)
|
318
291
|
end
|
319
292
|
|
320
293
|
it 'should be there' do
|
321
|
-
|
322
|
-
attachment
|
323
|
-
Base64.decode64(attachment).should == @attach
|
294
|
+
attachment = @db.fetch_attachment('mydocwithattachment', 'test.html')
|
295
|
+
attachment.should == @attach
|
324
296
|
end
|
325
297
|
end
|
326
298
|
|
@@ -342,43 +314,22 @@ describe CouchRest::Database do
|
|
342
314
|
}
|
343
315
|
}
|
344
316
|
}
|
345
|
-
@db.
|
346
|
-
@doc = @db.get("mydocwithattachment")
|
317
|
+
@db.save(@doc)
|
347
318
|
end
|
348
319
|
it "should save and be indicated" do
|
349
|
-
|
350
|
-
|
320
|
+
doc = @db.get("mydocwithattachment")
|
321
|
+
doc['_attachments']['test.html']['length'].should == @attach.length
|
322
|
+
doc['_attachments']['other.html']['length'].should == @attach2.length
|
351
323
|
end
|
352
324
|
it "should be there" do
|
353
|
-
attachment = @db.fetch_attachment(
|
325
|
+
attachment = @db.fetch_attachment("mydocwithattachment","test.html")
|
354
326
|
attachment.should == @attach
|
355
327
|
end
|
356
328
|
it "should be there" do
|
357
|
-
attachment = @db.fetch_attachment(
|
329
|
+
attachment = @db.fetch_attachment("mydocwithattachment","other.html")
|
358
330
|
attachment.should == @attach2
|
359
331
|
end
|
360
332
|
end
|
361
|
-
|
362
|
-
describe "DELETE an attachment directly from the database" do
|
363
|
-
before(:each) do
|
364
|
-
doc = {
|
365
|
-
'_id' => 'mydocwithattachment',
|
366
|
-
'_attachments' => {
|
367
|
-
'test.html' => {
|
368
|
-
'type' => 'text/html',
|
369
|
-
'data' => "<html><head><title>My Doc</title></head><body><p>Has words.</p></body></html>"
|
370
|
-
}
|
371
|
-
}
|
372
|
-
}
|
373
|
-
@db.save_doc(doc)
|
374
|
-
@doc = @db.get('mydocwithattachment')
|
375
|
-
end
|
376
|
-
it "should delete the attachment" do
|
377
|
-
lambda { @db.fetch_attachment(@doc,'test.html') }.should_not raise_error
|
378
|
-
@db.delete_attachment(@doc, "test.html")
|
379
|
-
lambda { @db.fetch_attachment(@doc,'test.html') }.should raise_error(RestClient::ResourceNotFound)
|
380
|
-
end
|
381
|
-
end
|
382
333
|
|
383
334
|
describe "POST document with attachment (with funky name)" do
|
384
335
|
before(:each) do
|
@@ -392,15 +343,14 @@ describe CouchRest::Database do
|
|
392
343
|
}
|
393
344
|
}
|
394
345
|
}
|
395
|
-
@docid = @db.
|
346
|
+
@docid = @db.save(@doc)['id']
|
396
347
|
end
|
397
348
|
it "should save and be indicated" do
|
398
349
|
doc = @db.get(@docid)
|
399
350
|
doc['_attachments']['http://example.com/stuff.cgi?things=and%20stuff']['length'].should == @attach.length
|
400
351
|
end
|
401
352
|
it "should be there" do
|
402
|
-
|
403
|
-
attachment = @db.fetch_attachment(doc,"http://example.com/stuff.cgi?things=and%20stuff")
|
353
|
+
attachment = @db.fetch_attachment(@docid,"http://example.com/stuff.cgi?things=and%20stuff")
|
404
354
|
attachment.should == @attach
|
405
355
|
end
|
406
356
|
end
|
@@ -408,15 +358,15 @@ describe CouchRest::Database do
|
|
408
358
|
describe "PUT (new document with url id)" do
|
409
359
|
it "should create the document" do
|
410
360
|
@docid = "http://example.com/stuff.cgi?things=and%20stuff"
|
411
|
-
@db.
|
412
|
-
lambda{@db.
|
361
|
+
@db.save({'_id' => @docid, 'will-exist' => 'here'})
|
362
|
+
lambda{@db.save({'_id' => @docid})}.should raise_error(RestClient::Request::RequestFailed)
|
413
363
|
@db.get(@docid)['will-exist'].should == 'here'
|
414
364
|
end
|
415
365
|
end
|
416
366
|
|
417
367
|
describe "PUT (new document with id)" do
|
418
368
|
it "should start without the document" do
|
419
|
-
# r = @db.
|
369
|
+
# r = @db.save({'lemons' => 'from texas', 'and' => 'spain'})
|
420
370
|
@db.documents['rows'].each do |doc|
|
421
371
|
doc['id'].should_not == 'my-doc'
|
422
372
|
end
|
@@ -425,17 +375,17 @@ describe CouchRest::Database do
|
|
425
375
|
# or instead make it return something with a fancy <=> method
|
426
376
|
end
|
427
377
|
it "should create the document" do
|
428
|
-
@db.
|
429
|
-
lambda{@db.
|
378
|
+
@db.save({'_id' => 'my-doc', 'will-exist' => 'here'})
|
379
|
+
lambda{@db.save({'_id' => 'my-doc'})}.should raise_error(RestClient::Request::RequestFailed)
|
430
380
|
end
|
431
381
|
end
|
432
382
|
|
433
383
|
describe "PUT (existing document with rev)" do
|
434
384
|
before(:each) do
|
435
|
-
@db.
|
385
|
+
@db.save({'_id' => 'my-doc', 'will-exist' => 'here'})
|
436
386
|
@doc = @db.get('my-doc')
|
437
387
|
@docid = "http://example.com/stuff.cgi?things=and%20stuff"
|
438
|
-
@db.
|
388
|
+
@db.save({'_id' => @docid, 'now' => 'save'})
|
439
389
|
end
|
440
390
|
it "should start with the document" do
|
441
391
|
@doc['will-exist'].should == 'here'
|
@@ -444,18 +394,18 @@ describe CouchRest::Database do
|
|
444
394
|
it "should save with url id" do
|
445
395
|
doc = @db.get(@docid)
|
446
396
|
doc['yaml'] = ['json', 'word.']
|
447
|
-
@db.
|
397
|
+
@db.save doc
|
448
398
|
@db.get(@docid)['yaml'].should == ['json', 'word.']
|
449
399
|
end
|
450
400
|
it "should fail to resave without the rev" do
|
451
401
|
@doc['them-keys'] = 'huge'
|
452
402
|
@doc['_rev'] = 'wrong'
|
453
|
-
# @db.
|
454
|
-
lambda {@db.
|
403
|
+
# @db.save(@doc)
|
404
|
+
lambda {@db.save(@doc)}.should raise_error
|
455
405
|
end
|
456
406
|
it "should update the document" do
|
457
407
|
@doc['them-keys'] = 'huge'
|
458
|
-
@db.
|
408
|
+
@db.save(@doc)
|
459
409
|
now = @db.get('my-doc')
|
460
410
|
now['them-keys'].should == 'huge'
|
461
411
|
end
|
@@ -464,7 +414,7 @@ describe CouchRest::Database do
|
|
464
414
|
describe "cached bulk save" do
|
465
415
|
it "stores documents in a database-specific cache" do
|
466
416
|
td = {"_id" => "btd1", "val" => "test"}
|
467
|
-
@db.
|
417
|
+
@db.save(td, true)
|
468
418
|
@db.instance_variable_get("@bulk_save_cache").should == [td]
|
469
419
|
|
470
420
|
end
|
@@ -473,8 +423,8 @@ describe CouchRest::Database do
|
|
473
423
|
@db.bulk_save_cache_limit = 3
|
474
424
|
td1 = {"_id" => "td1", "val" => true}
|
475
425
|
td2 = {"_id" => "td2", "val" => 4}
|
476
|
-
@db.
|
477
|
-
@db.
|
426
|
+
@db.save(td1, true)
|
427
|
+
@db.save(td2, true)
|
478
428
|
lambda do
|
479
429
|
@db.get(td1["_id"])
|
480
430
|
end.should raise_error(RestClient::ResourceNotFound)
|
@@ -482,7 +432,7 @@ describe CouchRest::Database do
|
|
482
432
|
@db.get(td2["_id"])
|
483
433
|
end.should raise_error(RestClient::ResourceNotFound)
|
484
434
|
td3 = {"_id" => "td3", "val" => "foo"}
|
485
|
-
@db.
|
435
|
+
@db.save(td3, true)
|
486
436
|
@db.get(td1["_id"])["val"].should == td1["val"]
|
487
437
|
@db.get(td2["_id"])["val"].should == td2["val"]
|
488
438
|
@db.get(td3["_id"])["val"].should == td3["val"]
|
@@ -492,11 +442,11 @@ describe CouchRest::Database do
|
|
492
442
|
td1 = {"_id" => "blah", "val" => true}
|
493
443
|
td2 = {"_id" => "steve", "val" => 3}
|
494
444
|
@db.bulk_save_cache_limit = 50
|
495
|
-
@db.
|
445
|
+
@db.save(td1, true)
|
496
446
|
lambda do
|
497
447
|
@db.get(td1["_id"])
|
498
448
|
end.should raise_error(RestClient::ResourceNotFound)
|
499
|
-
@db.
|
449
|
+
@db.save(td2)
|
500
450
|
@db.get(td1["_id"])["val"].should == td1["val"]
|
501
451
|
@db.get(td2["_id"])["val"].should == td2["val"]
|
502
452
|
end
|
@@ -504,27 +454,27 @@ describe CouchRest::Database do
|
|
504
454
|
|
505
455
|
describe "DELETE existing document" do
|
506
456
|
before(:each) do
|
507
|
-
@r = @db.
|
457
|
+
@r = @db.save({'lemons' => 'from texas', 'and' => 'spain'})
|
508
458
|
@docid = "http://example.com/stuff.cgi?things=and%20stuff"
|
509
|
-
@db.
|
459
|
+
@db.save({'_id' => @docid, 'will-exist' => 'here'})
|
510
460
|
end
|
511
461
|
it "should work" do
|
512
462
|
doc = @db.get(@r['id'])
|
513
463
|
doc['and'].should == 'spain'
|
514
|
-
@db.
|
464
|
+
@db.delete doc
|
515
465
|
lambda{@db.get @r['id']}.should raise_error
|
516
466
|
end
|
517
467
|
it "should work with uri id" do
|
518
468
|
doc = @db.get(@docid)
|
519
|
-
@db.
|
469
|
+
@db.delete doc
|
520
470
|
lambda{@db.get @docid}.should raise_error
|
521
471
|
end
|
522
472
|
it "should fail without an _id" do
|
523
|
-
lambda{@db.
|
473
|
+
lambda{@db.delete({"not"=>"a real doc"})}.should raise_error(ArgumentError)
|
524
474
|
end
|
525
475
|
it "should defer actual deletion when using bulk save" do
|
526
476
|
doc = @db.get(@docid)
|
527
|
-
@db.
|
477
|
+
@db.delete doc, true
|
528
478
|
lambda{@db.get @docid}.should_not raise_error
|
529
479
|
@db.bulk_save
|
530
480
|
lambda{@db.get @docid}.should raise_error
|
@@ -534,14 +484,15 @@ describe CouchRest::Database do
|
|
534
484
|
|
535
485
|
describe "COPY existing document" do
|
536
486
|
before :each do
|
537
|
-
@r = @db.
|
487
|
+
@r = @db.save({'artist' => 'Zappa', 'title' => 'Muffin Man'})
|
538
488
|
@docid = 'tracks/zappa/muffin-man'
|
539
489
|
@doc = @db.get(@r['id'])
|
540
490
|
end
|
541
491
|
describe "to a new location" do
|
542
492
|
it "should work" do
|
543
|
-
@db.
|
493
|
+
@db.copy @doc, @docid
|
544
494
|
newdoc = @db.get(@docid)
|
495
|
+
debugger
|
545
496
|
newdoc['artist'].should == 'Zappa'
|
546
497
|
end
|
547
498
|
it "should fail without an _id" do
|
@@ -550,20 +501,20 @@ describe CouchRest::Database do
|
|
550
501
|
end
|
551
502
|
describe "to an existing location" do
|
552
503
|
before :each do
|
553
|
-
@db.
|
504
|
+
@db.save({'_id' => @docid, 'will-exist' => 'here'})
|
554
505
|
end
|
555
506
|
it "should fail without a rev" do
|
556
|
-
lambda{@db.
|
507
|
+
lambda{@db.copy @doc, @docid}.should raise_error(RestClient::RequestFailed)
|
557
508
|
end
|
558
509
|
it "should succeed with a rev" do
|
559
510
|
@to_be_overwritten = @db.get(@docid)
|
560
|
-
@db.
|
511
|
+
@db.copy @doc, "#{@docid}?rev=#{@to_be_overwritten['_rev']}"
|
561
512
|
newdoc = @db.get(@docid)
|
562
513
|
newdoc['artist'].should == 'Zappa'
|
563
514
|
end
|
564
515
|
it "should succeed given the doc to overwrite" do
|
565
516
|
@to_be_overwritten = @db.get(@docid)
|
566
|
-
@db.
|
517
|
+
@db.copy @doc, @to_be_overwritten
|
567
518
|
newdoc = @db.get(@docid)
|
568
519
|
newdoc['artist'].should == 'Zappa'
|
569
520
|
end
|
@@ -572,13 +523,13 @@ describe CouchRest::Database do
|
|
572
523
|
|
573
524
|
describe "MOVE existing document" do
|
574
525
|
before :each do
|
575
|
-
@r = @db.
|
526
|
+
@r = @db.save({'artist' => 'Zappa', 'title' => 'Muffin Man'})
|
576
527
|
@docid = 'tracks/zappa/muffin-man'
|
577
528
|
@doc = @db.get(@r['id'])
|
578
529
|
end
|
579
530
|
describe "to a new location" do
|
580
531
|
it "should work" do
|
581
|
-
@db.
|
532
|
+
@db.move @doc, @docid
|
582
533
|
newdoc = @db.get(@docid)
|
583
534
|
newdoc['artist'].should == 'Zappa'
|
584
535
|
lambda {@db.get(@r['id'])}.should raise_error(RestClient::ResourceNotFound)
|
@@ -590,22 +541,22 @@ describe CouchRest::Database do
|
|
590
541
|
end
|
591
542
|
describe "to an existing location" do
|
592
543
|
before :each do
|
593
|
-
@db.
|
544
|
+
@db.save({'_id' => @docid, 'will-exist' => 'here'})
|
594
545
|
end
|
595
546
|
it "should fail without a rev" do
|
596
|
-
lambda{@db.
|
547
|
+
lambda{@db.move @doc, @docid}.should raise_error(RestClient::RequestFailed)
|
597
548
|
lambda{@db.get(@r['id'])}.should_not raise_error
|
598
549
|
end
|
599
550
|
it "should succeed with a rev" do
|
600
551
|
@to_be_overwritten = @db.get(@docid)
|
601
|
-
@db.
|
552
|
+
@db.move @doc, "#{@docid}?rev=#{@to_be_overwritten['_rev']}"
|
602
553
|
newdoc = @db.get(@docid)
|
603
554
|
newdoc['artist'].should == 'Zappa'
|
604
555
|
lambda {@db.get(@r['id'])}.should raise_error(RestClient::ResourceNotFound)
|
605
556
|
end
|
606
557
|
it "should succeed given the doc to overwrite" do
|
607
558
|
@to_be_overwritten = @db.get(@docid)
|
608
|
-
@db.
|
559
|
+
@db.move @doc, @to_be_overwritten
|
609
560
|
newdoc = @db.get(@docid)
|
610
561
|
newdoc['artist'].should == 'Zappa'
|
611
562
|
lambda {@db.get(@r['id'])}.should raise_error(RestClient::ResourceNotFound)
|
@@ -616,7 +567,7 @@ describe CouchRest::Database do
|
|
616
567
|
|
617
568
|
it "should list documents" do
|
618
569
|
5.times do
|
619
|
-
@db.
|
570
|
+
@db.save({'another' => 'doc', 'will-exist' => 'anywhere'})
|
620
571
|
end
|
621
572
|
ds = @db.documents
|
622
573
|
ds['rows'].should be_an_instance_of(Array)
|
@@ -627,7 +578,7 @@ describe CouchRest::Database do
|
|
627
578
|
describe "documents / _all_docs" do
|
628
579
|
before(:each) do
|
629
580
|
9.times do |i|
|
630
|
-
@db.
|
581
|
+
@db.save({'_id' => "doc#{i}",'another' => 'doc', 'will-exist' => 'here'})
|
631
582
|
end
|
632
583
|
end
|
633
584
|
it "should list documents with keys and such" do
|
@@ -674,72 +625,6 @@ describe CouchRest::Database do
|
|
674
625
|
@cr.databases.should_not include('couchrest-test')
|
675
626
|
end
|
676
627
|
end
|
677
|
-
|
678
|
-
describe "replicating a database" do
|
679
|
-
before do
|
680
|
-
@db.save_doc({'_id' => 'test_doc', 'some-value' => 'foo'})
|
681
|
-
@other_db = @cr.database 'couchrest-test-replication'
|
682
|
-
@other_db.delete! rescue nil
|
683
|
-
@other_db = @cr.create_db 'couchrest-test-replication'
|
684
|
-
end
|
685
|
-
|
686
|
-
describe "via pulling" do
|
687
|
-
before do
|
688
|
-
@other_db.replicate_from @db
|
689
|
-
end
|
690
|
-
|
691
|
-
it "contains the document from the original database" do
|
692
|
-
doc = @other_db.get('test_doc')
|
693
|
-
doc['some-value'].should == 'foo'
|
694
|
-
end
|
695
|
-
end
|
696
|
-
|
697
|
-
describe "via pushing" do
|
698
|
-
before do
|
699
|
-
@db.replicate_to @other_db
|
700
|
-
end
|
701
|
-
|
702
|
-
it "copies the document to the other database" do
|
703
|
-
doc = @other_db.get('test_doc')
|
704
|
-
doc['some-value'].should == 'foo'
|
705
|
-
end
|
706
|
-
end
|
707
|
-
end
|
708
|
-
|
709
|
-
describe "creating a database" do
|
710
|
-
before(:each) do
|
711
|
-
@db = @cr.database('couchrest-test-db_to_create')
|
712
|
-
@db.delete! if @cr.databases.include?('couchrest-test-db_to_create')
|
713
|
-
end
|
714
|
-
|
715
|
-
it "should just work fine" do
|
716
|
-
@cr.databases.should_not include('couchrest-test-db_to_create')
|
717
|
-
@db.create!
|
718
|
-
@cr.databases.should include('couchrest-test-db_to_create')
|
719
|
-
end
|
720
|
-
end
|
721
|
-
|
722
|
-
describe "recreating a database" do
|
723
|
-
before(:each) do
|
724
|
-
@db = @cr.database('couchrest-test-db_to_create')
|
725
|
-
@db2 = @cr.database('couchrest-test-db_to_recreate')
|
726
|
-
@cr.databases.include?(@db.name) ? nil : @db.create!
|
727
|
-
@cr.databases.include?(@db2.name) ? @db2.delete! : nil
|
728
|
-
end
|
729
|
-
|
730
|
-
it "should drop and recreate a database" do
|
731
|
-
@cr.databases.should include(@db.name)
|
732
|
-
@db.recreate!
|
733
|
-
@cr.databases.should include(@db.name)
|
734
|
-
end
|
735
|
-
|
736
|
-
it "should recreate a db even tho it doesn't exist" do
|
737
|
-
@cr.databases.should_not include(@db2.name)
|
738
|
-
@db2.recreate!
|
739
|
-
@cr.databases.should include(@db2.name)
|
740
|
-
end
|
741
|
-
|
742
|
-
end
|
743
628
|
|
744
629
|
|
745
|
-
end
|
630
|
+
end
|