Commit | Line | Data |
46845551 |
1 | #!perl |
2 | |
ce0b9604 |
3 | use Test::More; |
46845551 |
4 | use lib qw(t/lib); |
5 | use DBICTest; |
6 | use Data::Dumper; |
7 | |
8 | # set up and populate schema |
9 | ok(my $schema = DBICTest->init_schema(), 'got schema'); |
10 | |
11 | { |
d1d2fc5e |
12 | my $artist_rs = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->display(); |
46845551 |
13 | is_deeply($artist_rs, [ |
14 | { |
15 | 'artistid' => '1', |
16 | 'name' => 'Caterwauler McCrae' |
17 | }, |
18 | { |
19 | 'artistid' => '2', |
20 | 'name' => 'Random Boy Band' |
21 | }, |
22 | { |
23 | 'artistid' => '3', |
24 | 'name' => 'We Are Goth' |
25 | } |
26 | ], 'ordered display returned as expected'); |
27 | } |
28 | |
29 | { |
d1d2fc5e |
30 | my $artists = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->with_substr->display(); |
46845551 |
31 | is_deeply($artists, [ |
32 | { |
33 | 'artistid' => '1', |
34 | 'name' => 'Caterwauler McCrae', |
35 | 'substr' => 'Cat' |
36 | }, |
37 | { |
38 | 'artistid' => '2', |
39 | 'name' => 'Random Boy Band', |
40 | 'substr' => 'Ran' |
41 | }, |
42 | { |
43 | 'artistid' => '3', |
44 | 'name' => 'We Are Goth', |
45 | 'substr' => 'We ' |
46 | } |
47 | ], 'display with substring okay'); |
48 | } |
49 | |
f1690863 |
50 | # { |
51 | # my $artists = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->with_substr_old->display(); |
52 | # is_deeply($artists, [ |
53 | # { |
54 | # 'artistid' => '1', |
55 | # 'name' => 'Caterwauler McCrae', |
56 | # 'substr' => 'Cat' |
57 | # }, |
58 | # { |
59 | # 'artistid' => '2', |
60 | # 'name' => 'Random Boy Band', |
61 | # 'substr' => 'Ran' |
62 | # }, |
63 | # { |
64 | # 'artistid' => '3', |
65 | # 'name' => 'We Are Goth', |
66 | # 'substr' => 'We ' |
67 | # } |
68 | # ], 'display with substring okay'); |
69 | # } |
70 | |
79b18b81 |
71 | { |
d1d2fc5e |
72 | my $artists = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->with_substr->search({}, { prefetch => 'cds', rows => 1 })->display(); |
79b18b81 |
73 | is_deeply($artists, [ |
ce0b9604 |
74 | { |
75 | 'artistid' => 1, |
76 | 'cds' => [ |
77 | { |
78 | 'cdid' => 3, |
79 | 'artist' => 1, |
80 | 'title' => 'Caterwaulin\' Blues', |
81 | 'year' => '1997' |
82 | }, |
83 | { |
84 | 'cdid' => 1, |
85 | 'artist' => 1, |
86 | 'title' => 'Spoonful of bees', |
87 | 'year' => '1999' |
88 | }, |
89 | { |
90 | 'cdid' => 2, |
91 | 'artist' => 1, |
92 | 'title' => 'Forkful of bees', |
93 | 'year' => '2001' |
94 | } |
95 | ], |
96 | 'name' => 'Caterwauler McCrae', |
97 | 'substr' => 'Cat' |
98 | } |
99 | ], 'substring before prefetch okay'); |
79b18b81 |
100 | } |
101 | |
ce0b9604 |
102 | done_testing(); |