From: Arthur Axel "fREW" Schmidt Date: Wed, 14 Apr 2010 15:55:14 +0000 (+0000) Subject: basic tests and a tiny fix X-Git-Tag: v0.08122~72^2~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cc2d2ead25cccac83d8e31f1756289040aff2d5f;p=dbsrgits%2FDBIx-Class.git basic tests and a tiny fix --- diff --git a/lib/DBIx/Class/FilterColumn.pm b/lib/DBIx/Class/FilterColumn.pm index 2425986..7077123 100644 --- a/lib/DBIx/Class/FilterColumn.pm +++ b/lib/DBIx/Class/FilterColumn.pm @@ -16,7 +16,7 @@ sub filter_column { $self->column_info($col)->{_filter_info} = $attrs; my $acc = $self->column_info($col)->{accessor}; - $self->mk_group_accessors('filtered_column' => [ (defined $acc ? $acc : $col), $col]); + $self->mk_group_accessors('value' => [ (defined $acc ? $acc : $col), $col]); return 1; } @@ -73,18 +73,4 @@ sub set_value { return $filtered; } -sub register_column { - my ($class, $col, $info) = @_; - my $acc = $col; - if (exists $info->{accessor}) { - return unless defined $info->{accessor}; - $acc = [ $info->{accessor}, $col ]; - } - if ( exists $self->column_info($col)->{_filter_info} ) { - $class->mk_group_accessors(value => $acc); - } else { - $class->mk_group_accessors(column => $acc); - } -} - 1; diff --git a/t/row/filter_column.t b/t/row/filter_column.t index da7283e..59c01a0 100644 --- a/t/row/filter_column.t +++ b/t/row/filter_column.t @@ -2,6 +2,51 @@ use strict; use warnings; use Test::More; -use Test::Exception; use lib qw(t/lib); use DBICTest; + +my $schema = DBICTest->init_schema(); +DBICTest::Schema::Artist->load_components('FilterColumn'); +DBICTest::Schema::Artist->filter_column(rank => { + filter => sub { warn "FILTERING!"; $_[1] * 2 }, + unfilter => sub {warn "UNFILTERING!"; $_[1] / 2 }, +}); +Class::C3->reinitialize(); + +my $artist = $schema->resultset('Artist')->create( { rank => 20 } ); + +# this should be using the cursor directly, no inflation/processing of any sort +my ($raw_db_rank) = $schema->resultset('Artist') + ->search ($artist->ident_condition) + ->get_column('rank') + ->_resultset + ->cursor + ->next; + +is ($raw_db_rank, 10, 'INSERT: correctly unfiltered on insertion'); + +for my $reloaded (0, 1) { + my $test = $reloaded ? 'reloaded' : 'stored'; + $artist->discard_changes if $reloaded; + + is( $artist->rank , 20, "got $test filtered rank" ); +} + +$artist->update; +$artist->discard_changes; +is( $artist->rank , 20, "got filtered rank" ); + +$artist->update ({ rank => 40 }); +($raw_db_rank) = $schema->resultset('Artist') + ->search ($artist->ident_condition) + ->get_column('rank') + ->_resultset + ->cursor + ->next; +is ($raw_db_rank, 20, 'UPDATE: correctly unflitered on update'); + +$artist->discard_changes; +$artist->rank(40); +ok( !$artist->is_column_changed('rank'), 'column is not dirty after setting the same value' ); + +done_testing;