Created
July 20, 2010 09:20
-
-
Save MasterLambaster/482730 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 4cba2c216ddd2f11d207e6b454ed7d6c04085cea Mon Sep 17 00:00:00 2001 | |
From: MasterLambaster <[email protected]> | |
Date: Tue, 20 Jul 2010 12:14:34 +0300 | |
Subject: [PATCH] Self-emedded records test | |
--- | |
spec/integration/mongoid/associations_spec.rb | 11 +++++++++++ | |
spec/models/node.rb | 4 ++++ | |
2 files changed, 15 insertions(+), 0 deletions(-) | |
create mode 100644 spec/models/node.rb | |
diff --git a/spec/integration/mongoid/associations_spec.rb b/spec/integration/mongoid/associations_spec.rb | |
index 133bef4..e313e64 100644 | |
--- a/spec/integration/mongoid/associations_spec.rb | |
+++ b/spec/integration/mongoid/associations_spec.rb | |
@@ -765,4 +765,15 @@ describe Mongoid::Associations do | |
end | |
end | |
end | |
+ | |
+ context "self referencing embeded association" do | |
+ let(:subject) { Node.create(:name => "Root")} | |
+ | |
+ context "creating many embedded with self reference" do | |
+ it "creates new embeded record" do | |
+ rec = subject.nodes.create(:name => 'Leaf') | |
+ Node.find(subject.id).nodes.first.should == rec | |
+ end | |
+ end | |
+ end | |
end | |
diff --git a/spec/models/node.rb b/spec/models/node.rb | |
new file mode 100644 | |
index 0000000..3ec4115 | |
--- /dev/null | |
+++ b/spec/models/node.rb | |
@@ -0,0 +1,4 @@ | |
+class Node | |
+ include Mongoid::Document | |
+ embeds_many :nodes | |
+end | |
-- | |
1.7.1.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment