Permalink
Browse files

Fixing expected value from find when it results in failure.

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 23d4807933657ef44f8f8ce6f58ca87a66d663f9
Showing with 21 additions and 1 deletion.
  1. +1 −1 lib/Cake/Model/Model.php
  2. +20 −0 lib/Cake/Test/Case/Model/ModelDeleteTest.php
View
@@ -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;
}
@@ -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
*

0 comments on commit 23d4807

Please sign in to comment.