From 9954d914c7dd9094bc68abc41df2c49c028b50f0 Mon Sep 17 00:00:00 2001 From: Matt Lyon Date: Thu, 12 Jun 2008 08:40:52 -0700 Subject: [PATCH] PUT attachments as stubs doesnt choke --- lib/database.rb | 1 + spec/database_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/database.rb b/lib/database.rb index b2bd966..39cc622 100644 --- a/lib/database.rb +++ b/lib/database.rb @@ -64,6 +64,7 @@ class CouchRest private def encode_attachments attachments attachments.each do |k,v| + next if v['stub'] v['data'] = base64(v['data']) end attachments diff --git a/spec/database_spec.rb b/spec/database_spec.rb index b586f3b..b88f3de 100644 --- a/spec/database_spec.rb +++ b/spec/database_spec.rb @@ -207,6 +207,30 @@ describe CouchRest::Database do attachment.should == @attach end end + + describe "PUT document with attachment stub" do + before(:each) do + @attach = "My Doc

Has words.

" + doc = { + '_id' => 'mydocwithattachment', + 'field' => ['some_value'], + '_attachments' => { + 'test.html' => { + 'type' => 'text/html', 'data' => @attach + } + } + } + @db.save(doc) + doc = @db.get('mydocwithattachment') + doc['field'] << 'another value' + @db.save(doc) + end + + it 'should be there' do + attachment = @db.fetch_attachment('mydocwithattachment', 'test.html') + attachment.should == @attach + end + end describe "PUT document with multiple attachments" do before(:each) do