From 3fb1e130b9428235e73a7b530761b9cd438d7f80 Mon Sep 17 00:00:00 2001 From: hukl Date: Wed, 9 Sep 2009 12:34:19 +0200 Subject: uhm yeah - well it was finally time to validate the uniqueness of slugs scoped to the parent_id. Who though it wasn't there already? --- app/models/node.rb | 1 + test/unit/node_test.rb | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/node.rb b/app/models/node.rb index d4979ea..4bc8ed4 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -16,6 +16,7 @@ class Node < ActiveRecord::Base # Validations # validates_length_of :slug, :within => 3..40 + validates_uniqueness_of :slug, :scope => :parent_id # Index for Fulltext Search define_index do diff --git a/test/unit/node_test.rb b/test/unit/node_test.rb index 50c2dd2..ee4d71f 100644 --- a/test/unit/node_test.rb +++ b/test/unit/node_test.rb @@ -98,14 +98,14 @@ class NodeTest < ActiveSupport::TestCase end def test_create_new_draft_of_published_page - node = Node.create :slug => "third_child" + node = Node.create :slug => "xyz" node.move_to_child_of @root assert node.publish_draft! end def test_find_or_create_draft_if_no_draft_exists - node = Node.create :slug => "third_child" + node = Node.create :slug => "xyz" node.move_to_child_of @root node.publish_draft! @@ -113,7 +113,7 @@ class NodeTest < ActiveSupport::TestCase end def test_find_or_create_draft_if_draft_exists_and_is_owned_by_user - node = Node.create :slug => "third_child" + node = Node.create :slug => "xyz" node.move_to_child_of @root node.publish_draft! @@ -122,7 +122,7 @@ class NodeTest < ActiveSupport::TestCase end def test_exception_if_draft_exists_but_locked_by_another_user - node = Node.create :slug => "third_child" + node = Node.create :slug => "xyz" node.move_to_child_of @root node.publish_draft! node.find_or_create_draft @user1 -- cgit v1.3