Permalink
Browse files

Fix exception raising

  • Loading branch information...
1 parent 8d9e2f6 commit 833aac31a1cc6eea3abfe7092a5e11cc0b726f88 @matthiasjakel matthiasjakel committed Feb 26, 2012
Showing with 17 additions and 4 deletions.
  1. +1 −1 lib/couch_potato/database.rb
  2. +16 −3 spec/unit/database_spec.rb
@@ -122,7 +122,7 @@ def load!(id)
if id.is_a?(Array)
missing_docs = id - doc.map(&:id)
end
- raise(CouchPotato::NotFound, missing_docs) if doc.nil? || missing_docs
+ raise(CouchPotato::NotFound, missing_docs) if doc.nil? || !missing_docs.empty?
end
def inspect #:nodoc:
@@ -109,17 +109,30 @@ class Child
end
context "when several ids given" do
- it "raises an exception when not all documents could be found" do
- docs = [
+
+ let(:docs) do
+ [
DbTestUser.new(:id => '1'),
DbTestUser.new(:id => '2')
]
-
+ end
+
+ before(:each) do
db.stub(:load).and_return(docs)
+ end
+
+ it "raises an exception when not all documents could be found" do
lambda {
db.load! ['1', '2', '3']
}.should raise_error(CouchPotato::NotFound, ['3'])
end
+
+ it "raises no exception when all documents are found" do
+ docs << DbTestUser.new(:id => '3')
+ lambda {
+ db.load! ['1', '2', '3']
+ }.should_not raise_error(CouchPotato::NotFound)
+ end
end
end

0 comments on commit 833aac3

Please sign in to comment.