Skip to content

Commit

Permalink
Same _type tweak for embedded documents.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Mar 31, 2010
1 parent aac15e6 commit 31fd5fa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
1 change: 0 additions & 1 deletion lib/mongo_mapper/document.rb
Expand Up @@ -36,7 +36,6 @@ def self.included(model)

module ClassMethods
def inherited(subclass)
key :_type, String unless keys.keys.include?(:_type)
subclass.set_collection_name(collection_name)
super
end
Expand Down
1 change: 1 addition & 0 deletions lib/mongo_mapper/plugins/keys.rb
Expand Up @@ -7,6 +7,7 @@ def self.configure(model)

module ClassMethods
def inherited(descendant)
key :_type, String unless keys.keys.include?(:_type)
descendant.instance_variable_set(:@keys, keys.dup)
super
end
Expand Down
14 changes: 7 additions & 7 deletions test/unit/test_embedded_document.rb
Expand Up @@ -179,17 +179,17 @@ class ::OtherChild < ::Parent

context "keys" do
should "be inherited" do
Grandparent.keys.keys.sort.should == ['_id', 'grandparent']
Parent.keys.keys.sort.should == ['_id', 'grandparent', 'parent']
Child.keys.keys.sort.should == ['_id', 'child', 'grandparent', 'parent']
Grandparent.keys.keys.sort.should == ['_id', '_type', 'grandparent']
Parent.keys.keys.sort.should == ['_id', '_type', 'grandparent', 'parent']
Child.keys.keys.sort.should == ['_id', '_type', 'child', 'grandparent', 'parent']
end

should "propogate to descendants if key added after class definition" do
Grandparent.key :_type, String
Grandparent.key :foo, String

Grandparent.keys.keys.sort.should == ['_id', '_type', 'grandparent']
Parent.keys.keys.sort.should == ['_id', '_type', 'grandparent', 'parent']
Child.keys.keys.sort.should == ['_id', '_type', 'child', 'grandparent', 'parent']
Grandparent.keys.keys.sort.should == ['_id', '_type', 'foo', 'grandparent']
Parent.keys.keys.sort.should == ['_id', '_type', 'foo', 'grandparent', 'parent']
Child.keys.keys.sort.should == ['_id', '_type', 'child', 'foo', 'grandparent', 'parent']
end

should "not add anonymous objects to the ancestor tree" do
Expand Down
6 changes: 3 additions & 3 deletions test/unit/test_rails_compatibility.rb
Expand Up @@ -29,9 +29,9 @@ class SecondItem < Item
end

should "have column names" do
Item.column_names.sort.should == ['_id', 'for_all']
FirstItem.column_names.sort.should == ['_id', 'first_only', 'for_all']
SecondItem.column_names.sort.should == ['_id', 'for_all', 'second_only']
Item.column_names.sort.should == ['_id', '_type', 'for_all']
FirstItem.column_names.sort.should == ['_id', '_type', 'first_only', 'for_all']
SecondItem.column_names.sort.should == ['_id', '_type', 'for_all', 'second_only']
end

should "alias new to new_record?" do
Expand Down

0 comments on commit 31fd5fa

Please sign in to comment.