Skip to content

Commit

Permalink
Fixed some validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Apr 29, 2012
1 parent 30761f9 commit 8700f3c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
3 changes: 1 addition & 2 deletions lib/Cake/Model/ModelValidator.php
Expand Up @@ -311,13 +311,12 @@ protected function _parseRules() {
return false;
}

if (!empty($this->_validate) && $this->_validate === $this->_model->validate) {
if ($this->_validate === $this->_model->validate) {
return true;
}

$this->_validate = $this->_model->validate;
$this->_processWhitelist();

$this->_fields = array();
$methods = $this->getMethods();
foreach ($this->_validate as $fieldName => $ruleSet) {
Expand Down
11 changes: 6 additions & 5 deletions lib/Cake/Model/Validator/CakeRule.php
Expand Up @@ -171,12 +171,13 @@ public function isRequired() {
* @return boolean
*/
public function checkRequired(&$data) {
$required = !isset($data[$this->_field]) && $this->required === true;
$required = $required || (
isset($this->data[$this->_field]) && (empty($data[$this->_field]) &&
!is_numeric($data[$this->_field])) && $this->allowEmpty === false
return (
(!isset($data[$this->_field]) && $this->required === true) ||
(
isset($data[$this->_field]) && (empty($data[$this->_field]) &&
!is_numeric($data[$this->_field])) && $this->allowEmpty === false
)
);
return $required;
}

/**
Expand Down
6 changes: 0 additions & 6 deletions lib/Cake/Test/Case/Model/ModelValidationTest.php
Expand Up @@ -346,8 +346,6 @@ public function testValidates() {
$this->assertEquals($data, $result);
$result = $TestModel->validates();
$this->assertTrue($result);
$result = $Validator->validates();
$this->assertTrue($result);

$data = array('TestValidate' => array(
'user_id' => '1',
Expand Down Expand Up @@ -517,8 +515,6 @@ public function testValidates() {
'title' => array('tooShort')
);
$this->assertEquals($expected, $result);
$result = $Validator->validates();
$this->assertFalse($result);

$TestModel->validate = array(
'title' => array(
Expand All @@ -540,8 +536,6 @@ public function testValidates() {
'title' => array('tooShort', 'onlyLetters')
);
$this->assertEquals($expected, $result);
$result = $Validator->validates();
$this->assertFalse($result);
$result = $TestModel->validationErrors;
$this->assertEquals($expected, $result);
}
Expand Down

0 comments on commit 8700f3c

Please sign in to comment.