fixed attr merging problem
[dbsrgits/DBIx-Class.git] / t / 91merge_attr.t
1 use strict;
2 use warnings;  
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7 use Test::More;
8 use Data::Dumper;
9
10 plan tests => 14;
11
12 my $schema = DBICTest->init_schema();
13 my $rs = $schema->resultset( 'CD' );
14
15 {
16   my $a = 'artist';
17   my $b = 'cd';
18   my $expected = [ 'artist', 'cd' ];
19   my $result = $rs->_merge_attr($a, $b);
20   is_deeply( $result, $expected );
21 }
22
23 {
24   my $a = [ 'artist' ];
25   my $b = [ 'cd' ];
26   my $expected = [ 'artist', 'cd' ];
27   my $result = $rs->_merge_attr($a, $b);
28   is_deeply( $result, $expected );
29 }
30
31 {
32   my $a = [ 'artist', 'cd' ];
33   my $b = [ 'cd' ];
34   my $expected = [ 'artist', 'cd' ];
35   my $result = $rs->_merge_attr($a, $b);
36   is_deeply( $result, $expected );
37 }
38
39 {
40   my $a = [ 'artist', 'artist' ];
41   my $b = [ 'artist', 'cd' ];
42   my $expected = [ 'artist', 'artist', 'cd' ];
43   my $result = $rs->_merge_attr($a, $b);
44   is_deeply( $result, $expected );
45 }
46
47 {
48   my $a = [ 'artist', 'cd' ];
49   my $b = [ 'artist', 'artist' ];
50   my $expected = [ 'artist', 'cd', 'artist' ];
51   my $result = $rs->_merge_attr($a, $b);
52   is_deeply( $result, $expected );
53 }
54
55 {
56   my $a = [ 'artist', 'cd', { 'artist' => 'manager' } ];
57   my $b = 'artist';
58   my $expected = [ 'artist', 'cd', { 'artist' => 'manager' } ];
59   my $result = $rs->_merge_attr($a, $b);
60   is_deeply( $result, $expected );
61 }
62
63 {
64   my $a = [ 'artist', 'cd', { 'artist' => 'manager' } ];
65   my $b = [ 'artist', 'cd' ];
66   my $expected = [ 'artist', 'cd', { 'artist' => 'manager' } ];
67   my $result = $rs->_merge_attr($a, $b);
68   is_deeply( $result, $expected );
69 }
70
71 {
72   my $a = [ 'artist', 'cd', { 'artist' => 'manager' } ];
73   my $b = { 'artist' => 'manager' };
74   my $expected = [ 'artist', 'cd', { 'artist' => [ 'manager' ] } ];
75   my $result = $rs->_merge_attr($a, $b);
76   is_deeply( $result, $expected );
77 }
78
79 {
80   my $a = [ 'artist', 'cd', { 'artist' => 'manager' } ];
81   my $b = { 'artist' => 'agent' };
82   my $expected = [ { 'artist' => 'agent' }, 'cd', { 'artist' => 'manager' } ];
83   my $result = $rs->_merge_attr($a, $b);
84   is_deeply( $result, $expected );
85 }
86
87 {
88   my $a = [ 'artist', 'cd', { 'artist' => 'manager' } ];
89   my $b = { 'artist' => { 'manager' => 'artist' } };
90   my $expected = [ 'artist', 'cd', { 'artist' => [ { 'manager' => 'artist' } ] } ];
91   my $result = $rs->_merge_attr($a, $b);
92   is_deeply( $result, $expected );
93 }
94
95 {
96   my $a = [ 'artist', 'cd', { 'artist' => 'manager' } ];
97   my $b = { 'artist' => { 'manager' => [ 'artist', 'label' ] } };
98   my $expected = [ 'artist', 'cd', { 'artist' => [ { 'manager' => [ 'artist', 'label' ] } ] } ];
99   my $result = $rs->_merge_attr($a, $b);
100   is_deeply( $result, $expected );
101 }
102
103 {
104   my $a = [ 'artist', 'cd', { 'artist' => 'manager' } ];
105   my $b = { 'artist' => { 'tour_manager' => [ 'venue', 'roadie' ] } };
106   my $expected = [ { 'artist' => { 'tour_manager' => [ 'venue', 'roadie' ] } }, 'cd', { 'artist' =>  'manager' } ];
107   my $result = $rs->_merge_attr($a, $b);
108   is_deeply( $result, $expected );
109 }
110
111 {
112   my $a = [ 'artist', 'cd' ];
113   my $b = { 'artist' => { 'tour_manager' => [ 'venue', 'roadie' ] } };
114   my $expected = [ { 'artist' => { 'tour_manager' => [ 'venue', 'roadie' ] } }, 'cd' ];
115   my $result = $rs->_merge_attr($a, $b);
116   is_deeply( $result, $expected );
117 }
118
119 {
120   my $a = [ { 'artist' => 'manager' }, 'cd' ];
121   my $b = [ 'artist', { 'artist' => 'manager' } ];
122   my $expected = [ { 'artist' => 'manager' }, 'cd', { 'artist' => 'manager' } ];
123   my $result = $rs->_merge_attr($a, $b);
124   is_deeply( $result, $expected );
125 }
126
127
128 1;