Permalink
Browse files

Fixed wrong validation init in Model bake task when having index star…

…ting at 1.

Added guess 'uuid' for type 'string' and length 36.
Updated missing calls to assertEqual() testFieldValidationGuessing().
Added test for uuid guessing.
  • Loading branch information...
1 parent b6ef130 commit 8ef70165456479703a889bc7d47152c81660f444 Thomas Ploch committed May 16, 2011
Showing with 14 additions and 1 deletion.
  1. +3 −0 cake/console/libs/tasks/model.php
  2. +11 −1 cake/tests/cases/console/libs/tasks/model.test.php
@@ -353,6 +353,7 @@ function initValidations() {
$default++;
}
}
+ $choices[$default] = 'none'; // Needed since index starts at 1
$this->_validations = $choices;
return $choices;
}
@@ -391,6 +392,8 @@ function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
if ($metaData['null'] != 1 && !in_array($fieldName, array($primaryKey, 'created', 'modified', 'updated'))) {
if ($fieldName == 'email') {
$guess = $methods['email'];
+ } elseif ($metaData['type'] == 'string' && $metaData['length'] == 36) {
+ $guess = $methods['uuid'];
} elseif ($metaData['type'] == 'string') {
$guess = $methods['notempty'];
} elseif ($metaData['type'] == 'integer') {
@@ -197,21 +197,31 @@ function testFieldValidationGuessing() {
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
$expected = array('notempty' => 'notempty');
+ $this->assertEqual($result, $expected);
$result = $this->Task->fieldValidation('text', array('type' => 'date', 'length' => 10, 'null' => false));
$expected = array('date' => 'date');
+ $this->assertEqual($result, $expected);
$result = $this->Task->fieldValidation('text', array('type' => 'time', 'length' => 10, 'null' => false));
$expected = array('time' => 'time');
+ $this->assertEqual($result, $expected);
$result = $this->Task->fieldValidation('email', array('type' => 'string', 'length' => 10, 'null' => false));
$expected = array('email' => 'email');
+ $this->assertEqual($result, $expected);
$result = $this->Task->fieldValidation('test', array('type' => 'integer', 'length' => 10, 'null' => false));
$expected = array('numeric' => 'numeric');
+ $this->assertEqual($result, $expected);
$result = $this->Task->fieldValidation('test', array('type' => 'boolean', 'length' => 10, 'null' => false));
- $expected = array('numeric' => 'numeric');
+ $expected = array('boolean' => 'boolean');
+ $this->assertEqual($result, $expected);
+
+ $result = $this->Task->fieldValidation('test', array('type' => 'string', 'length' => 36, 'null' => false));
+ $expected = array('uuid' => 'uuid');
+ $this->assertEqual($result, $expected);
}
/**

0 comments on commit 8ef7016

Please sign in to comment.