Commit | Line | Data |
956f4141 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
956f4141 |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
cc2d2ead |
7 | |
8 | my $schema = DBICTest->init_schema(); |
9 | DBICTest::Schema::Artist->load_components('FilterColumn'); |
10 | DBICTest::Schema::Artist->filter_column(rank => { |
d7d38bef |
11 | filter_from_storage => sub { $_[1] * 2 }, |
12 | filter_to_storage => sub { $_[1] / 2 }, |
cc2d2ead |
13 | }); |
14 | Class::C3->reinitialize(); |
15 | |
16 | my $artist = $schema->resultset('Artist')->create( { rank => 20 } ); |
17 | |
18 | # this should be using the cursor directly, no inflation/processing of any sort |
19 | my ($raw_db_rank) = $schema->resultset('Artist') |
20 | ->search ($artist->ident_condition) |
21 | ->get_column('rank') |
22 | ->_resultset |
23 | ->cursor |
24 | ->next; |
25 | |
26 | is ($raw_db_rank, 10, 'INSERT: correctly unfiltered on insertion'); |
27 | |
28 | for my $reloaded (0, 1) { |
29 | my $test = $reloaded ? 'reloaded' : 'stored'; |
30 | $artist->discard_changes if $reloaded; |
31 | |
32 | is( $artist->rank , 20, "got $test filtered rank" ); |
33 | } |
34 | |
35 | $artist->update; |
36 | $artist->discard_changes; |
37 | is( $artist->rank , 20, "got filtered rank" ); |
38 | |
39 | $artist->update ({ rank => 40 }); |
40 | ($raw_db_rank) = $schema->resultset('Artist') |
41 | ->search ($artist->ident_condition) |
42 | ->get_column('rank') |
43 | ->_resultset |
44 | ->cursor |
45 | ->next; |
46 | is ($raw_db_rank, 20, 'UPDATE: correctly unflitered on update'); |
47 | |
48 | $artist->discard_changes; |
49 | $artist->rank(40); |
50 | ok( !$artist->is_column_changed('rank'), 'column is not dirty after setting the same value' ); |
51 | |
8cfbd51c |
52 | MC: { |
53 | my $cd = $schema->resultset('CD')->create({ |
54 | artist => { rank => 20 }, |
55 | title => 'fun time city!', |
56 | year => 'forevertime', |
57 | }); |
0f914ece |
58 | ($raw_db_rank) = $schema->resultset('Artist') |
59 | ->search ($cd->artist->ident_condition) |
60 | ->get_column('rank') |
61 | ->_resultset |
62 | ->cursor |
63 | ->next; |
64 | |
65 | is $raw_db_rank, 10, 'artist rank gets correctly unfiltered w/ MC'; |
66 | is $cd->artist->rank, 20, 'artist rank gets correctly filtered w/ MC'; |
8cfbd51c |
67 | } |
68 | |
cc2d2ead |
69 | done_testing; |