public function test_regular_models_not_cached()
 {
     $method = $this->set_method_public('Author', 'cache_key');
     $author = Author::first();
     $cache_key = $method->invokeArgs($author, array());
     $this->assertFalse(Cache::$adapter->read($cache_key));
 }
Пример #2
0
 public function test_caches_column_meta_data()
 {
     Author::first();
     $table_name = Author::table()->get_fully_qualified_table_name(!$this->conn instanceof ActiveRecord\PgsqlAdapter);
     $value = Cache::$adapter->read("get_meta_data-{$table_name}");
     $this->assert_true(is_array($value));
 }
 public function testCachesColumnMetaData()
 {
     Author::first();
     $tableName = Author::table()->getFullyQualifiedTableName(!$this->conn instanceof ActiveRecord\PgsqlAdapter);
     $value = Cache::$adapter->read("get_meta_data-{$tableName}");
     $this->assertTrue(is_array($value));
 }
 public function test_datefield_gets_converted_to_ar_datetime()
 {
     //make sure first author has a date
     $author = Author::first();
     $author->some_date = new DateTime();
     $author->save();
     $author = Author::first();
     $this->assert_is_a("ActiveRecord\\DateTime", $author->some_date);
 }
 public function test_has_many_build_association()
 {
     $author = Author::first();
     $this->assert_equals($author->id, $author->build_books()->author_id);
     $this->assert_equals($author->id, $author->build_book()->author_id);
 }
Пример #6
0
 public function test_is_dirty()
 {
     $author = Author::first();
     $this->assert_equals(false, $author->is_dirty());
     $author->name = 'coco';
     $this->assert_equals(true, $author->is_dirty());
 }
 public function testHaving()
 {
     if ($this->conn instanceof ActiveRecord\OciAdapter) {
         $author = Author::first(array('select' => 'to_char(created_at,\'YYYY-MM-DD\') as created_at', 'group' => 'to_char(created_at,\'YYYY-MM-DD\')', 'having' => "to_char(created_at,'YYYY-MM-DD') > '2009-01-01'"));
         $this->assertSqlHas("GROUP BY to_char(created_at,'YYYY-MM-DD') HAVING to_char(created_at,'YYYY-MM-DD') > '2009-01-01'", Author::table()->lastSql);
     } else {
         $author = Author::first(array('select' => 'date(created_at) as created_at', 'group' => 'date(created_at)', 'having' => "date(created_at) > '2009-01-01'"));
         $this->assertSqlHas("GROUP BY date(created_at) HAVING date(created_at) > '2009-01-01'", Author::table()->lastSql);
     }
 }
 public function test_having()
 {
     $author = Author::first(array('group' => "date(created_at)", 'having' => "created_at > '2009-01-01'"));
     $this->assert_true(strpos(Author::table()->last_sql, "GROUP BY date(created_at) HAVING created_at > '2009-01-01'") !== false);
 }
 public function test_only_method()
 {
     $this->assert_contains('<sharks>lasers</sharks>', Author::first()->to_xml(array('only_method' => 'return_something')));
 }
Пример #10
0
 /**
  * @expectedException ActiveRecord\ActiveRecordException
  */
 public function test_undefined_instance_method()
 {
     Author::first()->find_by_name('sdf');
 }
 public function testOnlyMethod()
 {
     $this->assertContains('<sharks>lasers</sharks>', Author::first()->toXml(array('onlyMethod' => 'returnSomething')));
 }
 public function testHasManyBuildAssociation()
 {
     $author = Author::first();
     $this->assertEquals($author->id, $author->buildBooks()->author_id);
     $this->assertEquals($author->id, $author->buildBook()->author_id);
 }
Пример #13
0
 public function test_has_one_can_be_self_referential()
 {
     Author::$has_one[1] = array('parent_author', 'class_name' => 'Author', 'foreign_key' => 'parent_author_id');
     $author = Author::first();
     $this->assert_equals(1, $author->id);
     $this->assert_equals(3, $author->parent_author->id);
 }
 /**
  * @expectedException ActiveRecord\ActiveRecordException
  */
 public function testUndefinedInstanceMethod()
 {
     Author::first()->findByName('sdf');
 }