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 | { |
b9495a50 |
30 | my $artists = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->with_substr_multi->display(); |
31 | is_deeply($artists, [ |
32 | { |
33 | 'artistid' => '1', |
34 | 'name' => 'Caterwauler McCrae', |
35 | 'substr' => 'Cat', |
36 | 'substr2' => 'Cate' |
37 | }, |
38 | { |
39 | 'artistid' => '2', |
40 | 'name' => 'Random Boy Band', |
41 | 'substr' => 'Ran', |
42 | 'substr2' => 'Rand' |
43 | }, |
44 | { |
45 | 'artistid' => '3', |
46 | 'name' => 'We Are Goth', |
47 | 'substr' => 'We ', |
48 | 'substr2' => 'We A' |
49 | } |
50 | ], 'display with substring using _with_meta_hash okay'); |
51 | } |
52 | |
53 | { |
fbe6d90c |
54 | my $artists = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->with_substr_multi_object->display(); |
55 | is_deeply($artists, [ |
56 | { |
57 | 'artistid' => '1', |
58 | 'name' => 'Caterwauler McCrae', |
59 | 'substr' => 'Cat', |
60 | 'substr2' => 'Cate' |
61 | }, |
62 | { |
63 | 'artistid' => '2', |
64 | 'name' => 'Random Boy Band', |
65 | 'substr' => 'Ran', |
66 | 'substr2' => 'Rand' |
67 | }, |
68 | { |
69 | 'artistid' => '3', |
70 | 'name' => 'We Are Goth', |
71 | 'substr' => 'We ', |
72 | 'substr2' => 'We A' |
73 | } |
74 | ], 'display with substring using _with_object_meta_hash okay'); |
75 | } |
76 | |
77 | { |
b9495a50 |
78 | my $artists = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->with_substr_key->display(); |
46845551 |
79 | is_deeply($artists, [ |
80 | { |
81 | 'artistid' => '1', |
82 | 'name' => 'Caterwauler McCrae', |
83 | 'substr' => 'Cat' |
84 | }, |
85 | { |
86 | 'artistid' => '2', |
87 | 'name' => 'Random Boy Band', |
88 | 'substr' => 'Ran' |
89 | }, |
90 | { |
91 | 'artistid' => '3', |
92 | 'name' => 'We Are Goth', |
93 | 'substr' => 'We ' |
94 | } |
b9495a50 |
95 | ], 'display with substring using _with_meta_key okay'); |
46845551 |
96 | } |
97 | |
4d83e732 |
98 | { |
99 | my $artists = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->with_substr_key_obj->display(); |
100 | is_deeply($artists, [ |
101 | { |
102 | 'artistid' => '1', |
103 | 'name' => 'Caterwauler McCrae', |
104 | 'substr' => 'Cat' |
105 | }, |
106 | { |
107 | 'artistid' => '2', |
108 | 'name' => 'Random Boy Band', |
109 | 'substr' => 'Ran' |
110 | }, |
111 | { |
112 | 'artistid' => '3', |
113 | 'name' => 'We Are Goth', |
114 | 'substr' => 'We ' |
115 | } |
fbe6d90c |
116 | ], 'display with substring using _with_object_meta_key okay'); |
4d83e732 |
117 | } |
118 | |
f1690863 |
119 | # { |
120 | # my $artists = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->with_substr_old->display(); |
121 | # is_deeply($artists, [ |
122 | # { |
123 | # 'artistid' => '1', |
124 | # 'name' => 'Caterwauler McCrae', |
125 | # 'substr' => 'Cat' |
126 | # }, |
127 | # { |
128 | # 'artistid' => '2', |
129 | # 'name' => 'Random Boy Band', |
130 | # 'substr' => 'Ran' |
131 | # }, |
132 | # { |
133 | # 'artistid' => '3', |
134 | # 'name' => 'We Are Goth', |
135 | # 'substr' => 'We ' |
136 | # } |
137 | # ], 'display with substring okay'); |
138 | # } |
139 | |
79b18b81 |
140 | { |
b9495a50 |
141 | my $artists = $schema->resultset('Artist')->search({}, { order_by => 'artistid' })->with_substr_key->search({}, { prefetch => 'cds', rows => 1 })->display(); |
79b18b81 |
142 | is_deeply($artists, [ |
ce0b9604 |
143 | { |
144 | 'artistid' => 1, |
145 | 'cds' => [ |
146 | { |
147 | 'cdid' => 3, |
148 | 'artist' => 1, |
149 | 'title' => 'Caterwaulin\' Blues', |
150 | 'year' => '1997' |
151 | }, |
152 | { |
153 | 'cdid' => 1, |
154 | 'artist' => 1, |
155 | 'title' => 'Spoonful of bees', |
156 | 'year' => '1999' |
157 | }, |
158 | { |
159 | 'cdid' => 2, |
160 | 'artist' => 1, |
161 | 'title' => 'Forkful of bees', |
162 | 'year' => '2001' |
163 | } |
164 | ], |
165 | 'name' => 'Caterwauler McCrae', |
166 | 'substr' => 'Cat' |
167 | } |
168 | ], 'substring before prefetch okay'); |
79b18b81 |
169 | } |
170 | |
ce0b9604 |
171 | done_testing(); |