]> source.dussan.org Git - redmine.git/commitdiff
Validate project identifier only when changed (#3352).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 25 May 2009 18:01:27 +0000 (18:01 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 25 May 2009 18:01:27 +0000 (18:01 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2762 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
test/unit/project_test.rb

index b022ed96b2272ef4a0086df139f2f8e6e8208f2f..8799e3b5847eacfc65cd57f8202efd78713bf553 100644 (file)
@@ -61,7 +61,8 @@ class Project < ActiveRecord::Base
   validates_length_of :name, :maximum => 30
   validates_length_of :homepage, :maximum => 255
   validates_length_of :identifier, :in => 1..20
-  validates_format_of :identifier, :with => /^[a-z0-9\-]*$/
+  # donwcase letters, digits, dashes but not digits only
+  validates_format_of :identifier, :with => /^(?!\d+$)[a-z0-9\-]*$/, :if => Proc.new { |p| p.identifier_changed? }
   
   before_destroy :delete_all_members
 
@@ -392,11 +393,6 @@ class Project < ActiveRecord::Base
     end
   end
   
-protected
-  def validate
-    errors.add(:identifier, :invalid) if !identifier.blank? && identifier.match(/^\d*$/)
-  end
-  
 private
   def allowed_permissions
     @allowed_permissions ||= begin
index 1ea5c19828e7a4931116f41c1b7c2f2bdf4e0263..2c874585660a43f5b47b128164d2be3c83a3f1d4 100644 (file)
@@ -48,6 +48,20 @@ class ProjectTest < Test::Unit::TestCase
     assert_equal I18n.translate('activerecord.errors.messages.blank'), @ecookbook.errors.on(:name)\r
   end\r
   \r
+  def test_validate_identifier\r
+    to_test = {"abc" => true,\r
+               "ab12" => true,\r
+               "ab-12" => true,\r
+               "12" => false}\r
+               \r
+    to_test.each do |identifier, valid|\r
+      p = Project.new\r
+      p.identifier = identifier\r
+      p.valid?\r
+      assert_equal valid, p.errors.on('identifier').nil?\r
+    end\r
+  end\r
+  \r
   def test_archive\r
     user = @ecookbook.members.first.user\r
     @ecookbook.archive\r