Restore whitelist when save fails.

Fixes whitelist not being restored when save fails due to no data.

Fixes #3646
This commit is contained in:
mark_story 2013-02-25 20:57:39 -05:00
parent 3d0920a405
commit 33bd7a571a
2 changed files with 17 additions and 0 deletions

View file

@ -1626,6 +1626,7 @@ class Model extends Object implements CakeEventListener {
$this->set($data);
if (empty($this->data) && !$this->hasField(array('created', 'updated', 'modified'))) {
$this->whitelist = $_whitelist;
return false;
}

View file

@ -275,6 +275,22 @@ class ModelWriteTest extends BaseModelTest {
Configure::write('Cache.disable', $_back['disable']);
}
/**
* test that save() resets whitelist on failed save
*/
public function testSaveFieldListResetsWhitelistOnFailedSave() {
$this->loadFixtures('Bidding');
$model = new Bidding();
$whitelist = array('title');
$model->whitelist = $whitelist;
$result = $model->save(
array(),
array('fieldList' => array('body'))
);
$this->assertFalse($result);
$this->assertEquals($whitelist, $model->whitelist);
}
/**
* testSaveWithCounterCache method
*