Rebased
* 'master' of git://github.com/jchris/couchrest:
all specs pass; refined attachment api
add mattetti's 5aebd53a93
fix rebase end balance
Started on the ExtendedDocument class with features moved to mixins.
Started on the ExtendedDocument class with features moved to mixins.
updated readme file
Started the refactoring work on couchrest.
added some monkey patches to improve the http connection speed. (by keeping the http connection open)
slight change of API, CR::Document now uses <action>_doc instead of <action>, also added #create! and #recreate! to Document instances
Added attachment methods to CouchRest::Document: #put_attachment, #fetch_attachment and #delete_attachment. Note you can overwrite exisitng attachments with #put_attachment.
- Added Database#delete_attachment, for removing them directly
documentation for Document#copy and #move, copied from Database
database replication methods, no conflict resolution provided
This commit is contained in:
commit
fa29906900
6 changed files with 244 additions and 18 deletions
|
@ -142,6 +142,10 @@ describe CouchRest::Document do
|
|||
end
|
||||
end
|
||||
|
||||
describe "bulk saving" do
|
||||
before :all do
|
||||
@db = reset_test_db!
|
||||
end
|
||||
|
||||
describe "destroying a document from a db using bulk save" do
|
||||
before(:all) do
|
||||
|
@ -243,4 +247,68 @@ describe CouchRest::Document do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "dealing with attachments" do
|
||||
before do
|
||||
@db = reset_test_db!
|
||||
@attach = "<html><head><title>My Doc</title></head><body><p>Has words.</p></body></html>"
|
||||
response = @db.save({'key' => 'value'})
|
||||
@doc = @db.get(response['id'])
|
||||
end
|
||||
|
||||
def append_attachment(name='test.html', attach=@attach)
|
||||
@doc['_attachments'] ||= {}
|
||||
@doc['_attachments'][name] = {
|
||||
'type' => 'text/html',
|
||||
'data' => attach
|
||||
}
|
||||
@doc.save
|
||||
@rev = @doc['_rev']
|
||||
end
|
||||
|
||||
describe "PUTing an attachment directly to the doc" do
|
||||
before do
|
||||
@doc.put_attachment('test.html', @attach)
|
||||
end
|
||||
|
||||
it "is there" do
|
||||
@db.fetch_attachment(@doc, 'test.html').should == @attach
|
||||
end
|
||||
|
||||
it "updates the revision" do
|
||||
@doc['_rev'].should_not == @rev
|
||||
end
|
||||
|
||||
it "updates attachments" do
|
||||
@attach2 = "<html><head><title>My Doc</title></head><body><p>Is Different.</p></body></html>"
|
||||
@doc.put_attachment('test.html', @attach2)
|
||||
@db.fetch_attachment(@doc, 'test.html').should == @attach2
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetching an attachment from a doc directly" do
|
||||
before do
|
||||
append_attachment
|
||||
end
|
||||
|
||||
it "pulls the attachment" do
|
||||
@doc.fetch_attachment('test.html').should == @attach
|
||||
end
|
||||
end
|
||||
|
||||
describe "deleting an attachment from a doc directly" do
|
||||
before do
|
||||
append_attachment
|
||||
@doc.delete_attachment('test.html')
|
||||
end
|
||||
|
||||
it "removes it" do
|
||||
lambda { @db.fetch_attachment(@doc, 'test.html').should }.should raise_error(RestClient::ResourceNotFound)
|
||||
end
|
||||
|
||||
it "updates the revision" do
|
||||
@doc['_rev'].should_not == @rev
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue