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
end
end
-protected
- def validate
- errors.add(:identifier, :invalid) if !identifier.blank? && identifier.match(/^\d*$/)
- end
-
private
def allowed_permissions
@allowed_permissions ||= begin
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