Created
August 14, 2012 12:18
-
-
Save mrmorris/3348857 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function create($data = array(), $filterKey = false) { | |
$this->_validator = new ModelValidator($this); | |
return parent::create($data); | |
} | |
// TEST that shows issue/fix | |
public function testModelValidationClearing() { | |
$this->AppModelTestModel->validator() | |
->add( | |
'firstname', | |
'required', | |
array( | |
'rule' => 'notEmpty', | |
'required' => true | |
) | |
)->add( | |
'lastname', | |
'required', | |
array( | |
'rule' => 'notEmpty', | |
'required' => false | |
) | |
); | |
// save some invalid data to see it fail | |
$result = $this->AppModelTestModel->save(array('firstname' => '', 'lastname' => '')); | |
$this->assertFalse($result, "Invalid fields should both fail validation"); | |
// call create(). we're expecting this to clear all validation fails from before | |
$this->AppModelTestModel->create(null); | |
// attempt to re-save new data with a previously invalidated field, but not required, removed | |
$result = $this->AppModelTestModel->save(array('firstname' => 'Hi')); | |
$this->assertTrue($result, "Previously invalidated field, which we just removed, should no longer invalidate"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment