Permalink
Browse files

Use ActiveSupport DescendantsTracker

  • Loading branch information...
1 parent 34d121b commit 925b5bab982a347c87786c0f027f45229bb550d9 @bryckbost bryckbost committed Jul 30, 2010
View
2 UPGRADES
@@ -2,6 +2,8 @@
* [attribute]_before_typecast should become [attribute]_before_type_cast (note the extra _)
* Change validates_exclusion_of :within option to :in
* Change validates_inclusion_of :within option to :in
+ * descendants now returns all descendants use direct_descendants for just children
+ * Switch validate_on_create and validate_on_update use validate :on => :create syntax
0.7.6 => 0.8
* Proxy#owner has been removed in favor of Proxy#proxy_owner
View
2 lib/mongo_mapper/document.rb
@@ -13,14 +13,14 @@ def self.included(model)
include ActiveModel::Naming
include ActiveModel::Serialization
include ActiveModel::Serializers::JSON
+ include ActiveSupport::DescendantsTracker
extend ActiveModel::Translation
plugin Plugins::Document
plugin Plugins::Querying # for now needs to be before associations (save_to_collection)
plugin Plugins::Associations
plugin Plugins::Caching
plugin Plugins::Clone
- plugin Plugins::Descendants
plugin Plugins::DynamicQuerying
plugin Plugins::Equality
plugin Plugins::Inspect
View
2 lib/mongo_mapper/embedded_document.rb
@@ -13,13 +13,13 @@ def self.included(model)
include ActiveModel::Naming
include ActiveModel::Serialization
include ActiveModel::Serializers::JSON
+ include ActiveSupport::DescendantsTracker
extend ActiveModel::Translation
plugin Plugins::EmbeddedDocument
plugin Plugins::Associations
plugin Plugins::Caching
plugin Plugins::Clone
- plugin Plugins::Descendants
plugin Plugins::Equality
plugin Plugins::Inspect
plugin Plugins::Keys
View
17 lib/mongo_mapper/plugins/descendants.rb
@@ -1,17 +0,0 @@
-# encoding: UTF-8
-module MongoMapper
- module Plugins
- module Descendants
- module ClassMethods
- def inherited(descendant)
- descendants << descendant
- super
- end
-
- def descendants
- @descendants ||= []
- end
- end
- end
- end
-end
View
4 test/unit/test_embedded_document.rb
@@ -207,7 +207,9 @@ class ::OtherChild < ::Parent
end
should "be recorded" do
- Grandparent.descendants.should == [Parent]
+ Grandparent.direct_descendants.should == [Parent]
+ Grandparent.descendants.to_set.should == [Parent, Child, OtherChild].to_set
+
Parent.descendants.should == [Child, OtherChild]
end
end

0 comments on commit 925b5ba

Please sign in to comment.