Fix a race condition problem

Prevents Model::save() from generating a query with WHERE 1 = 1 on race condition.

Refs #3857
This commit is contained in:
chinpei215 2014-07-12 11:56:36 +09:00
parent 03c2a8b722
commit ace30fdd8a
4 changed files with 108 additions and 2 deletions

View file

@ -1412,4 +1412,45 @@ class DboSourceTest extends CakeTestCase {
$result = $db->insertMulti('articles', array_keys($data[0]), $data);
$this->assertTrue($result, 'Data was saved');
}
/**
* Test defaultConditions()
*
* @return
*/
public function testDefaultConditions() {
$this->loadFixtures('Article');
$Article = ClassRegistry::init('Article');
$db = $Article->getDataSource();
// Creates a default set of conditions from the model if $conditions is null/empty.
$Article->id = 1;
$result = $db->defaultConditions($Article, null);
$this->assertEquals(array('Article.id' => 1), $result);
// $useAlias == false
$Article->id = 1;
$result = $db->defaultConditions($Article, null, false);
$this->assertEquals(array($db->fullTableName($Article, false) . '.id' => 1), $result);
// If conditions are supplied then they will be returned.
$Article->id = 1;
$result = $db->defaultConditions($Article, array('Article.title' => 'First article'));
$this->assertEquals(array('Article.title' => 'First article'), $result);
// If a model doesn't exist and no conditions were provided either null or false will be returned based on what was input.
$Article->id = 1000000;
$result = $db->defaultConditions($Article, null);
$this->assertNull($result);
$Article->id = 1000000;
$result = $db->defaultConditions($Article, false);
$this->assertFalse($result);
// Safe update mode
$Article->id = 1000000;
$Article->__safeUpdateMode = true;
$result = $db->defaultConditions($Article, null);
$this->assertFalse($result);
}
}