1#!perl
2
3use strict;
4use warnings;
5
6use lib 't/lib';
7use Test::More;
8use Test::Deep;
9
10use TestSchema;
11my $schema = TestSchema->deploy_or_connect();
12$schema->prepopulate;
13
14my $first = $schema->resultset('Bar')->search(undef, { order_by => 'id' })->first;
15
16is($first->foo_id, 1, 'foo_id starts as 1');
17is($first->get_storage_value('foo_id'), 1, 'foo_id storage value starts as 1');
18$first->foo_id(2);
19is($first->foo_id, 2, 'foo_id changes to 2');
20is($first->get_storage_value('foo_id'), 1, 'foo_id storage value is still 1');
21$first->update;
22is($first->get_storage_value('foo_id'), 2, 'foo_id storage value is updated to 2');
23
24my $new = $schema->resultset('Bar')->new({
25   id => 999,
26   foo_id => 1,
27});
28is($new->foo_id, 1, 'new row of course has set values');
29is($new->get_storage_value('foo_id'), undef, 'and storage values are unset');
30$new->foo_id(2);
31is($new->foo_id, 2, 'updated row has new value');
32is($new->get_storage_value('foo_id'), undef, 'but storage values are unchanged');
33$new->insert;
34is($new->get_storage_value('foo_id'), 2, 'storage value updated after insert');
35
36done_testing;
37