Skip to content

Commit

Permalink
Fixing expected value from find when it results in failure.
Browse files Browse the repository at this point in the history
When a behavior callback (eg: beforeFind) stops the event, find will return null. False is really never returned from find().
  • Loading branch information
renan committed Jan 17, 2013
1 parent 70171f5 commit 23d4807
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2496,7 +2496,7 @@ public function deleteAll($conditions, $cascade = true, $callbacks = false) {
'fields' => "{$this->alias}.{$this->primaryKey}",
'recursive' => 0), compact('conditions'))
);
if ($ids === false) {
if ($ids === null) {
return false;
}

Expand Down
20 changes: 20 additions & 0 deletions lib/Cake/Test/Case/Model/ModelDeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,26 @@ public function testDeleteAllUnknownColumn() {
$this->assertFalse($result, 'deleteAll returned true when find query generated sql error. %s');
}

/**
* testDeleteAllFailedFind method
*
* Eg: Behavior callback stops the event, find returns null
*
* @return void
*/
public function testDeleteAllFailedFind() {
$this->loadFixtures('Article');
$this->getMock('Article', array('find'), array(), 'ArticleDeleteAll');

$TestModel = new ArticleDeleteAll();
$TestModel->expects($this->once())
->method('find')
->will($this->returnValue(null));

$result = $TestModel->deleteAll(array('Article.user_id' => 999));
$this->assertFalse($result);
}

/**
* testRecursiveDel method
*
Expand Down

0 comments on commit 23d4807

Please sign in to comment.