interim
[dbsrgits/DBIx-Class.git] / t / 19retrieve_on_update.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8 use DBICTest;
9
10 # basically copies the test for retrieve_on_insert due to its
11 # similarity in nature
12
13 my $schema = DBICTest->init_schema( quote_names => 1 );
14
15 my $rs = $schema->resultset ('Artist');
16
17 my $obj;
18 lives_ok { $obj = $rs->create ({ name => 'artistA', rank => 13 }) } 'insert successful';
19 is ($obj->rank, 13, 'initial valus is normal');
20
21 # increment rank using raw sql
22 lives_ok { $obj->update({ rank => \'rank + 1' }) }, "raw sql processed without errors";
23
24 isa_ok( $obj->rank, "SCALAR", "rank after raw sql update" );
25
26 $obj->discard_changes;
27
28 is( $obj->rank, 14, "rank incremented in db" );
29
30 $rs->result_source->add_columns(
31     '+rank' => { retrieve_on_update => 1 }
32 );
33
34 ## increment again
35 $obj->update({ rank => \'rank + 1' });
36
37 is( $obj->rank, 14, "rank updated without discarding changes to refetch" );
38
39 lives_ok { $obj = $rs->create ({ name => 'artistB', rank => 13 }) } 'insert #2 successful';
40 $obj->update({ rank => \'rank + 1' });
41 is($obj->rank, 14, 'With retrieve_on_update, check rank');
42
43 done_testing;