Skip to content

Instantly share code, notes, and snippets.

@larskluge
Created November 20, 2012 18:10
Show Gist options
  • Save larskluge/4119739 to your computer and use it in GitHub Desktop.
Save larskluge/4119739 to your computer and use it in GitHub Desktop.
Mongoid: odd test to show recursion issue
From 76332f87355d9e2385836274f6d5d628435f8b06 Mon Sep 17 00:00:00 2001
From: aekym <me@aekym.com>
Date: Tue, 20 Nov 2012 13:08:22 -0500
Subject: [PATCH] add odd test to show recursion issue
---
spec/mongoid/relations/embedded/one_spec.rb | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/spec/mongoid/relations/embedded/one_spec.rb b/spec/mongoid/relations/embedded/one_spec.rb
index 497dd45..8eb201b 100644
--- a/spec/mongoid/relations/embedded/one_spec.rb
+++ b/spec/mongoid/relations/embedded/one_spec.rb
@@ -61,6 +61,27 @@ describe Mongoid::Relations::Embedded::One do
it "does not save the target" do
name.should_not be_persisted
end
+
+ context "with overwritten getter" do
+
+ before do
+ person.name = nil
+ def person.name_with_default
+ puts 'getter called'
+ name_without_default or (self.name = Name.new)
+ end
+ class << person
+ alias_method_chain :name, :default
+ end
+ end
+
+ it 'sets the target without an invinite recursion (setter calls getter etc)' do
+ person.name = name
+ person.name.should be_present
+ end
+
+ end
+
end
context "when the parent is not a new record" do
--
1.7.9.6 (Apple Git-31.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment