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