From 5c21de8586f85b88b609a45ee3a2a43c1d9f3518 Mon Sep 17 00:00:00 2001 From: Sam Lown Date: Sun, 5 Sep 2010 20:06:44 +0200 Subject: [PATCH] Fixing find(blank) issue --- history.txt | 7 +++++++ lib/couchrest/model/document_queries.rb | 1 + spec/couchrest/persistence_spec.rb | 10 ++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/history.txt b/history.txt index 402c89f..d7e157f 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,10 @@ +== Next Version + +* Major enhancements + +* Minor enhancements + * Fixing find("") issue (thanks epochwolf) + == CouchRest Model 1.0.0.beta8 * Major enhancements diff --git a/lib/couchrest/model/document_queries.rb b/lib/couchrest/model/document_queries.rb index eb3e7da..3cc2673 100644 --- a/lib/couchrest/model/document_queries.rb +++ b/lib/couchrest/model/document_queries.rb @@ -70,6 +70,7 @@ module CouchRest # id:: Document ID # db:: optional option to pass a custom database to use def get!(id, db = database) + raise "Missing or empty document ID" if id.to_s.empty? doc = db.get id create_from_database(doc) end diff --git a/spec/couchrest/persistence_spec.rb b/spec/couchrest/persistence_spec.rb index 05e9b39..6723653 100644 --- a/spec/couchrest/persistence_spec.rb +++ b/spec/couchrest/persistence_spec.rb @@ -282,11 +282,17 @@ describe "Model Persistence" do foundart = Article.get 'matt aimonetti' foundart.should be_nil end + it "should return nil if a blank id is requested" do + Article.get("").should be_nil + end it "should raise an error if `get!` is used and the document doesn't exist" do - lambda{foundart = Article.get!('matt aimonetti')}.should raise_error + expect{ Article.get!('matt aimonetti') }.to raise_error + end + it "should raise an error if `get!` is requested with a blank id" do + expect{ Article.get!("") }.to raise_error end it "should raise an error if `find!` is used and the document doesn't exist" do - lambda{foundart = Article.find!('matt aimonetti')}.should raise_error + expect{ Article.find!('matt aimonetti') }.to raise_error end end