Commit | Line | Data |
1f005975 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | use Test::Warn; |
7 | use lib qw(t/lib); |
8 | use Data::Query::ExprDeclare; |
9 | use Data::Query::ExprHelpers; |
10 | use DBICTest; |
11 | use DBIC::SqlMakerTest; |
12 | |
13 | my $schema = DBICTest->init_schema(); |
14 | |
15 | $schema->source($_)->resultset_class('DBIx::Class::ResultSet::WithDQMethods') |
16 | for qw(CD Tag); |
17 | |
18 | my $cds = $schema->resultset('CD'); |
19 | |
0f900f81 |
20 | throws_ok { |
21 | $cds->_remap_identifiers(Identifier('name')) |
22 | } qr/Invalid name on me: name/; |
23 | |
1f005975 |
24 | is_deeply( |
0f900f81 |
25 | [ $cds->_remap_identifiers(Identifier('title')) ], |
26 | [ Identifier('me', 'title'), [] ], |
1f005975 |
27 | 'Remap column on me' |
28 | ); |
29 | |
30 | is_deeply( |
31 | [ $cds->_remap_identifiers(Identifier('artist', 'name')) ], |
32 | [ Identifier('artist', 'name'), [ { artist => {} } ] ], |
33 | 'Remap column on rel' |
34 | ); |
35 | |
36 | is_deeply( |
37 | [ $cds->search({}, { join => { single_track => { cd => 'artist' } } }) |
38 | ->_remap_identifiers(Identifier('artist', 'name')) ], |
39 | [ Identifier('artist_2', 'name'), [ { artist => {} } ] ], |
40 | 'Remap column on rel with re-alias' |
41 | ); |
42 | |
0f900f81 |
43 | is_deeply( |
44 | [ $cds->_remap_identifiers(Identifier('artist_id')) ], |
45 | [ Identifier('me', 'artist'), [] ], |
46 | 'Remap column w/column name rename' |
47 | ); |
48 | |
49 | my $double_name = expr { $_->artist->name == $_->artist->name }->{expr}; |
50 | |
51 | is_deeply( |
52 | [ $cds->_remap_identifiers($double_name) ], |
53 | [ $double_name, [ { artist => {} } ] ], |
54 | 'Remap column on rel only adds rel once' |
55 | ); |
56 | |
1f005975 |
57 | done_testing; |