From c7c4b007621fd28c88b65db5fd3296ef730097d9 Mon Sep 17 00:00:00 2001 From: hukl Date: Sat, 17 Oct 2009 23:31:28 +0200 Subject: added some more validations to ensure data integrity and applied necessary changes on tests --- app/models/node.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'app/models/node.rb') diff --git a/app/models/node.rb b/app/models/node.rb index 6587585..88a4d68 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -16,9 +16,12 @@ class Node < ActiveRecord::Base after_save :update_unique_names_of_children # Validations - validates_length_of :slug, :within => 1..255, :unless => "parent_id.nil?" + validates_length_of :slug, :within => 1..255, :unless => "parent_id.nil?" validates_presence_of :slug, :unless => "parent_id.nil?" validates_uniqueness_of :slug, :scope => :parent_id, :unless => "parent_id.nil?" + validates_presence_of :parent_id, :unless => "Node.root.nil?" + + validate :borders # This should never ever happen. # Index for Fulltext Search define_index do @@ -183,6 +186,12 @@ class Node < ActiveRecord::Base descendant.update_unique_name end end + + def borders + if lft && rgt && (lft > rgt) + errors.add("Fuck!. lft should never be smaller than rgt") + end + end end class LockedByAnotherUser < StandardError; end -- cgit v1.3