Skip to content

Commit

Permalink
Validate project identifier only when changed (#3352).
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2762 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
jplang committed May 25, 2009
1 parent 7034091 commit bd42b7c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 2 additions & 6 deletions app/models/project.rb
Expand Up @@ -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

Expand Down Expand Up @@ -392,11 +393,6 @@ def self.copy_from(project)
end
end

protected
def validate
errors.add(:identifier, :invalid) if !identifier.blank? && identifier.match(/^\d*$/)
end

private
def allowed_permissions
@allowed_permissions ||= begin
Expand Down
14 changes: 14 additions & 0 deletions test/unit/project_test.rb
Expand Up @@ -48,6 +48,20 @@ def test_validate
assert_equal I18n.translate('activerecord.errors.messages.blank'), @ecookbook.errors.on(:name)
end

def test_validate_identifier
to_test = {"abc" => true,
"ab12" => true,
"ab-12" => true,
"12" => false}

to_test.each do |identifier, valid|
p = Project.new
p.identifier = identifier
p.valid?
assert_equal valid, p.errors.on('identifier').nil?
end
end

def test_archive
user = @ecookbook.members.first.user
@ecookbook.archive
Expand Down

0 comments on commit bd42b7c

Please sign in to comment.