Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

error message must be a string

  • Loading branch information...
commit d562a5408ca8ede1d018771020c013b13f0f7e6f 1 parent 6e462a4
@langalex authored
Showing with 9 additions and 3 deletions.
  1. +7 −1 lib/couch_potato/database.rb
  2. +2 −2 spec/unit/database_spec.rb
View
8 lib/couch_potato/database.rb
@@ -100,6 +100,10 @@ def destroy_document(document)
alias_method :destroy, :destroy_document
# loads a document by its id(s)
+ # id - either a single id or an array of ids
+ # returns either a single document or an array of documents (if an array of ids was passed).
+ # returns nil if the single document could not be found. when passing an array and some documents
+ # could not be found these are omitted from the returned array
def load_document(id)
raise "Can't load a document without an id (got nil)" if id.nil?
@@ -117,12 +121,14 @@ def load_document(id)
end
alias_method :load, :load_document
+ # loads one or more documents by its id(s)
+ # behaves like #load except it raises a CouchPotato::NotFound if any of the documents could not be found
def load!(id)
doc = load(id)
if id.is_a?(Array)
missing_docs = id - doc.map(&:id)
end
- raise(CouchPotato::NotFound, missing_docs) if doc.nil? || missing_docs.try(:any?)
+ raise(CouchPotato::NotFound, missing_docs.try(:join, ', ')) if doc.nil? || missing_docs.try(:any?)
doc
end
View
4 spec/unit/database_spec.rb
@@ -129,8 +129,8 @@ class Child
it "raises an exception when not all documents could be found" do
lambda {
- db.load! ['1', '2', '3']
- }.should raise_error(CouchPotato::NotFound, ['3'])
+ db.load! ['1', '2', '3', '4']
+ }.should raise_error(CouchPotato::NotFound, '3, 4')
end
it "raises no exception when all documents are found" do
Please sign in to comment.
Something went wrong with that request. Please try again.