Skip to content

Commit

Permalink
Restore whitelist when save fails.
Browse files Browse the repository at this point in the history
Fixes whitelist not being restored when save fails due to no data.

Fixes #3646
  • Loading branch information
markstory committed Feb 26, 2013
1 parent 3d0920a commit 33bd7a5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Cake/Model/Model.php
Expand Up @@ -1626,6 +1626,7 @@ public function save($data = null, $validate = true, $fieldList = array()) {
$this->set($data);

if (empty($this->data) && !$this->hasField(array('created', 'updated', 'modified'))) {
$this->whitelist = $_whitelist;
return false;
}

Expand Down
16 changes: 16 additions & 0 deletions lib/Cake/Test/Case/Model/ModelWriteTest.php
Expand Up @@ -275,6 +275,22 @@ public function testCacheClearOnSave() {
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
*
Expand Down

0 comments on commit 33bd7a5

Please sign in to comment.