-
Notifications
You must be signed in to change notification settings - Fork 14
Attachments
debasishg edited this page Sep 13, 2010
·
1 revision
val att = "The quick brown fox jumps over the lazy dog."
val s = Shop("Sears", "refrigerator", 12500)
val d = Doc(test, "sears")
var ir:(String, String) = null
var ii:(String, String) = null
// create a document from an object
couch(d add s)
ir = http(d ># %(Id._id, Id._rev))
ir._1 should equal("sears")
// query by id should fetch a row
ii = http(test by_id ir._1)
ii._1 should equal("sears")
// sticking an attachment should be successful
http(d attach("foo", "text/plain", att.getBytes, Some(ii._2)))
// retrieving the attachment should equal to att
val air = http(d ># %(Id._id, Id._rev))
air._1 should equal("sears")
http(d.getAttachment("foo") as_str) should equal(att)
Attachments can also be created for non-existing documents. In that case, the document also gets created along with the attachment. Have a look at the test suite for the spec.