Skip to content
Permalink
Browse files

Added test to prove that valiadtion in associated save will abort the

full save operation
  • Loading branch information...
lorenzo committed Nov 23, 2013
1 parent de5ddae commit dbeee9d5c30947f7d32df99d4dab83cb80a78077
Showing with 30 additions and 1 deletion.
  1. +30 −1 Cake/Test/TestCase/ORM/TableTest.php
@@ -1953,7 +1953,7 @@ public function testsSaveBelongsTo() {
'body' => 'A body'
]);
$entity->author = new \Cake\ORM\Entity([
'name' => 'Jose',
'name' => 'Jose'
]);
$table = TableRegistry::get('articles');
@@ -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.
You can’t perform that action at this time.