Skip to content

Commit

Permalink
Adding another test for #250.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 30, 2010
1 parent 9cb15be commit 29d1314
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
30 changes: 29 additions & 1 deletion cake/tests/cases/libs/model/model_delete.test.php
Expand Up @@ -635,6 +635,34 @@ function testDeleteHabtmPostgresFailure() {
// Removing Article #2 from Tag #1 is all that should have happened.
$this->assertEqual(count($before[0]["Tag"]), count($after[0]["Tag"]));
}

/**
* test that deleting records inside the beforeDelete doesn't truncate the table.
*
* @return void
*/
function testBeforeDeleteWipingTable() {
$this->loadFixtures('Comment');

$Comment =& new BeforeDeleteComment();
// Delete 3 records.
$Comment->delete(4);
$result = $Comment->find('count');

$this->assertTrue($result > 1, 'Comments are all gone.');
$Comment->create(array(
'article_id' => 1,
'user_id' => 2,
'comment' => 'new record',
'published' => 'Y'
));
$Comment->save();

$Comment->delete(5);
$result = $Comment->find('count');

$this->assertTrue($result > 1, 'Comments are all gone.');
}
}

?>
?>
20 changes: 19 additions & 1 deletion cake/tests/cases/libs/model/models.php
Expand Up @@ -258,6 +258,24 @@ function titleDuplicate ($title) {
return true;
}
}
/**
* Model stub for beforeDelete testing
*
* @see #250
* @package cake.tests
*/
class BeforeDeleteComment extends CakeTestModel {
var $name = 'BeforeDeleteComment';

var $useTable = 'comments';

function beforeDelete($cascade = true) {
$db =& $this->getDataSource();
$db->delete($this, array($this->alias . '.' . $this->primaryKey => array(1, 3)));
return true;
}
}

/**
* NumericArticle class
*
Expand Down Expand Up @@ -3161,4 +3179,4 @@ class GroupUpdateAll extends CakeTestModel {

}

?>
?>

0 comments on commit 29d1314

Please sign in to comment.