Make design_doc non-inheritable. Fixes bug where views added to a child class were propagated to the parent and siblings. Child class "all" view map function now checks in guard clause for child class name instead of parent name
This commit is contained in:
parent
1ee82b714c
commit
5d112df1e8
|
@ -7,7 +7,11 @@ module CouchRest
|
||||||
end
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
attr_accessor :design_doc_slug_cache, :design_doc_fresh
|
attr_accessor :design_doc, :design_doc_slug_cache, :design_doc_fresh
|
||||||
|
|
||||||
|
def design_doc
|
||||||
|
@design_doc ||= Design.new(default_design_doc)
|
||||||
|
end
|
||||||
|
|
||||||
# Define a CouchDB view. The name of the view will be the concatenation
|
# Define a CouchDB view. The name of the view will be the concatenation
|
||||||
# of <tt>by</tt> and the keys joined by <tt>_and_</tt>
|
# of <tt>by</tt> and the keys joined by <tt>_and_</tt>
|
||||||
|
@ -77,7 +81,6 @@ module CouchRest
|
||||||
# <tt>spec/core/model_spec.rb</tt>.
|
# <tt>spec/core/model_spec.rb</tt>.
|
||||||
|
|
||||||
def view_by(*keys)
|
def view_by(*keys)
|
||||||
self.design_doc ||= Design.new(default_design_doc)
|
|
||||||
opts = keys.pop if keys.last.is_a?(Hash)
|
opts = keys.pop if keys.last.is_a?(Hash)
|
||||||
opts ||= {}
|
opts ||= {}
|
||||||
ducktype = opts.delete(:ducktype)
|
ducktype = opts.delete(:ducktype)
|
||||||
|
|
|
@ -14,7 +14,10 @@ class DesignBusinessCard < BusinessCard
|
||||||
property :bg_color, :default => '#eee'
|
property :bg_color, :default => '#eee'
|
||||||
end
|
end
|
||||||
|
|
||||||
class OnlineCourse < Course; end
|
class OnlineCourse < Course
|
||||||
|
property :url
|
||||||
|
view_by :url
|
||||||
|
end
|
||||||
|
|
||||||
class Animal < CouchRest::ExtendedDocument
|
class Animal < CouchRest::ExtendedDocument
|
||||||
use_database TEST_SERVER.default_database
|
use_database TEST_SERVER.default_database
|
||||||
|
@ -71,12 +74,25 @@ describe "Subclassing an ExtendedDocument" do
|
||||||
OnlineCourse.design_doc_slug.should =~ /^OnlineCourse/
|
OnlineCourse.design_doc_slug.should =~ /^OnlineCourse/
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have a it's own design_doc_fresh" do
|
it "should have its own design_doc_fresh" do
|
||||||
Animal.refresh_design_doc
|
Animal.refresh_design_doc
|
||||||
Dog.design_doc_fresh.should_not == true
|
Dog.design_doc_fresh.should_not == true
|
||||||
Dog.refresh_design_doc
|
Dog.refresh_design_doc
|
||||||
Dog.design_doc_fresh.should == true
|
Dog.design_doc_fresh.should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not add views to the parent's design_doc" do
|
||||||
|
Course.design_doc['views'].keys.should_not include('by_url')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not add the parent's views to its design doc" do
|
||||||
|
Course.refresh_design_doc
|
||||||
|
OnlineCourse.refresh_design_doc
|
||||||
|
OnlineCourse.design_doc['views'].keys.should_not include('by_title')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should have an all view with a guard clause for couchrest-type == subclass name in the map function" do
|
||||||
|
OnlineCourse.design_doc['views']['all']['map'].should =~ /if \(doc\['couchrest-type'\] == 'OnlineCourse'\)/
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue