Fix whitelist being empty during afterSave.

whitelist should only be reset after afterSave event.

Refs #6028
This commit is contained in:
mark_story 2015-03-08 13:51:46 -04:00
parent 534154f4f1
commit a9519d39f7
2 changed files with 34 additions and 2 deletions

View file

@ -1941,9 +1941,8 @@ class Model extends Object implements CakeEventListener {
$this->_saveMulti($joined, $this->id, $db);
}
$this->whitelist = $_whitelist;
if (!$success) {
$this->whitelist = $_whitelist;
return $success;
}
@ -1964,6 +1963,7 @@ class Model extends Object implements CakeEventListener {
$this->_clearCache();
$this->validationErrors = array();
$this->whitelist = $_whitelist;
$this->data = false;
return $success;

View file

@ -387,6 +387,38 @@ class ModelWriteTest extends BaseModelTest {
$this->assertEquals($whitelist, $model->whitelist);
}
/**
* Test save() resets the whitelist after afterSave
*
* @return void
*/
public function testSaveResetWhitelistOnSuccess() {
$this->loadFixtures('Post');
$callback = array($this, 'callbackForWhitelistReset');
$model = ClassRegistry::init('Post');
$model->whitelist = array('author_id', 'title', 'body');
$model->getEventManager()->attach($callback, 'Model.afterSave');
$data = array(
'title' => 'New post',
'body' => 'Post body',
'author_id' => 1
);
$result = $model->save($data);
$this->assertNotEmpty($result);
}
/**
* Callback for testing whitelist in afterSave
*
* @param Model $model The model having save called.
* @return void
*/
public function callbackForWhitelistReset($event) {
$expected = array('author_id', 'title', 'body', 'updated', 'created');
$this->assertEquals($expected, $event->subject()->whitelist);
}
/**
* testSaveWithCounterCache method
*