Validate project identifier only when changed (#3352).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2762 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
70340910de
commit
bd42b7cd9e
@ -61,7 +61,8 @@ class Project < ActiveRecord::Base
|
|||||||
validates_length_of :name, :maximum => 30
|
validates_length_of :name, :maximum => 30
|
||||||
validates_length_of :homepage, :maximum => 255
|
validates_length_of :homepage, :maximum => 255
|
||||||
validates_length_of :identifier, :in => 1..20
|
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
|
before_destroy :delete_all_members
|
||||||
|
|
||||||
@ -392,11 +393,6 @@ class Project < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
def validate
|
|
||||||
errors.add(:identifier, :invalid) if !identifier.blank? && identifier.match(/^\d*$/)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def allowed_permissions
|
def allowed_permissions
|
||||||
@allowed_permissions ||= begin
|
@allowed_permissions ||= begin
|
||||||
|
@ -48,6 +48,20 @@ class ProjectTest < Test::Unit::TestCase
|
|||||||
assert_equal I18n.translate('activerecord.errors.messages.blank'), @ecookbook.errors.on(:name)
|
assert_equal I18n.translate('activerecord.errors.messages.blank'), @ecookbook.errors.on(:name)
|
||||||
end
|
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
|
def test_archive
|
||||||
user = @ecookbook.members.first.user
|
user = @ecookbook.members.first.user
|
||||||
@ecookbook.archive
|
@ecookbook.archive
|
||||||
|
Loading…
x
Reference in New Issue
Block a user