Removing continue statement that did nothing.

Adding a rollback for when validation fails and atomic has been set.
Tests added. Fixes #797
This commit is contained in:
mark_story 2010-06-09 13:48:54 -04:00
parent bca3c4ab38
commit ad8b70cec2
2 changed files with 32 additions and 1 deletions

View file

@ -1622,7 +1622,6 @@ class Model extends Overloadable {
case ($options['validate'] === 'first'): case ($options['validate'] === 'first'):
$options['validate'] = true; $options['validate'] = true;
$return = array(); $return = array();
continue;
break; break;
default: default:
if ($options['atomic']) { if ($options['atomic']) {
@ -1636,6 +1635,10 @@ class Model extends Overloadable {
break; break;
} }
} }
if ($options['atomic'] && !$validates) {
$db->rollback($this);
return false;
}
return $return; return $return;
} }
$associations = $this->getAssociated(); $associations = $this->getAssociated();

View file

@ -3034,6 +3034,34 @@ class ModelWriteTest extends BaseModelTest {
), array('validate' => 'only')); ), 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 * testSaveAllTransaction method
* *