Added count_from_sql, refactored andyg's count_related implementation
[dbsrgits/DBIx-Class-Historic.git] / t / 01core.t
CommitLineData
604d9f38 1use Test::More;
2
06d90c6b 3plan tests => 20;
604d9f38 4
5use lib qw(t/lib);
6
7use_ok('DBICTest');
8
9my @art = DBICTest::Artist->search({ }, { order_by => 'name DESC'});
10
11cmp_ok(@art, '==', 3, "Three artists returned");
12
13my $art = $art[0];
14
15is($art->name, 'We Are Goth', "Correct order too");
16
17$art->name('We Are In Rehab');
18
19is($art->name, 'We Are In Rehab', "Accessor update ok");
20
21is($art->get_column("name"), 'We Are In Rehab', 'And via get_column');
22
23ok($art->update, 'Update run');
24
25@art = DBICTest::Artist->search({ name => 'We Are In Rehab' });
26
27cmp_ok(@art, '==', 1, "Changed artist returned by search");
28
29cmp_ok($art[0]->artistid, '==', 3,'Correct artist too');
30
31$art->delete;
32
33@art = DBICTest::Artist->search({ });
34
35cmp_ok(@art, '==', 2, 'And then there were two');
36
37ok(!$art->in_database, "It knows it's dead");
38
39eval { $art->delete; };
40
41ok($@, "Can't delete twice: $@");
42
43is($art->name, 'We Are In Rehab', 'But the object is still live');
44
45$art->insert;
46
47ok($art->in_database, "Re-created");
48
49@art = DBICTest::Artist->search({ });
50
51cmp_ok(@art, '==', 3, 'And now there are three again');
52
53my $new = DBICTest::Artist->create({ artistid => 4 });
54
55cmp_ok($new->artistid, '==', 4, 'Create produced record ok');
56
57@art = DBICTest::Artist->search({ });
58
59cmp_ok(@art, '==', 4, "Oh my god! There's four of them!");
60
61$new->set_column('name' => 'Man With A Fork');
62
63is($new->name, 'Man With A Fork', 'set_column ok');
64
65$new->discard_changes;
66
67ok(!defined $new->name, 'Discard ok');
68
69$new->name('Man With A Spoon');
70
71$new->update;
72
73$new_again = DBICTest::Artist->retrieve(4);
74
75is($new_again->name, 'Man With A Spoon', 'Retrieved correctly');
06d90c6b 76
77is(DBICTest::Artist->count, 4, 'count ok');