Commit d14479dd0cd3db672ae7152b26ca4a6495f460b1

Authored by AntonioTerceiro
1 parent b11a31f6

ActionItem21: restricting slug under the same level



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@972 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/article.rb
... ... @@ -3,6 +3,8 @@ class Article < ActiveRecord::Base
3 3 belongs_to :profile
4 4 validates_presence_of :profile_id, :name, :slug, :path
5 5  
  6 + 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.')
  7 +
6 8 acts_as_taggable
7 9  
8 10 acts_as_filesystem
... ...
test/unit/article_test.rb
... ... @@ -78,4 +78,19 @@ class ArticleTest < Test::Unit::TestCase
78 78 assert_same result, a.mime_type_description
79 79 end
80 80  
  81 + should 'not accept articles with same slug under the same level' do
  82 + profile = create_user('testinguser').person
  83 + a1 = profile.articles.build(:name => 'test')
  84 + a1.save!
  85 +
  86 + a2 = profile.articles.build(:name => 'test')
  87 + a2.valid?
  88 + assert a2.errors.invalid?(:slug)
  89 +
  90 + a3 = profile.articles.build(:name => 'test')
  91 + a3.parent = a1
  92 + a3.valid?
  93 + assert !a3.errors.invalid?(:slug)
  94 + end
  95 +
81 96 end
... ...