Permalink
Browse files

Add test for saveAssociated and expression objects.

Add a test for #1514. This issue was fixed during recent refactorings.

Closes #1514
  • Loading branch information...
markstory committed Nov 16, 2013
1 parent cee2801 commit 016c3aed44f890b8ff605b24a4392c4acd3464fa
Showing with 26 additions and 0 deletions.
  1. +26 −0 lib/Cake/Test/Case/Model/ModelWriteTest.php
@@ -6244,6 +6244,32 @@ public function testSaveAssociatedEmptyData() {
$this->assertFalse($result);
}
+/**
+ * Test that saveAssociated will accept expression object values when saving.
+ *
+ * @return void
+ */
+ public function testSaveAssociatedExpressionObjects() {
+ $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment', 'Article', 'User');
+ $TestModel = new Post();
+ $db = $TestModel->getDataSource();
+
+ $TestModel->saveAssociated(array(
+ 'Post' => array(
+ 'title' => $db->expression('(SELECT "Post with Author")'),
+ 'body' => 'This post will be saved with an author'
+ ),
+ 'Author' => array(
+ 'user' => 'bob',
+ 'password' => '5f4dcc3b5aa765d61d8327deb882cf90'
+ )));
+
+ $result = $TestModel->find('first', array(
+ 'order' => array('Post.id ' => 'DESC')
+ ));
+ $this->assertEquals('Post with Author', $result['Post']['title']);
+ }
+
/**
* testUpdateWithCalculation method
*

0 comments on commit 016c3ae

Please sign in to comment.