Skip to content
Permalink
Browse files

Fix whitelist being empty during afterSave.

whitelist should only be reset after afterSave event.

Refs #6028
  • Loading branch information...
markstory committed Mar 8, 2015
1 parent 534154f commit a9519d39f7dbe5d26808868533fae1617978d2a2
Showing with 34 additions and 2 deletions.
  1. +2 −2 lib/Cake/Model/Model.php
  2. +32 −0 lib/Cake/Test/Case/Model/ModelWriteTest.php
@@ -1941,9 +1941,8 @@ protected function _doSave($data = null, $options = array()) {
$this->_saveMulti($joined, $this->id, $db);
}
$this->whitelist = $_whitelist;
if (!$success) {
$this->whitelist = $_whitelist;
return $success;
}
@@ -1964,6 +1963,7 @@ protected function _doSave($data = null, $options = array()) {
$this->_clearCache();
$this->validationErrors = array();
$this->whitelist = $_whitelist;
$this->data = false;
return $success;
@@ -387,6 +387,38 @@ public function testSaveFieldListResetsWhitelistOnFailedSave() {
$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
*

0 comments on commit a9519d3

Please sign in to comment.
You can’t perform that action at this time.