Skip to content

Commit

Permalink
Adding test case from '0x20h'. Fixing issue where atomic = false, val…
Browse files Browse the repository at this point in the history
…idate = first and saveAll() saving many rows could return an incorrect value. Fixes #1050
  • Loading branch information
markstory committed Aug 27, 2010
1 parent ea9e308 commit b02e213
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/model/model.php
Expand Up @@ -1593,6 +1593,7 @@ function saveAll($data = null, $options = array()) {

if (Set::numeric(array_keys($data))) {
while ($validates) {
$return = array();
foreach ($data as $key => $record) {
if (!$currentValidates = $this->__save($record, $options)) {
$validationErrors[$key] = $this->validationErrors;
Expand Down Expand Up @@ -1624,7 +1625,6 @@ function saveAll($data = null, $options = array()) {
break;
case ($options['validate'] === 'first'):
$options['validate'] = true;
$return = array();
break;
default:
if ($options['atomic']) {
Expand Down
59 changes: 59 additions & 0 deletions cake/tests/cases/libs/model/model_write.test.php
Expand Up @@ -3584,6 +3584,65 @@ function testSaveAllValidateFirst() {
$this->assertEqual($result[0]['Comment'][0]['comment'], 'Only new comment');
}

/**
* test saveAll()'s return is correct when using atomic = false and validate = first.
*
* @return void
*/
function testSaveAllValidateFirstAtomicFalse() {
$Something =& new Something();
$invalidData = array(
array(
'title' => 'foo',
'body' => 'bar',
'published' => 'baz',
),
array(
'body' => 3,
'published' =>'sd',
),
);
$Something->create();
$Something->validate = array(
'title' => array(
'rule' => 'alphaNumeric',
'required' => true,
),
'body' => array(
'rule' => 'alphaNumeric',
'required' => true,
'allowEmpty' => true,
),
);
$result = $Something->saveAll($invalidData, array(
'atomic' => false,
'validate' => 'first',
));
$expected = array(true, false);
$this->assertEqual($result, $expected);

$Something =& new Something();
$validData = array(
array(
'title' => 'title value',
'body' => 'body value',
'published' => 'baz',
),
array(
'title' => 'valid',
'body' => 'this body',
'published' =>'sd',
),
);
$Something->create();
$result = $Something->saveAll($validData, array(
'atomic' => false,
'validate' => 'first',
));
$expected = array(true, true);
$this->assertEqual($result, $expected);
}

/**
* testUpdateWithCalculation method
*
Expand Down

0 comments on commit b02e213

Please sign in to comment.