Skip to content

Commit

Permalink
Removing continue statement that did nothing.
Browse files Browse the repository at this point in the history
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 ad8b70c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cake/libs/model/model.php
Expand Up @@ -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']) {
Expand All @@ -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();
Expand Down
28 changes: 28 additions & 0 deletions cake/tests/cases/libs/model/model_write.test.php
Expand Up @@ -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
*
Expand Down

0 comments on commit ad8b70c

Please sign in to comment.