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