Skip to content
Permalink
Browse files

Removing continue statement that did nothing.

Adding a rollback for when validation fails and atomic has been set.
Tests added. Fixes #797
  • Loading branch information...
markstory committed Jun 9, 2010
1 parent bca3c4a commit ad8b70cec24164c967dc769bde1679c5822c7e8c
Showing with 32 additions and 1 deletion.
  1. +4 −1 cake/libs/model/model.php
  2. +28 −0 cake/tests/cases/libs/model/model_write.test.php
@@ -1622,7 +1622,6 @@ function saveAll($data = null, $options = array()) {
case ($options['validate'] === 'first'):
$options['validate'] = true;
$return = array();
continue;
break;
default:
if ($options['atomic']) {
@@ -1636,6 +1635,10 @@ function saveAll($data = null, $options = array()) {
break;
}
}
if ($options['atomic'] && !$validates) {
$db->rollback($this);
return false;
}
return $return;
}
$associations = $this->getAssociated();
@@ -3034,6 +3034,34 @@ function testSaveAllHasManyValidation() {
), array('validate' => 'only'));
}
/**
* test saveAll with transactions and ensure there is no missing rollback.
*
* @return void
*/
function testSaveAllTransactionNoRollback() {
$this->loadFixtures('Post');
Mock::generate('DboSource', 'MockTransactionDboSource');
$db = ConnectionManager::create('mock_transaction', array(
'datasource' => 'MockTransactionDbo',
));
$db->expectOnce('rollback');
$Post =& new Post();
$Post->useDbConfig = 'mock_transaction';
$Post->validate = array(
'title' => array('rule' => array('notEmpty'))
);
$data = array(
array('author_id' => 1, 'title' => 'New Fourth Post'),
array('author_id' => 1, 'title' => '')
);
$Post->saveAll($data, array('atomic' => true));
}
/**
* testSaveAllTransaction method
*

0 comments on commit ad8b70c

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