From 9f65b9c0f61fd4c03211f8b77df7d24949cc0ab9 Mon Sep 17 00:00:00 2001 From: Yurii Rashkovskii Date: Sun, 4 May 2008 10:41:19 +0300 Subject: [PATCH 1/2] Minor Document pretty printing change for immutable documents --- lib/strokedb/document.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/strokedb/document.rb b/lib/strokedb/document.rb index aa3815a2..b4833459 100644 --- a/lib/strokedb/document.rb +++ b/lib/strokedb/document.rb @@ -269,7 +269,7 @@ def diff(from) def pretty_print #:nodoc: slots = to_raw.except('meta') - s = is_a?(ImmutableDocument) ? "#<(imm)" : "#<" + s = is_a?(ImmutableDocument) ? "#<^" : "#<" Util.catch_circular_reference(self) do if self[:meta] && name = meta[:name] From e88d17472c8a85b3a72ebc76a20d47923126f834 Mon Sep 17 00:00:00 2001 From: Yurii Rashkovskii Date: Sun, 4 May 2008 10:44:26 +0300 Subject: [PATCH 2/2] ImmutableDocument#make_mutable! has been added --- lib/strokedb/document.rb | 4 ++++ spec/lib/strokedb/document/document_spec.rb | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/strokedb/document.rb b/lib/strokedb/document.rb index b4833459..bbb5c359 100644 --- a/lib/strokedb/document.rb +++ b/lib/strokedb/document.rb @@ -745,5 +745,9 @@ def mutable? def save! self end + + def make_mutable! + unextend(ImmutableDocument) + end end end \ No newline at end of file diff --git a/spec/lib/strokedb/document/document_spec.rb b/spec/lib/strokedb/document/document_spec.rb index df5a3744..6114ee63 100644 --- a/spec/lib/strokedb/document/document_spec.rb +++ b/spec/lib/strokedb/document/document_spec.rb @@ -819,6 +819,23 @@ @document.should_not == @another_document end +end + +describe "Immutable Document" do + + before(:each) do + setup_default_store + @document = Document.new(:some_data => 1).make_immutable! + @document.should_not be_mutable + end + + it "should be able to be mutable again" do + @document.make_mutable! + @document.should be_mutable + end + + + end describe "Valid Document's JSON" do