Adding test case from '0x20h'. Fixing issue where atomic = false, validate = first and saveAll() saving many rows could return an incorrect value. Fixes #1050

This commit is contained in:
mark_story 2010-08-26 22:21:39 -04:00
parent ea9e30890f
commit b02e213958
2 changed files with 60 additions and 1 deletions

View file

@ -1593,6 +1593,7 @@ class Model extends Overloadable {
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;
@ -1624,7 +1625,6 @@ class Model extends Overloadable {
break;
case ($options['validate'] === 'first'):
$options['validate'] = true;
$return = array();
break;
default:
if ($options['atomic']) {

View file

@ -3584,6 +3584,65 @@ class ModelWriteTest extends BaseModelTest {
$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
*