Skip to content
Browse files

Restore whitelist when save fails.

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

Fixes #3646
  • Loading branch information...
1 parent 3d0920a commit 33bd7a571a0c5e02327f72c50eed386b2e242ce5 @markstory markstory committed
Showing with 17 additions and 0 deletions.
  1. +1 −0 lib/Cake/Model/Model.php
  2. +16 −0 lib/Cake/Test/Case/Model/ModelWriteTest.php
View
1 lib/Cake/Model/Model.php
@@ -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;
}
View
16 lib/Cake/Test/Case/Model/ModelWriteTest.php
@@ -276,6 +276,22 @@ public function testCacheClearOnSave() {
}
/**
+ * 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
*
* @return void

0 comments on commit 33bd7a5

Please sign in to comment.
Something went wrong with that request. Please try again.