Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasterLambaster/482730 to your computer and use it in GitHub Desktop.
Save MasterLambaster/482730 to your computer and use it in GitHub Desktop.
From 4cba2c216ddd2f11d207e6b454ed7d6c04085cea Mon Sep 17 00:00:00 2001
From: MasterLambaster <MasterLambaster@gmail.com>
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