- Added Database#delete_attachment, for removing them directly
- Modified Database#fetch_attachment to take a doc as its first argument +as well as+ a docid, to be consistent with the other attachment methods. - Refactored the attachment uri generation used by #fetch_attachment, #put_attachment, and #delete_attachment to a common private method, #uri_for_attachment
This commit is contained in:
parent
9b3b56bbf5
commit
b915f7f708
2 changed files with 64 additions and 14 deletions
|
@ -230,7 +230,31 @@ describe CouchRest::Database do
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
describe "fetch_attachment" do
|
||||
before do
|
||||
@attach = "<html><head><title>My Doc</title></head><body><p>Has words.</p></body></html>"
|
||||
@doc = {
|
||||
"_id" => "mydocwithattachment",
|
||||
"field" => ["some value"],
|
||||
"_attachments" => {
|
||||
"test.html" => {
|
||||
"type" => "text/html",
|
||||
"data" => @attach
|
||||
}
|
||||
}
|
||||
}
|
||||
@db.save(@doc)
|
||||
end
|
||||
|
||||
it "should get the attachment with the doc's _id" do
|
||||
@db.fetch_attachment("mydocwithattachment", "test.html").should == @attach
|
||||
end
|
||||
it "should get the attachment with the doc itself" do
|
||||
@db.fetch_attachment(@db.get('mydocwithattachment'), 'test.html').should == @attach
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT attachment from file" do
|
||||
before(:each) do
|
||||
filename = FIXTURE_PATH + '/attachments/couchdb.png'
|
||||
|
@ -330,6 +354,27 @@ describe CouchRest::Database do
|
|||
attachment.should == @attach2
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE an attachment directly from the database" do
|
||||
before(:each) do
|
||||
doc = {
|
||||
'_id' => 'mydocwithattachment',
|
||||
'_attachments' => {
|
||||
'test.html' => {
|
||||
'type' => 'text/html',
|
||||
'data' => "<html><head><title>My Doc</title></head><body><p>Has words.</p></body></html>"
|
||||
}
|
||||
}
|
||||
}
|
||||
@db.save(doc)
|
||||
@doc = @db.get('mydocwithattachment')
|
||||
end
|
||||
it "should delete the attachment" do
|
||||
lambda { @db.fetch_attachment('mydocwithattachment','test.html') }.should_not raise_error
|
||||
@db.delete_attachment(@doc, "test.html")
|
||||
lambda { @db.fetch_attachment('mydocwithattachment','test.html') }.should raise_error(RestClient::ResourceNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST document with attachment (with funky name)" do
|
||||
before(:each) do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue