##// END OF EJS Templates
Validate project identifier only when changed (#3352)....
Jean-Philippe Lang -
r2663:bd42b7cd9e69
parent child
Show More
@@ -61,7 +61,8 class Project < ActiveRecord::Base
61 validates_length_of :name, :maximum => 30
61 validates_length_of :name, :maximum => 30
62 validates_length_of :homepage, :maximum => 255
62 validates_length_of :homepage, :maximum => 255
63 validates_length_of :identifier, :in => 1..20
63 validates_length_of :identifier, :in => 1..20
64 validates_format_of :identifier, :with => /^[a-z0-9\-]*$/
64 # donwcase letters, digits, dashes but not digits only
65 validates_format_of :identifier, :with => /^(?!\d+$)[a-z0-9\-]*$/, :if => Proc.new { |p| p.identifier_changed? }
65
66
66 before_destroy :delete_all_members
67 before_destroy :delete_all_members
67
68
@@ -392,11 +393,6 class Project < ActiveRecord::Base
392 end
393 end
393 end
394 end
394
395
395 protected
396 def validate
397 errors.add(:identifier, :invalid) if !identifier.blank? && identifier.match(/^\d*$/)
398 end
399
400 private
396 private
401 def allowed_permissions
397 def allowed_permissions
402 @allowed_permissions ||= begin
398 @allowed_permissions ||= begin
@@ -48,6 +48,20 class ProjectTest < Test::Unit::TestCase
48 assert_equal I18n.translate('activerecord.errors.messages.blank'), @ecookbook.errors.on(:name)
48 assert_equal I18n.translate('activerecord.errors.messages.blank'), @ecookbook.errors.on(:name)
49 end
49 end
50
50
51 def test_validate_identifier
52 to_test = {"abc" => true,
53 "ab12" => true,
54 "ab-12" => true,
55 "12" => false}
56
57 to_test.each do |identifier, valid|
58 p = Project.new
59 p.identifier = identifier
60 p.valid?
61 assert_equal valid, p.errors.on('identifier').nil?
62 end
63 end
64
51 def test_archive
65 def test_archive
52 user = @ecookbook.members.first.user
66 user = @ecookbook.members.first.user
53 @ecookbook.archive
67 @ecookbook.archive
General Comments 0
You need to be logged in to leave comments. Login now