/**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     ActiveRecordManager::clearPool();
     $this->TWriter = ClassRegistry::init('TWriter');
 }
 public function testCreateSaveAllAndUpdate()
 {
     $post = new ARTPost(array('title' => 'TestTitle', 'message' => 'TestMessage', 'writer_id' => 1));
     ActiveRecordManager::saveAll();
     $newTitle = 'Test2Title';
     $post->title = $newTitle;
     ActiveRecordManager::saveAll();
     $id = $post->id;
     ActiveRecordManager::clearPool();
     $post = $this->TPost->find('first', array('recursive' => -1, 'conditions' => array('id' => $id), 'activeRecord' => true));
     $this->assertEquals($newTitle, $post->title);
 }
 /**
  * Test refresh on create
  */
 public function testRefreshOnCreate()
 {
     $record = array('name2' => 'dsfaedsjgfbdsjygfvb', 'id' => 100);
     $Record = new ARTRecord($record);
     $Record->save();
     ActiveRecordManager::clearPool();
     $RecordRefreshed = new ARTRecord(array('id' => $record['id']));
     $this->assertEqual($RecordRefreshed->name2, $record['name2']);
     $this->assertEqual($RecordRefreshed->id, $record['id']);
     ActiveRecordManager::clearPool();
     $RecordNotRefreshed = new ARTRecord(array('id' => $record['id']), array('norefresh' => true));
     $this->assertEmpty($RecordNotRefreshed->name2);
     $this->assertEqual($RecordNotRefreshed->id, $record['id']);
     ActiveRecordManager::clearPool();
     $RecordSaved = ClassRegistry::init('TRecord')->find('first', array('conditions' => array('id' => $record['id']), 'fields' => array('id'), 'activeRecord' => true));
     $this->assertEmpty($RecordSaved->name2);
     $this->assertEqual($RecordSaved->id, $record['id']);
     ActiveRecordManager::clearPool();
     $RecordSaved2 = ClassRegistry::init('TRecord')->find('first', array('conditions' => array('id' => $record['id']), 'activeRecord' => true));
     $this->assertEqual($RecordSaved2->name2, $record['name2']);
     $this->assertEqual($RecordSaved2->id, $record['id']);
 }
 /**
  * Test save with HABTM association
  */
 public function testHABTM()
 {
     $ARTPost = new ARTPost(array('title' => 'lala', 'message' => '', 'writer_id' => 1));
     $Comment1 = new ARTComment(array('message' => 'coment1 lala1', 'post_id' => 0));
     $Comment2 = new ARTComment(array('message' => 'coment1 lala2', 'post_id' => 0));
     $Comment3 = new ARTComment(array('message' => 'coment1 lala3', 'post_id' => 0));
     $Comment4 = new ARTComment(array('message' => 'coment1 lala4', 'post_id' => 0));
     $Comment1->Post = $ARTPost;
     $Comment2->Post = $ARTPost;
     $Comment3->Post = $ARTPost;
     $Comment4->Post = $ARTPost;
     $Comment2->Parents[] = $Comment1;
     $Comment3->Parents[] = $Comment1;
     $Comment4->Parents[] = $Comment3;
     $Comment3->Childrens[] = $Comment4;
     $Comment1->Childrens[] = $Comment3;
     $Comment1->Childrens[] = $Comment2;
     $Comment1->save();
     $this->_assertHABTM($Comment1);
     ActiveRecordManager::clearPool();
     $this->_assertHABTM($Comment1);
     $ARTComment = $this->TComment->find('first', array('conditions' => array('TComment.id' => $Comment1->id), 'activeRecord' => true));
     $this->_assertHABTM($ARTComment);
 }