Skip to content

Commit

Permalink
Added test to prove that valiadtion in associated save will abort the
Browse files Browse the repository at this point in the history
full save operation
  • Loading branch information
lorenzo committed Nov 23, 2013
1 parent de5ddae commit dbeee9d
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion Cake/Test/TestCase/ORM/TableTest.php
Expand Up @@ -1953,7 +1953,7 @@ public function testsSaveBelongsTo() {
'body' => 'A body'
]);
$entity->author = new \Cake\ORM\Entity([
'name' => 'Jose',
'name' => 'Jose'
]);

$table = TableRegistry::get('articles');
Expand All @@ -1965,4 +1965,33 @@ public function testsSaveBelongsTo() {
$this->assertEquals(5, $entity->get('author_id'));
}

/**
* Tests saving belongsTo association and get a validation error
*
* @group save
* @return void
*/
public function testsSaveBelongsToWithValidationError() {
$entity = new \Cake\ORM\Entity([
'title' => 'A Title',
'body' => 'A body'
]);
$entity->author = new \Cake\ORM\Entity([
'name' => 'Jose'
]);

$table = TableRegistry::get('articles');
$table->belongsTo('authors');
$table->association('authors')
->target()
->validator()
->add('name', 'num', ['rule' => 'numeric']);

$this->assertFalse($table->save($entity));
$this->assertTrue($entity->isNew());
$this->assertTrue($entity->author->isNew());
$this->assertNull($entity->get('author_id'));
$this->assertNotEmpty($entity->author->errors('name'));
}

}

0 comments on commit dbeee9d

Please sign in to comment.