From 8533520ef9879c43ab08528029c4c8bb1b908b83 Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Sat, 22 Nov 2008 14:29:03 -0800 Subject: [PATCH] added couchrest-type back in to model --- lib/couchrest/core/model.rb | 9 ++++----- spec/couchrest/core/model_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/couchrest/core/model.rb b/lib/couchrest/core/model.rb index 4ac2da3..2cd3739 100644 --- a/lib/couchrest/core/model.rb +++ b/lib/couchrest/core/model.rb @@ -116,9 +116,6 @@ module CouchRest unless design_doc_fresh refresh_design_doc end - # view_name = "#{design_doc_slug}/all" - # raw = opts.delete(:raw) - # fetch_view_with_docs(view_name, opts, raw) view :all, opts, &block end @@ -270,8 +267,10 @@ module CouchRest opts = keys.pop if keys.last.is_a?(Hash) opts ||= {} ducktype = opts.delete(:ducktype) - # if ducktype - # end + unless ducktype || opts[:map] + opts[:guards] ||= [] + opts[:guards].push "(doc['couchrest-type'] == '#{self.to_s}')" + end keys.push opts self.design_doc.view_by(*keys) self.design_doc_fresh = false diff --git a/spec/couchrest/core/model_spec.rb b/spec/couchrest/core/model_spec.rb index 20ddbbf..6ae0502 100644 --- a/spec/couchrest/core/model_spec.rb +++ b/spec/couchrest/core/model_spec.rb @@ -412,6 +412,12 @@ describe CouchRest::Model do view['rows'].length.should == 4 end + it "should not include non-Articles" do + Article.database.save({"date" => 1}) + view = Article.by_date :raw => true + view['rows'].length.should == 4 + end + it "should return the matching objects (with default argument :descending => true)" do articles = Article.by_date articles.collect{|a|a.title}.should == @titles.reverse