Browse Source

Fix allowEmpty calculation.

I had the logic backwards.
mark_story 12 years ago
parent
commit
a29aec1633

+ 1 - 1
src/Console/Command/Task/ModelTask.php

@@ -437,7 +437,7 @@ class ModelTask extends BakeTask {
 		}
 
 		$allowEmpty = false;
-		if ($rule !== 'notEmpty' && $metaData['null'] === false) {
+		if ($rule !== 'notEmpty' && $metaData['null'] === true) {
 			$allowEmpty = true;
 		}
 

+ 3 - 3
tests/TestCase/Console/Command/Task/ModelTaskTest.php

@@ -371,11 +371,11 @@ class ModelTaskTest extends TestCase {
 		$model = TableRegistry::get('BakeArticles');
 		$result = $this->Task->getValidation($model);
 		$expected = [
-			'id' => ['rule' => 'numeric', 'allowEmpty' => true],
-			'bake_user_id' => ['rule' => 'numeric', 'allowEmpty' => true],
+			'id' => ['rule' => 'numeric', 'allowEmpty' => false],
+			'bake_user_id' => ['rule' => 'numeric', 'allowEmpty' => false],
 			'title' => ['rule' => 'notEmpty', 'allowEmpty' => false],
 			'body' => ['rule' => 'notEmpty', 'allowEmpty' => false],
-			'published' => ['rule' => 'boolean', 'allowEmpty' => false],
+			'published' => ['rule' => 'boolean', 'allowEmpty' => true],
 		];
 		$this->assertEquals($expected, $result);
 	}