diff options
Diffstat (limited to 'app/models/node.rb')
| -rw-r--r-- | app/models/node.rb | 11 |
1 files changed, 10 insertions, 1 deletions
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 | |||
| 16 | after_save :update_unique_names_of_children | 16 | after_save :update_unique_names_of_children |
| 17 | 17 | ||
| 18 | # Validations | 18 | # Validations |
| 19 | validates_length_of :slug, :within => 1..255, :unless => "parent_id.nil?" | 19 | validates_length_of :slug, :within => 1..255, :unless => "parent_id.nil?" |
| 20 | validates_presence_of :slug, :unless => "parent_id.nil?" | 20 | validates_presence_of :slug, :unless => "parent_id.nil?" |
| 21 | validates_uniqueness_of :slug, :scope => :parent_id, :unless => "parent_id.nil?" | 21 | validates_uniqueness_of :slug, :scope => :parent_id, :unless => "parent_id.nil?" |
| 22 | validates_presence_of :parent_id, :unless => "Node.root.nil?" | ||
| 23 | |||
| 24 | validate :borders # This should never ever happen. | ||
| 22 | 25 | ||
| 23 | # Index for Fulltext Search | 26 | # Index for Fulltext Search |
| 24 | define_index do | 27 | define_index do |
| @@ -183,6 +186,12 @@ class Node < ActiveRecord::Base | |||
| 183 | descendant.update_unique_name | 186 | descendant.update_unique_name |
| 184 | end | 187 | end |
| 185 | end | 188 | end |
| 189 | |||
| 190 | def borders | ||
| 191 | if lft && rgt && (lft > rgt) | ||
| 192 | errors.add("Fuck!. lft should never be smaller than rgt") | ||
| 193 | end | ||
| 194 | end | ||
| 186 | end | 195 | end |
| 187 | 196 | ||
| 188 | class LockedByAnotherUser < StandardError; end | 197 | class LockedByAnotherUser < StandardError; end |
