e8beb526ef241528ae23be064c6a79bb67d6fb7b
[dbsrgits/DBIx-Class.git] / t / dq / remap.t
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
20 is_deeply(
21   [ $cds->_remap_identifiers(Identifier('name')) ],
22   [ Identifier('me', 'name'), [] ],
23   'Remap column on me'
24 );
25
26 is_deeply(
27   [ $cds->_remap_identifiers(Identifier('artist', 'name')) ],
28   [ Identifier('artist', 'name'), [ { artist => {} } ] ],
29   'Remap column on rel'
30 );
31
32 is_deeply(
33   [ $cds->search({}, { join => { single_track => { cd => 'artist' } } })
34         ->_remap_identifiers(Identifier('artist', 'name')) ],
35   [ Identifier('artist_2', 'name'), [ { artist => {} } ] ],
36   'Remap column on rel with re-alias'
37 );
38
39 done_testing;