Skip to content

Instantly share code, notes, and snippets.

@mrmorris
Created August 14, 2012 12:18
Show Gist options
  • Save mrmorris/3348857 to your computer and use it in GitHub Desktop.
Save mrmorris/3348857 to your computer and use it in GitHub Desktop.
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