summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhukl <hukl@eight.local>2009-02-01 17:10:20 +0100
committerhukl <hukl@eight.local>2009-02-01 17:10:20 +0100
commita660a7ee62e44314c12440d376166ccb0cf60d80 (patch)
tree2f5bd0f4cfc6cebb2dc56b3b44ec2f51269716d3
parent07295b68c0ab6e340cccb1e124415572285f5e8f (diff)
added test for retrieving a specific revision via
a given node. turned out it wasn't working the way I thought so I rewrote it to use only Fixnums
-rw-r--r--app/controllers/content_controller.rb3
-rw-r--r--app/models/node.rb16
-rw-r--r--test/unit/node_test.rb16
3 files changed, 29 insertions, 6 deletions
diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb
index 5312ecd..278c5ab 100644
--- a/app/controllers/content_controller.rb
+++ b/app/controllers/content_controller.rb
@@ -12,7 +12,6 @@ class ContentController < ApplicationController
12 :status => 404 12 :status => 404
13 ) 13 )
14 end 14 end
15 15
16 end 16 end
17
18end 17end
diff --git a/app/models/node.rb b/app/models/node.rb
index 5acf563..3564ce4 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -5,16 +5,24 @@ class Node < ActiveRecord::Base
5 5
6 # Class methods 6 # Class methods
7 7
8 def self.find_page path, revision = :current 8
9 # Returns a page for a given node. If no revision is supplied, it returns
10 # the last / current one. If a specific revision number is supplied, the
11 # corresponding revision of that page is returned. Get the current / latest
12 # revision with -1. It raises an Argument error if the revision is not a
13 # Fixnum
14 def self.find_page path, revision = -1
15 unless revision.class == Fixnum
16 raise ArgumentError, "revision must be a Fixnum"
17 end
9 18
10 node = Node.find_by_unique_name(path) 19 node = Node.find_by_unique_name(path)
11 20
12 if node 21 if node
13
14 case revision 22 case revision
15 when :current 23 when -1
16 return node.pages.last 24 return node.pages.last
17 when /\d+/ 25 else
18 return node.pages.find_by_revision revision 26 return node.pages.find_by_revision revision
19 end 27 end
20 end 28 end
diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb
index 56012d6..5325daa 100644
--- a/test/unit/node_test.rb
+++ b/test/unit/node_test.rb
@@ -41,7 +41,23 @@ class NodeTest < ActiveSupport::TestCase
41 end 41 end
42 42
43 def test_retrieving_page_by_revision 43 def test_retrieving_page_by_revision
44 updates = Node.create(:slug => 'updates')
45 updates.move_to_child_of @root
46
47 year = Node.create(:slug => '2008')
48 year.move_to_child_of updates
49
50 foo = Node.create(:slug => 'foo')
51 foo.move_to_child_of year
52
53 assert_not_nil Node.find_by_unique_name('updates/2008/foo')
54
55 foo.pages.create :title => "Version 1"
56 foo.pages.create :title => "Version 2"
57 foo.pages.create :title => "Version 3"
44 58
59 page = Node.find_page("updates/2008/foo", 2)
60 assert_equal "Version 2", page.title
45 end 61 end
46 62
47 def test_order_of_pages_by_revision 63 def test_order_of_pages_by_revision