Renamed DBIx::Class::Table::in_database to DBIx::Class::Table::in_storage
[dbsrgits/DBIx-Class.git] / t / 01core.t
CommitLineData
604d9f38 1use Test::More;
2
b6e40530 3plan tests => 22;
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
8d5134b0 37ok(!$art->in_storage, "It knows it's dead");
604d9f38 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
8d5134b0 47ok($art->in_storage, "Re-created");
604d9f38 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
656796f2 73$new_again = DBICTest::Artist->find(4);
604d9f38 74
75is($new_again->name, 'Man With A Spoon', 'Retrieved correctly');
06d90c6b 76
77is(DBICTest::Artist->count, 4, 'count ok');
b978d0ef 78
b6e40530 79# insert_or_update
80$new = DBICTest::Track->new( {
81 trackid => 100,
82 cd => 1,
83 position => 1,
84 title => 'Insert or Update',
85} );
86$new->insert_or_update;
8d5134b0 87ok($new->in_storage, 'insert_or_update insert ok');
b6e40530 88
89# test in update mode
90$new->position(5);
91$new->insert_or_update;
656796f2 92is( DBICTest::Track->find(100)->position, 5, 'insert_or_update update ok');