diff --git a/lib/mongo_mapper/document.rb b/lib/mongo_mapper/document.rb index bc346f7fa..60d4e9857 100644 --- a/lib/mongo_mapper/document.rb +++ b/lib/mongo_mapper/document.rb @@ -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 diff --git a/lib/mongo_mapper/plugins/keys.rb b/lib/mongo_mapper/plugins/keys.rb index 542f896b5..b9a186dac 100644 --- a/lib/mongo_mapper/plugins/keys.rb +++ b/lib/mongo_mapper/plugins/keys.rb @@ -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 diff --git a/test/unit/test_embedded_document.rb b/test/unit/test_embedded_document.rb index d8032fae1..c9026e5f7 100644 --- a/test/unit/test_embedded_document.rb +++ b/test/unit/test_embedded_document.rb @@ -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 diff --git a/test/unit/test_rails_compatibility.rb b/test/unit/test_rails_compatibility.rb index 24255f135..69be94200 100644 --- a/test/unit/test_rails_compatibility.rb +++ b/test/unit/test_rails_compatibility.rb @@ -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