diff --git a/lib/Cake/Model/ModelValidator.php b/lib/Cake/Model/ModelValidator.php index 37d66548e..86f0f1627 100644 --- a/lib/Cake/Model/ModelValidator.php +++ b/lib/Cake/Model/ModelValidator.php @@ -311,13 +311,12 @@ class ModelValidator { 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) { diff --git a/lib/Cake/Model/Validator/CakeRule.php b/lib/Cake/Model/Validator/CakeRule.php index 3af2591dd..97eff77f0 100644 --- a/lib/Cake/Model/Validator/CakeRule.php +++ b/lib/Cake/Model/Validator/CakeRule.php @@ -171,12 +171,13 @@ class CakeRule { * @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; } /** diff --git a/lib/Cake/Test/Case/Model/ModelValidationTest.php b/lib/Cake/Test/Case/Model/ModelValidationTest.php index 97f52953a..c60492095 100644 --- a/lib/Cake/Test/Case/Model/ModelValidationTest.php +++ b/lib/Cake/Test/Case/Model/ModelValidationTest.php @@ -346,8 +346,6 @@ class ModelValidationTest extends BaseModelTest { $this->assertEquals($data, $result); $result = $TestModel->validates(); $this->assertTrue($result); - $result = $Validator->validates(); - $this->assertTrue($result); $data = array('TestValidate' => array( 'user_id' => '1', @@ -517,8 +515,6 @@ class ModelValidationTest extends BaseModelTest { 'title' => array('tooShort') ); $this->assertEquals($expected, $result); - $result = $Validator->validates(); - $this->assertFalse($result); $TestModel->validate = array( 'title' => array( @@ -540,8 +536,6 @@ class ModelValidationTest extends BaseModelTest { 'title' => array('tooShort', 'onlyLetters') ); $this->assertEquals($expected, $result); - $result = $Validator->validates(); - $this->assertFalse($result); $result = $TestModel->validationErrors; $this->assertEquals($expected, $result); }