merged in hartmeier quickstart
[dbsrgits/DBIx-Class.git] / t / run / 01core.tl
CommitLineData
0567538f 1sub run_tests {
2
1f6715ab 3plan tests => 23;
0567538f 4
5my @art = DBICTest::Artist->search({ }, { order_by => 'name DESC'});
6
7cmp_ok(@art, '==', 3, "Three artists returned");
8
9my $art = $art[0];
10
11is($art->name, 'We Are Goth', "Correct order too");
12
13$art->name('We Are In Rehab');
14
15is($art->name, 'We Are In Rehab', "Accessor update ok");
16
17is($art->get_column("name"), 'We Are In Rehab', 'And via get_column');
18
19ok($art->update, 'Update run');
20
21@art = DBICTest::Artist->search({ name => 'We Are In Rehab' });
22
23cmp_ok(@art, '==', 1, "Changed artist returned by search");
24
25cmp_ok($art[0]->artistid, '==', 3,'Correct artist too');
26
27$art->delete;
28
29@art = DBICTest::Artist->search({ });
30
31cmp_ok(@art, '==', 2, 'And then there were two');
32
33ok(!$art->in_storage, "It knows it's dead");
34
35eval { $art->delete; };
36
37ok($@, "Can't delete twice: $@");
38
39is($art->name, 'We Are In Rehab', 'But the object is still live');
40
41$art->insert;
42
43ok($art->in_storage, "Re-created");
44
45@art = DBICTest::Artist->search({ });
46
47cmp_ok(@art, '==', 3, 'And now there are three again');
48
49my $new = DBICTest::Artist->create({ artistid => 4 });
50
51cmp_ok($new->artistid, '==', 4, 'Create produced record ok');
52
53@art = DBICTest::Artist->search({ });
54
55cmp_ok(@art, '==', 4, "Oh my god! There's four of them!");
56
57$new->set_column('name' => 'Man With A Fork');
58
59is($new->name, 'Man With A Fork', 'set_column ok');
60
61$new->discard_changes;
62
63ok(!defined $new->name, 'Discard ok');
64
65$new->name('Man With A Spoon');
66
67$new->update;
68
69$new_again = DBICTest::Artist->find(4);
70
71is($new_again->name, 'Man With A Spoon', 'Retrieved correctly');
72
1f6715ab 73is($new_again->ID, 'DBICTest::Artist|artistid=4', 'unique object id generated correctly');
74
0567538f 75is(DBICTest::Artist->count, 4, 'count ok');
76
77# insert_or_update
78$new = DBICTest::Track->new( {
79 trackid => 100,
80 cd => 1,
81 position => 1,
82 title => 'Insert or Update',
83} );
84$new->insert_or_update;
85ok($new->in_storage, 'insert_or_update insert ok');
86
87# test in update mode
88$new->position(5);
89$new->insert_or_update;
90is( DBICTest::Track->find(100)->position, 5, 'insert_or_update update ok');
91
92eval { DBICTest::Track->load_components('DoesNotExist'); };
93
94ok $@, $@;
95
96}
97
981;