Skip to content

Commit

Permalink
Merge pull request #532 from Ali1/master
Browse files Browse the repository at this point in the history
Stop baking requirePresence validation when db default set
  • Loading branch information
markstory authored Apr 24, 2019
2 parents 4bd0b7b + 89650c1 commit 96651b0
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 36 deletions.
10 changes: 6 additions & 4 deletions src/Shell/Task/ModelTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,10 +768,12 @@ public function fieldValidation($schema, $fieldName, array $metaData, $primaryKe
'args' => [],
];
} else {
$validation['requirePresence'] = [
'rule' => 'requirePresence',
'args' => ["'create'"],
];
if ($metaData['default'] === null || $metaData['default'] === false) {
$validation['requirePresence'] = [
'rule' => 'requirePresence',
'args' => ["'create'"],
];
}
$validation['allowEmpty'] = [
'rule' => $this->getAllowEmptyMethod($fieldName, $metaData),
'args' => ['false'],
Expand Down
34 changes: 8 additions & 26 deletions tests/TestCase/Shell/Task/ModelTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,10 @@ public function testGetValidation()
$model = TableRegistry::getTableLocator()->get('BakeArticles');
$result = $this->Task->getValidation($model);
$expected = [
'id' => [
'integer' => ['rule' => 'integer', 'args' => []],
'allowEmpty' => ['rule' => 'allowEmptyString', 'args' => ["'create'"]]
],
'bake_user_id' => [
'integer' => ['rule' => 'integer', 'args' => []],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
Expand All @@ -871,7 +875,6 @@ public function testGetValidation()
],
'rating' => [
'numeric' => ['rule' => 'numeric', 'args' => []],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
'greaterThanOrEqual' => [
'rule' => 'greaterThanOrEqual',
'args' => [
Expand All @@ -885,7 +888,6 @@ public function testGetValidation()
],
'score' => [
'decimal' => ['rule' => 'decimal', 'args' => []],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
'greaterThanOrEqual' => [
'rule' => 'greaterThanOrEqual',
'args' => [
Expand All @@ -899,18 +901,10 @@ public function testGetValidation()
],
'published' => [
'boolean' => ['rule' => 'boolean', 'args' => []],
'requirePresence' => [
'rule' => 'requirePresence',
'args' => ["'create'" ],
],
'allowEmpty' => [
'rule' => 'allowEmptyString',
'args' => ['false'],
],
],
'id' => [
'integer' => ['rule' => 'integer', 'args' => []],
'allowEmpty' => ['rule' => 'allowEmptyString', 'args' => ["'create'"]]
]
];
$this->assertEquals($expected, $result);
Expand Down Expand Up @@ -982,18 +976,15 @@ public function testGetValidationSigned()
],
'rating' => [
'numeric' => ['rule' => 'numeric', 'args' => []],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
'allowEmpty' => ['rule' => 'allowEmptyString', 'args' => ['false']],
],
'score' => [
'decimal' => ['rule' => 'decimal', 'args' => []],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
'allowEmpty' => ['rule' => 'allowEmptyString', 'args' => ['false']]
],
'published' => [
'boolean' => ['rule' => 'boolean', 'args' => []],
'allowEmpty' => ['rule' => 'allowEmptyString', 'args' => ['false']],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
],
'id' => [
'integer' => ['rule' => 'integer', 'args' => []],
Expand Down Expand Up @@ -1053,9 +1044,9 @@ public function testGetValidationUniqueDateField()
'dateTime' => ['rule' => 'dateTime', 'args' => []],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
'allowEmpty' => [
'rule' => 'allowEmptyDateTime',
'args' => ['false'],
],
'rule' => 'allowEmptyDateTime',
'args' => ['false'],
],
];
$this->assertEquals($expected, $result['release_date']);
}
Expand Down Expand Up @@ -1182,8 +1173,7 @@ public function testGetValidationExcludeForeignKeys()
'allowEmpty' => [
'rule' => 'allowEmptyString',
'args' => ['false'],
],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
]
],
'score' => [
'decimal' => ['rule' => 'decimal', 'args' => []],
Expand All @@ -1193,7 +1183,6 @@ public function testGetValidationExcludeForeignKeys()
0,
],
],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
'allowEmpty' => [
'rule' => 'allowEmptyString',
'args' => ['false'],
Expand All @@ -1204,10 +1193,6 @@ public function testGetValidationExcludeForeignKeys()
'rule' => 'boolean',
'args' => [],
],
'requirePresence' => [
'rule' => 'requirePresence',
'args' => ["'create'" ],
],
'allowEmpty' => [
'rule' => 'allowEmptyString',
'args' => ['false'],
Expand Down Expand Up @@ -1249,7 +1234,6 @@ public function testGetValidationExcludeForeignKeysSigned()
'published' => [
'boolean' => ['rule' => 'boolean', 'args' => []],
'allowEmpty' => ['rule' => 'allowEmptyString', 'args' => ['false']],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
],
'id' => [
'integer' => ['rule' => 'integer', 'args' => []],
Expand All @@ -1258,12 +1242,10 @@ public function testGetValidationExcludeForeignKeysSigned()
'rating' => [
'numeric' => ['rule' => 'numeric', 'args' => []],
'allowEmpty' => ['rule' => 'allowEmptyString', 'args' => ['false']],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
],
'score' => [
'decimal' => ['rule' => 'decimal', 'args' => []],
'allowEmpty' => ['rule' => 'allowEmptyString', 'args' => ['false']],
'requirePresence' => ['rule' => 'requirePresence', 'args' => ["'create'"]],
]
];
$this->assertEquals($expected, $result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public function validationDefault(Validator $validator)
$validator
->scalar('name')
->maxLength('name', 100)
->requirePresence('name', 'create')
->allowEmptyString('name', false);

return $validator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public function validationDefault(Validator $validator)
$validator
->scalar('name')
->maxLength('name', 100)
->requirePresence('name', 'create')
->allowEmptyString('name', false);

return $validator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function validationDefault(Validator $validator)
$validator
->scalar('name')
->maxLength('name', 100)
->requirePresence('name', 'create')
->allowEmptyString('name', false);

return $validator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function validationDefault(Validator $validator)
$validator
->scalar('name')
->maxLength('name', 100)
->requirePresence('name', 'create')
->allowEmptyString('name', false);

return $validator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public function validationDefault(Validator $validator)
$validator
->scalar('name')
->maxLength('name', 100)
->requirePresence('name', 'create')
->allowEmptyString('name', false);

return $validator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public function validationDefault(Validator $validator)
$validator
->scalar('name')
->maxLength('name', 100)
->requirePresence('name', 'create')
->allowEmptyString('name', false);

return $validator;
Expand Down

0 comments on commit 96651b0

Please sign in to comment.