Permalink
Browse files

Fix errors when fetching deleted documents using the bulk api

When you try to fetch a deleted document the doc attribute is set but has the value null. My commit fixes that and avoids the following exception 'NoMethodError: undefined method `database=' for nil:NilClass'.
  • Loading branch information...
1 parent f98362c commit 347fb94e7f3822e2a861df73ab27dedd2ddefeb6 @matthiasjakel committed Jun 19, 2012
Showing with 8 additions and 3 deletions.
  1. +1 −2 lib/couch_potato/database.rb
  2. +7 −1 spec/unit/database_spec.rb
@@ -146,8 +146,7 @@ def couchrest_database
def bulk_load(ids)
response = couchrest_database.bulk_load ids
- existing_rows = response['rows'].select{|row| row.key? 'doc'}
- docs = existing_rows.map{|row| row["doc"]}
+ docs = response['rows'].map{|row| row['doc']}.compact
docs.each{|doc| doc.database = self}
end
@@ -73,7 +73,13 @@ class Child
let(:doc1) { DbTestUser.new }
let(:doc2) { DbTestUser.new }
let(:response) do
- {"rows" => [{}, {"doc" => doc1}, {"doc" => doc2}]}
+ {
+ "rows" => [
+ {"doc" => nil, "value" => {"rev" => "10-df5a4021129ebb70f4a111eea1e881ca", "deleted"=> true}},
+ {"doc" => doc1},
+ {"doc" => doc2}
+ ]
+ }
end
before(:each) do

0 comments on commit 347fb94

Please sign in to comment.