Moved inflation to inflate_result in Row.pm
[dbsrgits/DBIx-Class.git] / t / run / 01core.tl
CommitLineData
0567538f 1sub run_tests {
2
54540863 3plan tests => 31;
0567538f 4
3712e4f4 5my @art = DBICTest->class("Artist")->search({ }, { order_by => 'name DESC'});
0567538f 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
3712e4f4 21@art = DBICTest->class("Artist")->search({ name => 'We Are In Rehab' });
0567538f 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
3712e4f4 29@art = DBICTest->class("Artist")->search({ });
0567538f 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
3712e4f4 45@art = DBICTest->class("Artist")->search({ });
0567538f 46
47cmp_ok(@art, '==', 3, 'And now there are three again');
48
3712e4f4 49my $new = DBICTest->class("Artist")->create({ artistid => 4 });
0567538f 50
51cmp_ok($new->artistid, '==', 4, 'Create produced record ok');
52
3712e4f4 53@art = DBICTest->class("Artist")->search({ });
0567538f 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
3712e4f4 69$new_again = DBICTest->class("Artist")->find(4);
0567538f 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
3712e4f4 75is(DBICTest->class("Artist")->count, 4, 'count ok');
0567538f 76
3712e4f4 77my $cd = DBICTest->class("CD")->find(1);
076a6864 78my %cols = $cd->get_columns;
79
80cmp_ok(keys %cols, '==', 4, 'get_columns number of columns ok');
81
82is($cols{title}, 'Spoonful of bees', 'get_columns values ok');
83
84%cols = ( title => 'Forkful of bees', year => 2005);
85$cd->set_columns(\%cols);
86
87is($cd->title, 'Forkful of bees', 'set_columns ok');
88
89is($cd->year, 2005, 'set_columns ok');
90
91$cd->discard_changes;
92
3712e4f4 93$cd = DBICTest->class("CD")->search({ title => 'Spoonful of bees' }, { cols => ['title'] })->next;
90f3f5ff 94is($cd->title, 'Spoonful of bees', 'subset of columns returned correctly');
95
0567538f 96# insert_or_update
3712e4f4 97$new = DBICTest->class("Track")->new( {
0567538f 98 trackid => 100,
99 cd => 1,
100 position => 1,
101 title => 'Insert or Update',
102} );
103$new->insert_or_update;
104ok($new->in_storage, 'insert_or_update insert ok');
105
106# test in update mode
107$new->position(5);
108$new->insert_or_update;
3712e4f4 109is( DBICTest->class("Track")->find(100)->position, 5, 'insert_or_update update ok');
0567538f 110
3712e4f4 111eval { DBICTest->class("Track")->load_components('DoesNotExist'); };
0567538f 112
113ok $@, $@;
114
3712e4f4 115is(DBICTest->class("Artist")->field_name_for->{name}, 'artist name', 'mk_classdata usage ok');
90e6de6c 116
54540863 117my $search = [ { 'tags.tag' => 'Cheesy' }, { 'tags.tag' => 'Blue' } ];
118
119my $rs = DBICTest->class("CD")->search($search, { join => 'tags' });
120
121cmp_ok($rs->all, '==', 5, 'Search with OR ok');
122
123$rs = DBICTest->class("CD")->search($search, { join => 'tags', distinct => 1 });
124
125cmp_ok($rs->all, '==', 4, 'DISTINCT search with OR ok');
126
0567538f 127}
128
1291;