From a660a7ee62e44314c12440d376166ccb0cf60d80 Mon Sep 17 00:00:00 2001 From: hukl Date: Sun, 1 Feb 2009 17:10:20 +0100 Subject: 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 --- app/models/node.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'app/models') 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 # Class methods - def self.find_page path, revision = :current + + # Returns a page for a given node. If no revision is supplied, it returns + # the last / current one. If a specific revision number is supplied, the + # corresponding revision of that page is returned. Get the current / latest + # revision with -1. It raises an Argument error if the revision is not a + # Fixnum + def self.find_page path, revision = -1 + unless revision.class == Fixnum + raise ArgumentError, "revision must be a Fixnum" + end node = Node.find_by_unique_name(path) if node - case revision - when :current + when -1 return node.pages.last - when /\d+/ + else return node.pages.find_by_revision revision end end -- cgit v1.3