summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-04-18 14:23:51 +0200
committerhukl <contact@smyck.org>2009-04-18 14:23:51 +0200
commit6a13bb8c60b43f5798b7646791c982789d08215d (patch)
tree0cfdd35a404a0666403d83ce4bbb5b99bf116683
parent4b4846dc762df76ea82c3ef22787a7b193e357c6 (diff)
adding "restore_revision" functionality to the backend
-rw-r--r--app/models/node.rb9
-rw-r--r--test/unit/node_test.rb22
2 files changed, 31 insertions, 0 deletions
diff --git a/app/models/node.rb b/app/models/node.rb
index b56dff5..0b92708 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -81,6 +81,15 @@ class Node < ActiveRecord::Base
81 end 81 end
82 end 82 end
83 83
84 def restore_revision! revision
85 if page = self.pages.find_by_revision(revision)
86 self.head = page
87 self.save
88 else
89 nil
90 end
91 end
92
84 # returns an array with all parts of a unique_name rather than a string 93 # returns an array with all parts of a unique_name rather than a string
85 def unique_path 94 def unique_path
86 unique_name.split("/") rescue unique_name 95 unique_name.split("/") rescue unique_name
diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb
index 817c6f9..e054887 100644
--- a/test/unit/node_test.rb
+++ b/test/unit/node_test.rb
@@ -235,4 +235,26 @@ class NodeTest < ActiveSupport::TestCase
235 assert_not_nil test_node.draft 235 assert_not_nil test_node.draft
236 assert test_node.head != test_node.draft 236 assert test_node.head != test_node.draft
237 end 237 end
238
239 test "restoring a revision" do
240 test_node = Node.create! :slug => "test_node"
241 test_node.move_to_child_of Node.root
242 create_revisions( test_node, 3 )
243 test_node.find_or_create_draft @user1
244 test_node.reload
245
246 assert_equal 4, test_node.pages.count
247 assert_equal 3, test_node.head.revision
248
249 test_node.restore_revision!(1)
250 assert_equal 1, test_node.head.revision
251 assert_equal 4, test_node.draft.revision
252 end
253
254 def create_revisions node, count
255 count.times do
256 node.find_or_create_draft @user1
257 node.publish_draft!
258 end
259 end
238end 260end