diff --git a/app/models/article.rb b/app/models/article.rb index 84fa5d7..f2ac2c9 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -3,6 +3,8 @@ class Article < ActiveRecord::Base belongs_to :profile validates_presence_of :profile_id, :name, :slug, :path + validates_uniqueness_of :slug, :scope => ['profile_id', 'parent_id'], :message => _('%{fn} (the code generated from the article name) is already being used by another article.') + acts_as_taggable acts_as_filesystem diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 7f6745b..5bd377a 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -78,4 +78,19 @@ class ArticleTest < Test::Unit::TestCase assert_same result, a.mime_type_description end + should 'not accept articles with same slug under the same level' do + profile = create_user('testinguser').person + a1 = profile.articles.build(:name => 'test') + a1.save! + + a2 = profile.articles.build(:name => 'test') + a2.valid? + assert a2.errors.invalid?(:slug) + + a3 = profile.articles.build(:name => 'test') + a3.parent = a1 + a3.valid? + assert !a3.errors.invalid?(:slug) + end + end -- libgit2 0.21.2