Commit | Line | Data |
ab8481f5 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | |
8 | my $schema = DBICTest->init_schema(); |
9 | |
10 | plan tests => 8; |
11 | |
12 | my $label = $schema->resultset('Label')->find({ labelid => 1 }); |
13 | |
14 | # Check that you can leave off the alias |
15 | { |
16 | my $existing_agent = $label->agents->find_or_create({ |
17 | name => 'Ted', |
18 | }); |
19 | ok(! $existing_agent->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean'); |
20 | is($existing_agent->name, 'Ted', 'find_or_create on prefetched has_many with same column names: name matches existing entry'); |
21 | |
22 | my $new_agent = $label->agents->find_or_create({ |
23 | name => 'Someone Else', |
24 | }); |
25 | ok(! $new_agent->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean'); |
26 | is($new_agent->name, 'Someone Else', 'find_or_create on prefetched has_many with same column names: name matches'); |
27 | } |
28 | |
29 | # Check that you can specify the alias |
30 | { |
31 | my $existing_agent = $label->agents->find_or_create({ |
32 | 'me.name' => 'Someone Else', |
33 | }); |
34 | ok(! $existing_agent->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean'); |
35 | is($existing_agent->name, 'Someone Else', 'find_or_create on prefetched has_many with same column names: can be disambiguated with "me." for existing entry'); |
36 | |
37 | my $new_agent = $label->agents->find_or_create({ |
38 | 'me.name' => 'Some New Guy', |
39 | }); |
40 | ok(! $new_agent->is_changed, 'find_or_create on prefetched has_many with same column names: row is clean'); |
41 | is($new_agent->name, 'Some New Guy', 'find_or_create on prefetched has_many with same column names: can be disambiguated with "me." for new entry'); |
42 | } |